// File: /workspace/github_cpp_makefile_star2_O1/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 0x8598(%rip), %rsi      # 0x15998
movl $0x1, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x46c0
cmpq $-0x1, %rax
je 0xd60f
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), %rcx
movq %rcx, -0x10(%rcx)
leaq -0x38(%rbp), %rdx
movq -0x10(%rdx), %rax
cmpq %rdx, %rax
je 0xd477
movq %rax, -0x88(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0xd47d
movups (%rdx), %xmm0
movups %xmm0, (%rcx)
movq -0x40(%rbp), %rax
leaq -0x58(%rbp), %r13
movq %rax, -0x28(%r13)
movq %rdx, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movb $0x0, -0x38(%rbp)
movq %r13, -0x10(%r13)
leaq -0xb8(%rbp), %rax
movq -0x10(%rax), %rcx
cmpq %rax, %rcx
je 0xd4be
movq %rcx, -0x68(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0xd4c6
movups (%rax), %xmm0
movups %xmm0, (%r13)
movq -0xc0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rdi
cmpq %rdx, %rdi
je 0xd4e6
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43e0
leaq 0x81eb(%rip), %rsi      # 0x156d8
leaq -0x88(%rbp), %rdi
movl $0x6, %ecx
xorl %edx, %edx
callq 0x45a0
cmpq $-0x1, %rax
jne 0xd67b
movq -0x80(%rbp), %r14
testq %r14, %r14
je 0xd533
movq -0x88(%rbp), %r12
xorl %r15d, %r15d
movsbl (%r12,%r15), %edi
callq 0x13774
movb %al, (%r12,%r15)
incq %r15
cmpq %r15, %r14
jne 0xd51d
leaq -0x68(%rbp), %r14
leaq 0x81c1(%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 0x819e(%rip), %rsi      # 0x156ff
movl $0x2, %ecx
movq %r14, %rdi
movq $-0x1, %rdx
callq 0x4630
incq %rax
movq -0x60(%rbp), %rcx
cmpq %rax, %rcx
jb 0xd6dc
leaq -0x88(%rbp), %rsi
movq %rax, 0x28(%rsi)
movq 0x20(%rsi), %rcx
movb $0x0, (%rcx,%rax)
addq $0x78, %rbx
movq %rbx, %rdi
callq 0xe364
testb $0x1, %dl
je 0xd6f4
movq -0x68(%rbp), %rdi
cmpq %r13, %rdi
je 0xd5c2
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0xd5de
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x43e0
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd5fd
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), %r12
movq %r12, -0x10(%r12)
leaq 0x809f(%rip), %rsi      # 0x156cb
leaq 0x80a4(%rip), %rdx      # 0x156d7
leaq -0x88(%rbp), %rdi
callq 0x5790
movb $0x1, %r15b
leaq 0x7fa3(%rip), %rdx      # 0x155ec
leaq -0x88(%rbp), %rcx
movq %r14, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0xe106
xorl %r15d, %r15d
leaq 0xf709(%rip), %rsi      # 0x1cd70
leaq 0xb06(%rip), %rdx       # 0xe174
movq %r14, %rdi
callq 0x46a0
jmp 0xd753
movl $0x48, %edi
callq 0x41f0
movq %rax, %r14
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
movq %rax, (%rdi)
leaq 0x8045(%rip), %rsi      # 0x156df
leaq 0x805d(%rip), %rdx      # 0x156fe
callq 0x5790
movb $0x1, %r12b
leaq 0x7f3c(%rip), %rdx      # 0x155ec
leaq -0x48(%rbp), %rcx
movq %r14, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0xe106
xorl %r12d, %r12d
leaq 0xf6a5(%rip), %rsi      # 0x1cd70
leaq 0xaa2(%rip), %rdx       # 0xe174
movq %r14, %rdi
callq 0x46a0
jmp 0xd753
leaq 0x814a(%rip), %rdi      # 0x1582d
leaq 0x817a(%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 0x7fef(%rip), %rsi      # 0x15702
leaq 0x800a(%rip), %rdx      # 0x15724
callq 0x5790
movb $0x1, %r12b
leaq 0x7ec3(%rip), %rdx      # 0x155ec
leaq -0x48(%rbp), %rcx
movq %r14, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0xe106
xorl %r12d, %r12d
leaq 0xf62c(%rip), %rsi      # 0x1cd70
leaq 0xa29(%rip), %rdx       # 0xe174
movq %r14, %rdi
callq 0x46a0
jmp 0xd757
jmp 0xd775
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xd77b
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xd77b
movq %rax, %rbx
movb $0x1, %r12b
testb %r12b, %r12b
je 0xd7e6
movq %r14, %rdi
callq 0x42e0
jmp 0xd7e6
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0xd7ad
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xd7ad
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0xd7f2
movq %r14, %rdi
callq 0x42e0
jmp 0xd7f2
jmp 0xd7e3
movq %rax, %rbx
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd7f2
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xd7f2
movq %rax, %rbx
jmp 0xd7f2
jmp 0xd7e3
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x98a0
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd811
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x43e0
movq %rbx, %rdi
callq 0x46d0
nop