// File: llefranc[P]42_webserv/srcs/server/Request.cpp
// Function: Request::parseHeaderLine(unsigned long)
void Request::parseHeaderLine(size_t posCLRF)
{
    std::string headerLine = _buffer.substr(_index, posCLRF - _index);
    
	size_t pos = headerLine.find(":");
    if (pos == std::string::npos)
		throw StatusLine(400, REASON_400, "no semicolon");
	
	// Splitting field name and field value with first semicolon
	std::pair<std::string, std::string> headerField(headerLine.substr(0, pos), 
			headerLine.substr(pos + 1, std::string::npos));
	
	if (headerField.first.find_first_of("\r\n\t\v\f ") != std::string::npos)
		throw StatusLine(400, REASON_400, "no whitespaces before semicolon");
	
	// Header field name is case insensitive, transforming it to lowercase
    std::transform(headerField.first.begin(), headerField.first.end(), 
			headerField.first.begin(), asciiToLower);
	
	// Remove leading / trailing whitespaces in header field value
	headerField.second.erase(0, headerField.second.find_first_not_of(" \t"));
	headerField.second.erase(headerField.second.find_last_not_of(" \t") + 1, std::string::npos);
	
	if (!_headers.insert(headerField).second)
		throw StatusLine(400, REASON_400, "duplicated headers are not allowed");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rsi
movq %rsi, -0x188(%rbp)
movq 0x20(%rsi), %rdx
movq -0x10(%rbp), %rcx
subq 0x20(%rsi), %rcx
leaq -0x30(%rbp), %rdi
callq 0x5590
leaq -0x30(%rbp), %rdi
leaq 0xb505(%rip), %rsi      # 0x23953
xorl %eax, %eax
movl %eax, %edx
callq 0x59e0
movq %rax, -0x38(%rbp)
cmpq $-0x1, -0x38(%rbp)
jne 0x1852a
movb $0x1, -0x6d(%rbp)
movl $0x48, %edi
callq 0x5290
movq %rax, -0x198(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0x190(%rbp)
callq 0x58f0
movq -0x190(%rbp), %rdx
leaq 0xb23d(%rip), %rsi      # 0x236d6
leaq -0x58(%rbp), %rdi
callq 0x63e0
jmp 0x184a4
movq -0x198(%rbp), %rdi
leaq 0xb145(%rip), %rdx      # 0x235f7
movl $0x190, %esi            # imm = 0x190
leaq -0x58(%rbp), %rcx
callq 0x199d0
jmp 0x184c2
movq -0x198(%rbp), %rdi
movb $0x0, -0x6d(%rbp)
leaq 0x188bc(%rip), %rsi     # 0x30d90
leaq 0x15a5(%rip), %rdx      # 0x19a80
callq 0x58a0
jmp 0x18963
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x18508
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x5a08
leaq -0x59(%rbp), %rdi
callq 0x55c0
testb $0x1, -0x6d(%rbp)
jne 0x18519
jmp 0x18525
movq -0x198(%rbp), %rdi
callq 0x53f0
jmp 0x18951
movq -0x38(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0xd0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x5590
jmp 0x18544
movq -0x38(%rbp), %rdx
incq %rdx
leaq -0xf0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movq $-0x1, %rcx
callq 0x5590
jmp 0x18564
leaq -0xb0(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
leaq -0xf0(%rbp), %rdx
callq 0x19d60
jmp 0x18580
leaq -0xf0(%rbp), %rdi
callq 0x5a08
leaq -0xd0(%rbp), %rdi
callq 0x5a08
leaq -0xb0(%rbp), %rdi
leaq 0xb13d(%rip), %rsi      # 0x236e3
xorl %eax, %eax
movl %eax, %edx
callq 0x52b0
cmpq $-0x1, %rax
je 0x186dd
movb $0x1, -0x112(%rbp)
movl $0x48, %edi
callq 0x5290
movq %rax, -0x1a8(%rbp)
leaq -0x111(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x58f0
movq -0x1a0(%rbp), %rdx
leaq 0xb0f8(%rip), %rsi      # 0x236ea
leaq -0x110(%rbp), %rdi
callq 0x63e0
jmp 0x18600
movq -0x1a8(%rbp), %rdi
leaq 0xafe9(%rip), %rdx      # 0x235f7
movl $0x190, %esi            # imm = 0x190
leaq -0x110(%rbp), %rcx
callq 0x199d0
jmp 0x18621
movq -0x1a8(%rbp), %rdi
movb $0x0, -0x112(%rbp)
leaq 0x1875a(%rip), %rsi     # 0x30d90
leaq 0x1443(%rip), %rdx      # 0x19a80
callq 0x58a0
jmp 0x18963
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x18951
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x1867e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x5a08
leaq -0xd0(%rbp), %rdi
callq 0x5a08
jmp 0x18951
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x186b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x5a08
leaq -0x111(%rbp), %rdi
callq 0x55c0
testb $0x1, -0x112(%rbp)
jne 0x186cc
jmp 0x186d8
movq -0x1a8(%rbp), %rdi
callq 0x53f0
jmp 0x18945
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x5480
movq -0x1b8(%rbp), %rdi
movq %rax, -0x120(%rbp)
callq 0x5320
movq -0x1b8(%rbp), %rdi
movq %rax, -0x128(%rbp)
callq 0x5480
movq %rax, -0x130(%rbp)
movq -0x120(%rbp), %rdi
movq -0x128(%rbp), %rsi
movq -0x130(%rbp), %rdx
leaq 0x8497(%rip), %rcx      # 0x20bd0
callq 0x19da0
movq %rax, -0x1b0(%rbp)
jmp 0x18747
movq -0x1b0(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0x90(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
leaq 0xafa0(%rip), %rsi      # 0x2370a
xorl %eax, %eax
movl %eax, %edx
movq %rdx, -0x1c0(%rbp)
callq 0x5310
movq -0x1c8(%rbp), %rdi
movq -0x1c0(%rbp), %rsi
movq %rax, %rdx
callq 0x5130
jmp 0x18792
leaq -0x90(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
leaq 0xaf63(%rip), %rsi      # 0x2370a
movq $-0x1, %rdx
movq %rdx, -0x1d0(%rbp)
callq 0x5940
movq -0x1d8(%rbp), %rdi
movq -0x1d0(%rbp), %rdx
movq %rax, %rsi
incq %rsi
callq 0x5130
jmp 0x187d5
movq -0x188(%rbp), %rdi
addq $0x78, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x19e20
movb %dl, -0x1e1(%rbp)
movq %rax, -0x1e0(%rbp)
jmp 0x187fb
movb -0x1e1(%rbp), %al
movq -0x1e0(%rbp), %rcx
movq %rcx, -0x158(%rbp)
movb %al, -0x150(%rbp)
movq -0x158(%rbp), %rax
movq %rax, -0x148(%rbp)
movb -0x150(%rbp), %al
movb %al, -0x140(%rbp)
movb -0x140(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x18840
jmp 0x18927
movb $0x1, -0x17a(%rbp)
movl $0x48, %edi
callq 0x5290
movq %rax, -0x1f8(%rbp)
leaq -0x179(%rbp), %rdi
movq %rdi, -0x1f0(%rbp)
callq 0x58f0
movq -0x1f0(%rbp), %rdx
leaq 0xae94(%rip), %rsi      # 0x2370d
leaq -0x178(%rbp), %rdi
callq 0x63e0
jmp 0x18887
movq -0x1f8(%rbp), %rdi
leaq 0xad62(%rip), %rdx      # 0x235f7
movl $0x190, %esi            # imm = 0x190
leaq -0x178(%rbp), %rcx
callq 0x199d0
jmp 0x188a8
movq -0x1f8(%rbp), %rdi
movb $0x0, -0x17a(%rbp)
leaq 0x184d3(%rip), %rsi     # 0x30d90
leaq 0x11bc(%rip), %rdx      # 0x19a80
callq 0x58a0
jmp 0x18963
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x18945
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x18902
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x5a08
leaq -0x179(%rbp), %rdi
callq 0x55c0
testb $0x1, -0x17a(%rbp)
jne 0x18919
jmp 0x18925
movq -0x1f8(%rbp), %rdi
callq 0x53f0
jmp 0x18945
leaq -0xb0(%rbp), %rdi
callq 0x10bd0
leaq -0x30(%rbp), %rdi
callq 0x5a08
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
leaq -0xb0(%rbp), %rdi
callq 0x10bd0
leaq -0x30(%rbp), %rdi
callq 0x5a08
movq -0x68(%rbp), %rdi
callq 0x58e0
nopw %cs:(%rax,%rax)