// File: /workspace/github_cpp_makefile_star2_O1/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 0x35d93
movq %rax, %r14
leaq 0x148(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x34ce3
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x74b0
cmpq $-0x1, %r14
je 0x3532b
testq %r14, %r14
je 0x34dc2
movq 0x198(%rbx), %rdx
movq %r15, %rdi
movl $0x3a, %esi
callq 0x75c0
cmpq $-0x1, %rax
je 0x35344
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 0x5ea8(%rip), %rsi      # 0x3abf7
movl $0x2, %ecx
movq %r13, %rdi
xorl %edx, %edx
callq 0x77f0
testq %rax, %rax
je 0x34d81
movl $0x88, %edi
addq 0x19249(%rip), %rdi     # 0x4dfb8
leaq 0x50(%rsp), %rsi
callq 0x3673a
testb %al, %al
je 0x34e48
leaq 0x5e6f(%rip), %rsi      # 0x3abf7
leaq 0x50(%rsp), %rdi
movl $0x2, %ecx
xorl %edx, %edx
callq 0x77f0
testq %rax, %rax
je 0x34e54
movl $0x88, %edi
addq 0x1920a(%rip), %rdi     # 0x4dfb8
leaq 0x50(%rsp), %rsi
callq 0x364a4
movq %rax, 0x8(%rsp)
jmp 0x34e7c
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 0x8a49(%rip), %rsi      # 0x3d841
leaq 0x8a5c(%rip), %rdx      # 0x3d85b
leaq 0xf8(%rsp), %rdi
callq 0x80f4
leaq 0xf8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x32d48
movq 0xf8(%rsp), %rdi
cmpq %r15, %rdi
je 0x34e3c
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x74b0
movb $0x1, 0x190(%rbx)
jmp 0x3532b
addq %r14, 0x198(%rbx)
jmp 0x35275
leaq 0x70(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x88c4
leaq 0x70(%rsp), %rdi
callq 0x8a44
movq %rax, 0x8(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x89b4
movq 0x8(%rsp), %r12
testq %r12, %r12
je 0x35380
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 0x34ef5
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x8(%rsp), %rsi
movq (%rsi), %rax
leaq 0x30(%rsp), %rdi
callq *0x10(%rax)
leaq 0x897e(%rip), %rcx      # 0x3d88a
leaq 0x30(%rsp), %rdi
movl $0x11, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x7500
leaq 0x20(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x34f48
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x34f50
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
leaq 0x10(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x85f4(%rip), %rsi      # 0x3d567
callq 0x78d0
leaq 0x80(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x34fa5
movq %rdx, 0x70(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x80(%rsp)
jmp 0x34fad
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
movq %rdx, 0x78(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x8(%rsp), %rdi
callq 0x8e44
movq (%rax), %rsi
movq 0x8(%rax), %rdx
leaq 0x70(%rsp), %rdi
callq 0x7190
leaq 0xc8(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x35010
movq %rdx, 0xb8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xc8(%rsp)
jmp 0x35017
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
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 0x32d48
movq 0xb8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x35061
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x3507b
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x35092
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x40(%rsp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0x350ad
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x148(%rbx), %rsi
cmpq 0x150(%rbx), %rsi
je 0x350cf
movq 0x8(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x148(%rbx)
jmp 0x350e0
leaq 0x140(%rbx), %rdi
leaq 0x8(%rsp), %rdx
callq 0x36a2c
movq 0x8(%rsp), %rsi
movq (%rsi), %rax
leaq 0x10(%rsp), %rdi
callq *0x10(%rax)
leaq 0x70(%rsp), %rdi
callq 0x85dc
leaq 0x30(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x8682
movq 0x18(%rsp), %rdx
cmpq 0x38(%rsp), %rdx
jne 0x35131
testq %rdx, %rdx
je 0x35135
movq 0x30(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x74c0
testl %eax, %eax
sete %bpl
jmp 0x35138
xorl %ebp, %ebp
jmp 0x35138
movb $0x1, %bpl
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0x3514f
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x70(%rsp), %rdi
callq 0x861c
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x35170
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x74b0
testb %bpl, %bpl
je 0x35190
movq 0x8(%rsp), %rdi
callq 0x8e44
movq %rax, %rdi
callq 0x1bda4
cltq
movq %rax, 0x178(%rbx)
movq 0x8(%rsp), %rsi
movq (%rsi), %rax
leaq 0x10(%rsp), %rdi
callq *0x10(%rax)
leaq 0x70(%rsp), %rdi
callq 0x9ba0
leaq 0x30(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x9c46
movq 0x18(%rsp), %rdx
cmpq 0x38(%rsp), %rdx
jne 0x351dd
testq %rdx, %rdx
je 0x35217
movq 0x30(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x74c0
testl %eax, %eax
je 0x35217
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0x351f4
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x70(%rsp), %rdi
callq 0x9be0
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x35275
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x35275
movq 0x8(%rsp), %rdi
callq 0x8e44
leaq 0x8674(%rip), %rsi      # 0x3d89c
movq %rax, %rdi
callq 0x7180
movl %eax, %ebp
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0x35249
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x70(%rsp), %rdi
callq 0x9be0
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x3526a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x74b0
testl %ebp, %ebp
jne 0x35275
movb $0x1, 0x193(%rbx)
movq 0x8(%rbx), %rcx
movq 0x198(%rbx), %rax
cmpb $0xd, (%rcx,%rax)
jne 0x35310
cmpb $0xa, 0x1(%rcx,%rax)
jne 0x35310
addq $-0x2, %rax
movq %rax, 0x198(%rbx)
movq 0x28(%rbx), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
testb %al, %al
je 0x352b2
addq $0x4, 0x198(%rbx)
leaq 0xe8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x857c(%rip), %rsi      # 0x3d841
leaq 0x858f(%rip), %rdx      # 0x3d85b
leaq 0xd8(%rsp), %rdi
callq 0x80f4
leaq 0xd8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x32d48
movq 0xd8(%rsp), %rdi
cmpq %r15, %rdi
je 0x35309
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x74b0
movb $0x1, 0x190(%rbx)
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3532b
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 0x84fa(%rip), %rsi      # 0x3d85c
movq %rax, %rdi
callq 0x78c0
movq 0x18c57(%rip), %rsi     # 0x4dfc8
movq 0x18c38(%rip), %rdx     # 0x4dfb0
movq %rbx, %rdi
callq 0x77d0
movl $0x1f4, 0x188(%rbx)     # imm = 0x1F4
movl $0x10, %edi
callq 0x7260
movq %rax, %rbx
leaq 0x84de(%rip), %rsi      # 0x3d87c
movq %rax, %rdi
callq 0x78c0
movq 0x18c1b(%rip), %rsi     # 0x4dfc8
movq 0x18bfc(%rip), %rdx     # 0x4dfb0
movq %rbx, %rdi
callq 0x77d0
jmp 0x355dd
movq %rdx, %r15
movq %rax, %r14
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0x3547b
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x3547b
movq %rax, %r14
movq 0xd8(%rsp), %rdi
cmpq %r15, %rdi
je 0x35610
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x35610
jmp 0x3551d
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0x89b4
jmp 0x35610
jmp 0x3551d
movq %rax, %r14
movq %rbx, %rdi
callq 0x7390
jmp 0x35610
movq %rax, %r14
movq %rbx, %rdi
callq 0x7390
jmp 0x3562b
movq %rax, %r14
movq 0xf8(%rsp), %rdi
cmpq %r15, %rdi
je 0x3562b
movq 0x108(%rsp), %rsi
jmp 0x35623
movq %rax, %r14
jmp 0x3562b
movq %rdx, %r15
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0x9be0
jmp 0x354a6
jmp 0x354a0
jmp 0x35579
movq %rdx, %r15
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0x861c
jmp 0x354a6
movq %rdx, %r15
movq %rax, %r14
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x3557f
movq 0x20(%rsp), %rsi
jmp 0x3556f
jmp 0x35579
movq %rdx, %r15
movq %rax, %r14
movq 0xb8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x3552b
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x3552b
movq %rdx, %r15
movq %rax, %r14
jmp 0x35545
movq %rdx, %r15
movq %rax, %r14
jmp 0x3555c
jmp 0x35579
movq %rdx, %r15
movq %rax, %r14
leaq 0x128(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3557f
movq 0x128(%rsp), %rsi
jmp 0x3556f
jmp 0x3551d
movq %rax, %r14
jmp 0x35610
movq %rdx, %r15
movq %rax, %r14
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x35545
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x3555c
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3557f
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x3557f
movq %rdx, %r15
movq %rax, %r14
cmpl $0x1, %r15d
jne 0x35610
movq %r14, %rdi
callq 0x7210
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x355a1
movq (%rdi), %rax
callq *0x8(%rax)
movl $0x190, 0x188(%rbx)     # imm = 0x190
movl $0x10, %edi
callq 0x7260
movq %rax, %rbx
leaq 0x829d(%rip), %rsi      # 0x3d85c
movq %rax, %rdi
callq 0x78c0
movq 0x189fa(%rip), %rsi     # 0x4dfc8
movq 0x189db(%rip), %rdx     # 0x4dfb0
movq %rbx, %rdi
callq 0x77d0
movq %rax, %r14
leaq 0x148(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3562b
movq 0x148(%rsp), %rsi
jmp 0x35623
movq %rax, %r14
jmp 0x3560b
movq %rax, %r14
movq %rbx, %rdi
callq 0x7390
callq 0x7780
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3562b
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x74b0
movq %r14, %rdi
callq 0x7810
movq %rax, %rdi
callq 0x96cc
nop