// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $-0x1
popq %rcx
movq %r14, %rdi
movq %r15, %rsi
callq 0x7540
movq %r14, %rdi
callq 0x29109
movq %rax, %r14
leaq 0x138(%rsp), %rdi
callq 0x79b8
cmpq $-0x1, %r14
je 0x2898f
testq %r14, %r14
je 0x28637
movq 0x198(%rbx), %rdx
pushq $0x3a
popq %rsi
movq %r15, %rdi
callq 0x7650
cmpq $-0x1, %rax
je 0x289a8
movq 0x198(%rbx), %r12
pushq $0x3a
popq %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x7650
subq 0x198(%rbx), %rax
leaq 0x98(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %rax, %rcx
callq 0x7540
leaq 0x45e9(%rip), %rsi      # 0x2cbab
movq %r13, %rdi
xorl %edx, %edx
callq 0x7980
testq %rax, %rax
je 0x285f2
movl $0x88, %edi
addq 0x1a9db(%rip), %rdi     # 0x42fb8
leaq 0x98(%rsp), %rsi
callq 0x297f0
testb %al, %al
je 0x2869f
leaq 0x45b2(%rip), %rsi      # 0x2cbab
leaq 0x98(%rsp), %rdi
xorl %edx, %edx
callq 0x7980
testq %rax, %rax
je 0x286b5
movl $0x88, %edi
addq 0x1a99b(%rip), %rdi     # 0x42fb8
leaq 0x98(%rsp), %rsi
callq 0x29634
movq %rax, %r12
movq %rax, 0x8(%rsp)
jmp 0x286e5
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 0x7170(%rip), %rsi      # 0x2f7d1
leaq 0x118(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x8032
leaq 0x118(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x26da2
leaq 0x118(%rsp), %rdi
callq 0x79b8
movb $0x1, 0x190(%rbx)
jmp 0x2898f
movq 0x198(%rbx), %rax
addq %r14, %rax
movq %rax, 0x198(%rbx)
jmp 0x28911
leaq 0x50(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x862c
leaq 0x50(%rsp), %rdi
callq 0x8708
movq %rax, 0x8(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x86bc
movq 0x8(%rsp), %r12
testq %r12, %r12
je 0x289e2
movq 0xa0(%rsp), %rax
movq 0x198(%rbx), %rcx
leaq (%rax,%rcx), %rdx
incq %rdx
movq %rdx, 0x198(%rbx)
leaq 0xf8(%rsp), %rdi
pushq $-0x1
popq %rcx
movq %r15, %rsi
callq 0x7540
movq (%r12), %rax
leaq 0xf8(%rsp), %rsi
movq %r12, %rdi
callq *0x20(%rax)
addq %rax, 0x198(%rbx)
leaq 0xf8(%rsp), %rdi
callq 0x79b8
movq 0x8(%rsp), %rsi
movq (%rsi), %rax
leaq 0x30(%rsp), %rdi
callq *0x10(%rax)
leaq 0x70bf(%rip), %rsi      # 0x2f81a
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0xc30e
leaq 0x6d86(%rip), %rdx      # 0x2f4f7
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xbe83
movq 0x8(%rsp), %rdi
callq 0x8964
leaq 0xd8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movq %rax, %rdx
callq 0xc1ca
leaq 0xd8(%rsp), %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x26da2
leaq 0xd8(%rsp), %rdi
callq 0x79b8
leaq 0x50(%rsp), %rdi
callq 0x79b8
leaq 0x10(%rsp), %rdi
callq 0x79b8
leaq 0x30(%rsp), %rdi
callq 0x79b8
leaq 0x140(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0x296d2
movq 0x8(%rsp), %rsi
movq (%rsi), %rax
leaq 0x10(%rsp), %rdi
callq *0x10(%rax)
leaq 0x50(%rsp), %rdi
callq 0x844c
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x84a4
leaq 0x10(%rsp), %r12
leaq 0x30(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0xc2ad
movl %eax, %ebp
movq %r13, %rdi
callq 0x79b8
leaq 0x50(%rsp), %rdi
callq 0x8484
movq %r12, %rdi
callq 0x79b8
testb %bpl, %bpl
je 0x28869
movq 0x8(%rsp), %rdi
callq 0x8964
movq %rax, %rdi
callq 0x16b90
cltq
movq %rax, 0x178(%rbx)
movq 0x8(%rsp), %rsi
movq (%rsi), %rax
leaq 0x10(%rsp), %rdi
callq *0x10(%rax)
leaq 0x50(%rsp), %rdi
callq 0x93a4
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x93fc
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xc2ad
testb %al, %al
je 0x288ec
movq 0x8(%rsp), %rdi
callq 0x8964
leaq 0x6f76(%rip), %rsi      # 0x2f82c
movq %rax, %rdi
callq 0x91b7
movl %eax, %ebp
leaq 0x30(%rsp), %rdi
callq 0x79b8
leaq 0x50(%rsp), %rdi
callq 0x93dc
leaq 0x10(%rsp), %rdi
callq 0x79b8
testb %bpl, %bpl
je 0x2890a
movb $0x1, 0x193(%rbx)
jmp 0x2890a
leaq 0x30(%rsp), %rdi
callq 0x79b8
leaq 0x50(%rsp), %rdi
callq 0x93dc
leaq 0x10(%rsp), %rdi
callq 0x79b8
movq 0x198(%rbx), %rax
movq (%r15), %rcx
cmpb $0xd, (%rcx,%rax)
jne 0x28982
cmpb $0xa, 0x1(%rcx,%rax)
jne 0x28982
addq $-0x2, %rax
movq %rax, 0x198(%rbx)
movq 0x28(%rbx), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
testb %al, %al
je 0x28942
addq $0x4, 0x198(%rbx)
leaq 0x6e88(%rip), %rsi      # 0x2f7d1
leaq 0xb8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x8032
leaq 0xb8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x26da2
leaq 0xb8(%rsp), %rdi
callq 0x79b8
movb $0x1, 0x190(%rbx)
leaq 0x98(%rsp), %rdi
callq 0x79b8
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
pushq $0x10
popq %rdi
callq 0x7290
movq %rax, %rbx
leaq 0x6e28(%rip), %rsi      # 0x2f7ec
movq %rax, %rdi
callq 0x7910
movq 0x1a5f5(%rip), %rsi     # 0x42fc8
movq 0x1a5d6(%rip), %rdx     # 0x42fb0
movq %rbx, %rdi
callq 0x7830
movl $0x1f4, 0x188(%rbx)     # imm = 0x1F4
pushq $0x10
popq %rdi
callq 0x7290
movq %rax, %rbx
leaq 0x6e0e(%rip), %rsi      # 0x2f80c
movq %rax, %rdi
callq 0x7910
movq 0x1a5bb(%rip), %rsi     # 0x42fc8
movq 0x1a59c(%rip), %rdx     # 0x42fb0
movq %rbx, %rdi
callq 0x7830
jmp 0x28b9b
movq %rax, %r14
leaq 0xb8(%rsp), %rdi
callq 0x79b8
jmp 0x28bbd
jmp 0x28b0f
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x86bc
jmp 0x28bbd
jmp 0x28b0f
movq %rdx, %r15
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x79b8
jmp 0x28aa2
movq %rax, %r14
movq %rbx, %rdi
callq 0x73d0
jmp 0x28bbd
movq %rax, %r14
movq %rbx, %rdi
callq 0x73d0
jmp 0x28bca
movq %rax, %r14
leaq 0x118(%rsp), %rdi
jmp 0x28bc5
movq %rax, %r14
jmp 0x28bca
movq %rdx, %r15
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x93dc
jmp 0x28acd
jmp 0x28ac7
jmp 0x28b3d
movq %rdx, %r15
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x8484
jmp 0x28acd
movq %rdx, %r15
movq %rax, %r14
leaq 0x10(%rsp), %rdi
jmp 0x28b36
jmp 0x28b3d
movq %rdx, %r15
movq %rax, %r14
leaq 0xd8(%rsp), %rdi
callq 0x79b8
jmp 0x28b1d
movq %rdx, %r15
movq %rax, %r14
jmp 0x28b27
movq %rdx, %r15
movq %rax, %r14
jmp 0x28b31
jmp 0x28b3d
movq %rdx, %r15
movq %rax, %r14
leaq 0xf8(%rsp), %rdi
jmp 0x28b36
jmp 0x28b0f
movq %rax, %r14
jmp 0x28bbd
movq %rdx, %r15
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x79b8
leaq 0x10(%rsp), %rdi
callq 0x79b8
leaq 0x30(%rsp), %rdi
callq 0x79b8
jmp 0x28b43
movq %rdx, %r15
movq %rax, %r14
cmpl $0x1, %r15d
jne 0x28bbd
movq %r14, %rdi
callq 0x7220
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x28b61
movq (%rdi), %rax
callq *0x8(%rax)
movl $0x190, 0x188(%rbx)     # imm = 0x190
pushq $0x10
popq %rdi
callq 0x7290
movq %rax, %rbx
leaq 0x6c6f(%rip), %rsi      # 0x2f7ec
movq %rax, %rdi
callq 0x7910
movq 0x1a43c(%rip), %rsi     # 0x42fc8
movq 0x1a41d(%rip), %rdx     # 0x42fb0
movq %rbx, %rdi
callq 0x7830
movq %rax, %r14
leaq 0x138(%rsp), %rdi
jmp 0x28bc5
movq %rax, %r14
jmp 0x28bb8
movq %rax, %r14
movq %rbx, %rdi
callq 0x73d0
callq 0x77f0
leaq 0x98(%rsp), %rdi
callq 0x79b8
movq %r14, %rdi
callq 0x7860
movq %rax, %rdi
callq 0x8f59