// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %rcx
movq %rdi, %rbx
movq 0x20(%rdi), %rdx
subq %rdx, %rcx
leaq -0xa8(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4410
leaq 0x8570(%rip), %rsi      # 0x15998
movl $0x1, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x46c0
cmpq $-0x1, %rax
je 0xd612
movq %rax, %r14
leaq -0x48(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x4410
incq %r14
leaq -0xc8(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
movq %r14, %rdx
movq $-0x1, %rcx
callq 0x4410
leaq -0x78(%rbp), %rdx
movq %rdx, -0x10(%rdx)
leaq -0x38(%rbp), %rcx
movq -0x10(%rcx), %rax
cmpq %rcx, %rax
je 0xd49f
movq %rax, -0x88(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0xd4a5
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq -0x40(%rbp), %rax
leaq -0x58(%rbp), %r13
movq %rax, -0x28(%r13)
movq %r13, -0x10(%r13)
leaq -0xb8(%rbp), %rax
movq -0x10(%rax), %rcx
cmpq %rax, %rcx
je 0xd4d6
movq %rcx, -0x68(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0xd4de
movups (%rax), %xmm0
movups %xmm0, (%r13)
movq -0xc0(%rbp), %rax
leaq -0x88(%rbp), %rdi
movq %rax, 0x28(%rdi)
leaq 0x81e1(%rip), %rsi      # 0x156d8
movl $0x6, %ecx
xorl %edx, %edx
callq 0x45a0
cmpq $-0x1, %rax
jne 0xd67d
movq -0x80(%rbp), %r14
testq %r14, %r14
je 0xd536
movq -0x88(%rbp), %r15
xorl %r12d, %r12d
movsbl (%r15,%r12), %edi
callq 0x136a8
movb %al, (%r15,%r12)
incq %r12
cmpq %r12, %r14
jne 0xd520
leaq -0x68(%rbp), %r14
leaq 0x81be(%rip), %rsi      # 0x156ff
movl $0x2, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x4680
movq %r14, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x40d0
leaq 0x819b(%rip), %rsi      # 0x156ff
movl $0x2, %ecx
movq %r14, %rdi
movq $-0x1, %rdx
callq 0x4630
incq %rax
movq -0x60(%rbp), %rcx
cmpq %rax, %rcx
jb 0xd6de
leaq -0x88(%rbp), %rsi
movq %rax, 0x28(%rsi)
movq 0x20(%rsi), %rcx
movb $0x0, (%rcx,%rax)
addq $0x78, %rbx
movq %rbx, %rdi
callq 0xe332
testb $0x1, %dl
je 0xd6f6
movq -0x68(%rbp), %rdi
cmpq %r13, %rdi
je 0xd5c5
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0xd5e1
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x43e0
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd600
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x43e0
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x48, %edi
callq 0x41f0
movq %rax, %r14
leaq -0x78(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x809d(%rip), %rsi      # 0x156cb
leaq 0x80a2(%rip), %rdx      # 0x156d7
leaq -0x88(%rbp), %rdi
callq 0x5796
movb $0x1, %r12b
leaq 0x7fa1(%rip), %rdx      # 0x155ec
leaq -0x88(%rbp), %rcx
movq %r14, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0xe0d4
xorl %r12d, %r12d
leaq 0xf707(%rip), %rsi      # 0x1cd70
leaq 0xad2(%rip), %rdx       # 0xe142
movq %r14, %rdi
callq 0x46a0
jmp 0xd755
movl $0x48, %edi
callq 0x41f0
movq %rax, %r14
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
movq %rax, (%rdi)
leaq 0x8043(%rip), %rsi      # 0x156df
leaq 0x805b(%rip), %rdx      # 0x156fe
callq 0x5796
movb $0x1, %r12b
leaq 0x7f3a(%rip), %rdx      # 0x155ec
leaq -0x48(%rbp), %rcx
movq %r14, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0xe0d4
xorl %r12d, %r12d
leaq 0xf6a3(%rip), %rsi      # 0x1cd70
leaq 0xa6e(%rip), %rdx       # 0xe142
movq %r14, %rdi
callq 0x46a0
jmp 0xd755
leaq 0x8148(%rip), %rdi      # 0x1582d
leaq 0x8178(%rip), %rsi      # 0x15864
movq %rax, %rdx
xorl %eax, %eax
callq 0x4590
movl $0x48, %edi
callq 0x41f0
movq %rax, %r14
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
movq %rax, (%rdi)
leaq 0x7fed(%rip), %rsi      # 0x15702
leaq 0x8008(%rip), %rdx      # 0x15724
callq 0x5796
movb $0x1, %r12b
leaq 0x7ec1(%rip), %rdx      # 0x155ec
leaq -0x48(%rbp), %rcx
movq %r14, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0xe0d4
xorl %r12d, %r12d
leaq 0xf62a(%rip), %rsi      # 0x1cd70
leaq 0x9f5(%rip), %rdx       # 0xe142
movq %r14, %rdi
callq 0x46a0
jmp 0xd759
jmp 0xd77c
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xd775
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43e0
testb %r12b, %r12b
jne 0xd77f
jmp 0xd7e2
movq %rax, %rbx
movq %r14, %rdi
callq 0x42e0
jmp 0xd7e2
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r15, %rdi
je 0xd7a4
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x43e0
testb %r12b, %r12b
jne 0xd7ae
jmp 0xd7ee
movq %rax, %rbx
movq %r14, %rdi
callq 0x42e0
jmp 0xd7ee
jmp 0xd7df
movq %rax, %rbx
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd7ee
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xd7ee
movq %rax, %rbx
jmp 0xd7ee
jmp 0xd7df
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x9914
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd80d
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x43e0
movq %rbx, %rdi
callq 0x46d0
nop