// File: /workspace/github_cpp_makefile_star2_O3/mbourand[P]webserv/srcs/Request.cpp
// Function: Request::parse_headers()
bool Request::parse_headers()
{
	size_t header_len = is_header_field_finished(_raw.substr(_parse_start));

	if (header_len == size_t(-1))
		return false;
	else if (header_len == 0)
	{
		if (_method->requestHasBody())
			_parse_start += 2;
		else
			_parse_start -= 2;
		Logger::print("Header section is finished", false, INFO, VERBOSE);
		return (_header_section_finished = true);
	}
	if (_raw.find(':', _parse_start) == std::string::npos)
	{
		_error_code = 400;
		throw std::invalid_argument("Invalid header field in request");
	}
	std::string header_name = _raw.substr(_parse_start, _raw.find(':', _parse_start) - _parse_start);
	if ((header_name.find("X-") == 0) || g_webserv.headers.contains_ignore_case(header_name))
	{
		Header* header;
		if (header_name.find("X-") == 0)
			header = CustomHeader(header_name).clone();
		else
			header = g_webserv.headers.createByType_ignore_case(header_name);
		if (header == NULL)
		{
			_error_code = 500;
			throw std::invalid_argument("Out of memory");
		}
		try
		{
			_parse_start += header_name.size() + 1;
			_parse_start += header->parse(_raw.substr(_parse_start));
			Logger::print("Request header : " + header->getType() + " -> " + header->getValue(), true, INFO, VERBOSE);
			_headers.push_back(header);
			if (header->getType() == ContentLengthHeader().getType())
				_content_length = ft::toInt(header->getValue());
			if (header->getType() == TransferEncodingHeader().getType() && header->getValue() == "chunked")
				_chunked = true;
		}
		catch(const std::exception& e)
		{
			delete header;
			_error_code = 400;
			throw std::invalid_argument("Invalid header field in request");
		}
	}
	else
		_parse_start += header_len;
	if (_raw[_parse_start] == '\r' && _raw[_parse_start + 1] == '\n')
	{
		_parse_start -= 2;
		if (_method->requestHasBody())
			_parse_start += 4;
		Logger::print("Header section is finished", false, INFO, VERBOSE);
		return (_header_section_finished = true);
	}
	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rdi, %rbx
leaq 0x8(%rdi), %r15
movq 0x198(%rdi), %rdx
leaq 0x138(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq $-0x1, %rcx
callq 0x74d0
movq %r14, %rdi
callq 0x3597c
movq %rax, %r14
leaq 0x148(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x348ad
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x74b0
cmpq $-0x1, %r14
je 0x34f23
testq %r14, %r14
je 0x3498f
movq 0x198(%rbx), %rdx
movq %r15, %rdi
movl $0x3a, %esi
callq 0x75c0
cmpq $-0x1, %rax
je 0x34f3c
movq 0x198(%rbx), %r12
movq %r15, %rdi
movl $0x3a, %esi
movq %r12, %rdx
callq 0x75c0
subq 0x198(%rbx), %rax
leaq 0x50(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %rax, %rcx
callq 0x74d0
leaq 0x62de(%rip), %rsi      # 0x3abf7
movl $0x2, %ecx
movq %r13, %rdi
xorl %edx, %edx
callq 0x77f0
testq %rax, %rax
je 0x3494b
movl $0x88, %edi
addq 0x1967f(%rip), %rdi     # 0x4dfb8
leaq 0x50(%rsp), %rsi
callq 0x36322
testb %al, %al
je 0x34a15
leaq 0x62a5(%rip), %rsi      # 0x3abf7
leaq 0x50(%rsp), %rdi
movl $0x2, %ecx
xorl %edx, %edx
callq 0x77f0
testq %rax, %rax
je 0x34a2b
movl $0x88, %edi
addq 0x19640(%rip), %rdi     # 0x4dfb8
leaq 0x50(%rsp), %rsi
callq 0x36088
movq %rax, %r12
movq %rax, 0x8(%rsp)
jmp 0x34a58
movq 0x28(%rbx), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x198(%rbx), %rcx
movzbl %al, %eax
leaq (%rcx,%rax,4), %rax
addq $-0x2, %rax
movq %rax, 0x198(%rbx)
leaq 0x108(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x8e7c(%rip), %rsi      # 0x3d841
leaq 0x8e8f(%rip), %rdx      # 0x3d85b
leaq 0xf8(%rsp), %rdi
callq 0x80f4
leaq 0xf8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x32966
movq 0xf8(%rsp), %rdi
cmpq %r15, %rdi
je 0x34a09
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x74b0
movb $0x1, 0x190(%rbx)
jmp 0x34f23
movq 0x198(%rbx), %rax
addq %r14, %rax
movq %rax, 0x198(%rbx)
jmp 0x34e75
leaq 0x70(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x88cc
leaq 0x70(%rsp), %rdi
callq 0x8a4c
movq %rax, 0x8(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x89bc
movq 0x8(%rsp), %r12
testq %r12, %r12
je 0x34f78
movq 0x58(%rsp), %rax
movq 0x198(%rbx), %rcx
leaq (%rax,%rcx), %rdx
incq %rdx
movq %rdx, 0x198(%rbx)
leaq 0x118(%rsp), %rdi
movq %r15, %rsi
movq $-0x1, %rcx
callq 0x74d0
movq (%r12), %rax
leaq 0x118(%rsp), %rsi
movq %r12, %rdi
callq *0x20(%rax)
addq %rax, 0x198(%rbx)
leaq 0x128(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x34acc
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x8(%rsp), %rsi
movq (%rsi), %rax
leaq 0x30(%rsp), %rdi
callq *0x10(%rax)
leaq 0x8da7(%rip), %rcx      # 0x3d88a
leaq 0x30(%rsp), %rdi
movl $0x11, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x7500
leaq 0x20(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x34b1e
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x34b25
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
leaq 0x10(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x8a1f(%rip), %rsi      # 0x3d567
callq 0x78d0
leaq 0x80(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x34b7b
movq %rdx, 0x70(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x80(%rsp)
jmp 0x34b83
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
movq %rdx, 0x78(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x8(%rsp), %rdi
callq 0x8e50
movq (%rax), %rsi
movq 0x8(%rax), %rdx
leaq 0x70(%rsp), %rdi
callq 0x7190
leaq 0xc8(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x34be6
movq %rdx, 0xb8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xc8(%rsp)
jmp 0x34bee
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
leaq 0xb8(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl $0x1, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x32966
movq 0xb8(%rsp), %rdi
cmpq %r13, %rdi
je 0x34c38
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x70(%rsp), %rdi
cmpq %r12, %rdi
je 0x34c52
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x10(%rsp), %rdi
cmpq %rbp, %rdi
je 0x34c69
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x40(%rsp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0x34c84
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x148(%rbx), %rax
cmpq 0x150(%rbx), %rax
je 0x34ca6
movq 0x8(%rsp), %rsi
movq %rsi, (%rax)
addq $0x8, 0x148(%rbx)
jmp 0x34cbf
leaq 0x140(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movq %rax, %rsi
callq 0x365fa
movq 0x8(%rsp), %rsi
movq (%rsi), %rax
leaq 0x10(%rsp), %rdi
callq *0x10(%rax)
leaq 0x70(%rsp), %rdi
callq 0x85e4
leaq 0x30(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x868a
movq 0x18(%rsp), %rdx
cmpq 0x38(%rsp), %rdx
jne 0x34d0e
movq 0x30(%rsp), %r12
testq %rdx, %rdx
je 0x34d17
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x74c0
testl %eax, %eax
sete %bpl
jmp 0x34d1a
movq 0x30(%rsp), %r12
xorl %ebp, %ebp
jmp 0x34d1a
movb $0x1, %bpl
cmpq %r13, %r12
je 0x34d2f
movq 0x40(%rsp), %rsi
incq %rsi
movq %r12, %rdi
callq 0x74b0
leaq 0x70(%rsp), %rdi
callq 0x8624
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x34d55
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x74b0
testb %bpl, %bpl
leaq 0x20(%rsp), %rbp
je 0x34d7a
movq 0x8(%rsp), %rdi
callq 0x8e50
movq %rax, %rdi
callq 0x1bab0
cltq
movq %rax, 0x178(%rbx)
movq 0x8(%rsp), %rsi
movq (%rsi), %rax
leaq 0x10(%rsp), %rdi
callq *0x10(%rax)
leaq 0x70(%rsp), %rdi
callq 0x9b80
leaq 0x30(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x9c26
movq 0x18(%rsp), %rdx
cmpq 0x38(%rsp), %rdx
jne 0x34e33
testq %rdx, %rdx
je 0x34dce
movq 0x30(%rsp), %r12
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x74c0
testl %eax, %eax
jne 0x34e38
movq 0x8(%rsp), %rdi
callq 0x8e50
leaq 0x8abd(%rip), %rsi      # 0x3d89c
movq %rax, %rdi
callq 0x7180
movl %eax, %ebp
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0x34e00
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x70(%rsp), %rdi
callq 0x9bc0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x34e26
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x74b0
testl %ebp, %ebp
jne 0x34e6e
movb $0x1, 0x193(%rbx)
jmp 0x34e6e
movq 0x30(%rsp), %r12
cmpq %r13, %r12
je 0x34e4d
movq 0x40(%rsp), %rsi
incq %rsi
movq %r12, %rdi
callq 0x74b0
leaq 0x70(%rsp), %rdi
callq 0x9bc0
movq 0x10(%rsp), %rdi
cmpq %rbp, %rdi
je 0x34e6e
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x198(%rbx), %rax
movq (%r15), %rcx
cmpb $0xd, (%rcx,%rax)
jne 0x34f08
cmpb $0xa, 0x1(%rcx,%rax)
jne 0x34f08
addq $-0x2, %rax
movq %rax, 0x198(%rbx)
movq 0x28(%rbx), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
testb %al, %al
je 0x34eaa
addq $0x4, 0x198(%rbx)
leaq 0xe8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x8984(%rip), %rsi      # 0x3d841
leaq 0x8997(%rip), %rdx      # 0x3d85b
leaq 0xd8(%rsp), %rdi
callq 0x80f4
leaq 0xd8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x32966
movq 0xd8(%rsp), %rdi
cmpq %r15, %rdi
je 0x34f01
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x74b0
movb $0x1, 0x190(%rbx)
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x34f23
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x74b0
cmpq $-0x1, %r14
setne %al
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x190, 0x188(%rbx)     # imm = 0x190
movl $0x10, %edi
callq 0x7260
movq %rax, %rbx
leaq 0x8902(%rip), %rsi      # 0x3d85c
movq %rax, %rdi
callq 0x78c0
movq 0x1905f(%rip), %rsi     # 0x4dfc8
movq 0x19040(%rip), %rdx     # 0x4dfb0
movq %rbx, %rdi
callq 0x77d0
movl $0x1f4, 0x188(%rbx)     # imm = 0x1F4
movl $0x10, %edi
callq 0x7260
movq %rax, %rbx
leaq 0x88e6(%rip), %rsi      # 0x3d87c
movq %rax, %rdi
callq 0x78c0
movq 0x19023(%rip), %rsi     # 0x4dfc8
movq 0x19004(%rip), %rdx     # 0x4dfb0
movq %rbx, %rdi
callq 0x77d0
jmp 0x351e2
movq %rdx, %r15
movq %rax, %r14
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0x35073
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x35073
movq %rax, %r14
movq 0xd8(%rsp), %rdi
cmpq %r15, %rdi
je 0x35215
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x35215
jmp 0x3511d
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0x89bc
jmp 0x35215
jmp 0x3511d
movq %rax, %r14
movq %rbx, %rdi
callq 0x7390
jmp 0x35215
movq %rax, %r14
movq %rbx, %rdi
callq 0x7390
jmp 0x35230
movq %rax, %r14
movq 0xf8(%rsp), %rdi
cmpq %r15, %rdi
je 0x35230
movq 0x108(%rsp), %rsi
jmp 0x35228
movq %rax, %r14
jmp 0x35230
movq %rdx, %r15
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0x9bc0
jmp 0x3509e
jmp 0x35098
jmp 0x3517e
movq %rdx, %r15
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0x8624
jmp 0x3509e
movq %rdx, %r15
movq %rax, %r14
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x35184
movq 0x20(%rsp), %rsi
jmp 0x35174
jmp 0x3517e
movq %rdx, %r15
movq %rax, %r14
movq 0xb8(%rsp), %rdi
cmpq %r13, %rdi
je 0x3512b
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x3512b
movq %rdx, %r15
movq %rax, %r14
jmp 0x35145
movq %rdx, %r15
movq %rax, %r14
jmp 0x35161
jmp 0x3517e
movq %rdx, %r15
movq %rax, %r14
leaq 0x128(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x35184
movq 0x128(%rsp), %rsi
jmp 0x35174
jmp 0x3511d
movq %rax, %r14
jmp 0x35215
movq %rdx, %r15
movq %rax, %r14
movq 0x70(%rsp), %rdi
cmpq %r12, %rdi
je 0x35145
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x35161
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x35184
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x35184
movq %rdx, %r15
movq %rax, %r14
cmpl $0x1, %r15d
jne 0x35215
movq %r14, %rdi
callq 0x7210
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x351a6
movq (%rdi), %rax
callq *0x8(%rax)
movl $0x190, 0x188(%rbx)     # imm = 0x190
movl $0x10, %edi
callq 0x7260
movq %rax, %rbx
leaq 0x8698(%rip), %rsi      # 0x3d85c
movq %rax, %rdi
callq 0x78c0
movq 0x18df5(%rip), %rsi     # 0x4dfc8
movq 0x18dd6(%rip), %rdx     # 0x4dfb0
movq %rbx, %rdi
callq 0x77d0
movq %rax, %r14
leaq 0x148(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x35230
movq 0x148(%rsp), %rsi
jmp 0x35228
movq %rax, %r14
jmp 0x35210
movq %rax, %r14
movq %rbx, %rdi
callq 0x7390
callq 0x7780
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x35230
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x74b0
movq %r14, %rdi
callq 0x7810
movq %rax, %rdi
callq 0x96aa