// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xa0, %rsp
movq %rsi, %rcx
movq %rdi, %rbx
movq 0x20(%rdi), %rdx
subq %rdx, %rcx
leaq -0xa0(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4460
leaq 0x5e0c(%rip), %rsi      # 0x11946
movq %r14, %rdi
xorl %edx, %edx
callq 0x47c0
cmpq $-0x1, %rax
je 0xbc72
movq %rax, %r14
leaq -0x40(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x4460
incq %r14
leaq -0xc0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
pushq $-0x1
popq %rcx
movq %r14, %rdx
callq 0x4460
leaq -0x80(%rbp), %r14
leaq -0x40(%rbp), %r15
leaq -0xc0(%rbp), %r12
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xc66a
movq %r12, %rdi
callq 0x47d8
movq %r15, %rdi
callq 0x47d8
leaq 0x5b1b(%rip), %rsi      # 0x116d1
movq %r14, %rdi
xorl %edx, %edx
callq 0x4240
cmpq $-0x1, %rax
jne 0xbcca
movq -0x80(%rbp), %r14
movq -0x78(%rbp), %r15
xorl %r12d, %r12d
cmpq %r12, %r15
je 0xbbed
movsbl (%r14,%r12), %edi
callq 0xfc4c
movb %al, (%r14,%r12)
incq %r12
jmp 0xbbd5
leaq -0x60(%rbp), %r14
leaq 0x5b00(%rip), %rsi      # 0x116f8
movq %r14, %rdi
xorl %edx, %edx
callq 0x42a0
movq %r14, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x40f0
leaq 0x5ae2(%rip), %rsi      # 0x116f8
pushq $-0x1
popq %r15
movq %r14, %rdi
movq %r15, %rdx
callq 0x4720
leaq 0x1(%rax), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x40f0
addq $0x78, %rbx
leaq -0x80(%rbp), %rsi
movq %rbx, %rdi
callq 0xc7c4
testb $0x1, %dl
je 0xbd22
leaq -0x80(%rbp), %rdi
callq 0x8cde
leaq -0xa0(%rbp), %rdi
callq 0x47d8
addq $0xa0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
pushq $0x48
popq %rdi
callq 0x4220
movq %rax, %r14
leaq 0x5a40(%rip), %rsi      # 0x116c4
leaq -0x80(%rbp), %rdi
leaq -0x40(%rbp), %rdx
callq 0x4ec8
movb $0x1, %r15b
leaq 0x594a(%rip), %rdx      # 0x115e5
leaq -0x80(%rbp), %rcx
movq %r14, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0xc540
xorl %r15d, %r15d
leaq 0xd0da(%rip), %rsi      # 0x18d90
leaq 0x8d9(%rip), %rdx       # 0xc596
movq %r14, %rdi
callq 0x46b0
jmp 0xbd78
pushq $0x48
popq %rdi
callq 0x4220
movq %rax, %r14
leaq 0x59fc(%rip), %rsi      # 0x116d8
leaq -0x40(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
callq 0x4ec8
movb $0x1, %r15b
leaq 0x58ef(%rip), %rdx      # 0x115e5
leaq -0x40(%rbp), %rcx
movq %r14, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0xc540
xorl %r15d, %r15d
leaq 0xd07f(%rip), %rsi      # 0x18d90
leaq 0x87e(%rip), %rdx       # 0xc596
movq %r14, %rdi
callq 0x46b0
jmp 0xbd78
pushq $0x48
popq %rdi
callq 0x4220
movq %rax, %r14
leaq 0x59c7(%rip), %rsi      # 0x116fb
leaq -0x40(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
callq 0x4ec8
movb $0x1, %r15b
leaq 0x5897(%rip), %rdx      # 0x115e5
leaq -0x40(%rbp), %rcx
movq %r14, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0xc540
xorl %r15d, %r15d
leaq 0xd027(%rip), %rsi      # 0x18d90
leaq 0x826(%rip), %rdx       # 0xc596
movq %r14, %rdi
callq 0x46b0
jmp 0xbd7c
jmp 0xbd8f
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x47d8
testb %r15b, %r15b
jne 0xbd92
jmp 0xbdd6
movq %rax, %rbx
movq %r14, %rdi
callq 0x4330
jmp 0xbdd6
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x47d8
testb %r15b, %r15b
jne 0xbdb2
jmp 0xbddf
movq %rax, %rbx
movq %r14, %rdi
callq 0x4330
jmp 0xbddf
jmp 0xbdd3
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x47d8
jmp 0xbddf
movq %rax, %rbx
jmp 0xbddf
jmp 0xbdd3
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x8cde
leaq -0xa0(%rbp), %rdi
callq 0x47d8
movq %rbx, %rdi
callq 0x46d0
nop