// File: mbourand[P]webserv/srcs/Response.cpp
// Function: Response::getResponseText[abi:cxx11](ConfigContext const&, bool)
std::string Response::getResponseText(const ConfigContext& config, bool generate_body)
{
	if (_code >= 300)
	{
		if ((_candeflate || _cangzip) && (g_webserv.compression_deflate || g_webserv.compression_gzip))
		{
			this->addHeader("Transfer-Encoding", "chunked");

			std::string errorPage = config.getErrorPage(_code);
			if (errorPage.size() > MIN_COMPRESS_SIZE)
				this->compressBody(errorPage);
			else
				_body = errorPage;

			if (!_body.empty())
				_body = Chunk(_body);
		}
		else
			this->addHeader("Content-Length", ft::toString(config.getErrorPage(_code).size()));
		this->addHeader("Content-Type", "text/html; charset=UTF-8");
		this->addHeader("Connection", "keep-alive");
		this->addDateHeader();
		this->addHeader("Server", "Webserv");
	}
	else
	{
		if (_body.size() > MIN_COMPRESS_SIZE && (g_webserv.compression_deflate || g_webserv.compression_gzip))
		{
			compressBody(_body);
			this->addHeader("Content-Length", ft::toString(_body.size()));
		}
	}
	std::stringstream ss;
	ss << _code;
	std::string code_str = ss.str();
	std::string str = "HTTP/1.1 " + code_str + " " + ft::getErrorMessage(_code) + "\r\n";

	for (std::map<std::string, std::string>::iterator it = _headers.begin(); it != _headers.end(); it++)
	{
		str += it->first + ": " + it->second + "\r\n";
	}
	str += "\r\n";


	if (!_body.empty() && generate_body)
		str += _body;
	if (_body.empty() && _code >= 300)
		str += config.getErrorPage(_code);

	return str;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x590, %rsp            # imm = 0x590
movq %rdi, -0x540(%rbp)
movb %cl, %al
movq %rdi, %rcx
movq %rcx, -0x538(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x530(%rbp)
cmpl $0x12c, 0x8(%rax)       # imm = 0x12C
jl 0x65002
movq -0x530(%rbp), %rax
testb $0x1, 0xc(%rax)
jne 0x649d5
movq -0x530(%rbp), %rax
testb $0x1, 0xd(%rax)
je 0x64bbc
leaq 0x2ad44(%rip), %rax     # 0x8f720
testb $0x1, 0xc8(%rax)
jne 0x649f9
leaq 0x2ad34(%rip), %rax     # 0x8f720
testb $0x1, 0xc9(%rax)
je 0x64bbc
leaq -0x41(%rbp), %rdi
movq %rdi, -0x548(%rbp)
callq 0x9b10
movq -0x548(%rbp), %rdx
leaq 0x584b(%rip), %rsi      # 0x6a262
leaq -0x40(%rbp), %rdi
callq 0xa780
jmp 0x64a22
leaq -0x79(%rbp), %rdi
movq %rdi, -0x550(%rbp)
callq 0x9b10
movq -0x550(%rbp), %rdx
leaq 0x921c(%rip), %rsi      # 0x6dc5c
leaq -0x78(%rbp), %rdi
callq 0xa780
jmp 0x64a4b
movq -0x530(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x63770
jmp 0x64a61
leaq -0x78(%rbp), %rdi
callq 0x9c98
leaq -0x79(%rbp), %rdi
callq 0x9700
leaq -0x40(%rbp), %rdi
callq 0x9c98
leaq -0x41(%rbp), %rdi
callq 0x9700
movq -0x530(%rbp), %rax
movq -0x18(%rbp), %rsi
movl 0x8(%rax), %edx
leaq -0xa0(%rbp), %rdi
callq 0x4c7e0
leaq -0xa0(%rbp), %rdi
callq 0x9480
cmpq $0x64, %rax
jbe 0x64b3d
movq -0x530(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x63c80
jmp 0x64aca
jmp 0x64b58
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x64b12
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x64b00
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x9c98
leaq -0x79(%rbp), %rdi
callq 0x9700
leaq -0x40(%rbp), %rdi
callq 0x9c98
leaq -0x41(%rbp), %rdi
callq 0x9700
jmp 0x65554
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x9c98
jmp 0x65554
movq -0x530(%rbp), %rdi
addq $0x60, %rdi
leaq -0xa0(%rbp), %rsi
callq 0x9070
jmp 0x64b56
jmp 0x64b58
movq -0x530(%rbp), %rdi
addq $0x60, %rdi
callq 0x9a50
testb $0x1, %al
jne 0x64bab
movq -0x530(%rbp), %rsi
movq %rsi, %rdx
addq $0x60, %rdx
leaq -0xc0(%rbp), %rdi
callq 0x637e0
jmp 0x64b88
movq -0x530(%rbp), %rdi
addq $0x60, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x97e0
leaq -0xc0(%rbp), %rdi
callq 0x9c98
leaq -0xa0(%rbp), %rdi
callq 0x9c98
jmp 0x64cdc
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x558(%rbp)
callq 0x9b10
movq -0x558(%rbp), %rdx
leaq 0x5527(%rip), %rsi      # 0x6a104
leaq -0xe0(%rbp), %rdi
callq 0xa780
jmp 0x64beb
movq -0x530(%rbp), %rax
movq -0x18(%rbp), %rsi
movl 0x8(%rax), %edx
leaq -0x128(%rbp), %rdi
callq 0x4c7e0
jmp 0x64c07
leaq -0x128(%rbp), %rdi
callq 0x9480
movl %eax, %esi
leaq -0x108(%rbp), %rdi
callq 0x2f700
jmp 0x64c23
movq -0x530(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
leaq -0x108(%rbp), %rdx
callq 0x63770
jmp 0x64c3f
leaq -0x108(%rbp), %rdi
callq 0x9c98
leaq -0x128(%rbp), %rdi
callq 0x9c98
leaq -0xe0(%rbp), %rdi
callq 0x9c98
leaq -0xe1(%rbp), %rdi
callq 0x9700
jmp 0x64cdc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x64ccb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x64cbf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x64cb3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x9c98
leaq -0x128(%rbp), %rdi
callq 0x9c98
leaq -0xe0(%rbp), %rdi
callq 0x9c98
leaq -0xe1(%rbp), %rdi
callq 0x9700
jmp 0x65554
leaq -0x149(%rbp), %rdi
movq %rdi, -0x560(%rbp)
callq 0x9b10
movq -0x560(%rbp), %rdx
leaq 0x5455(%rip), %rsi      # 0x6a152
leaq -0x148(%rbp), %rdi
callq 0xa780
jmp 0x64d0b
leaq -0x171(%rbp), %rdi
movq %rdi, -0x568(%rbp)
callq 0x9b10
movq -0x568(%rbp), %rdx
leaq 0x597b(%rip), %rsi      # 0x6a6a7
leaq -0x170(%rbp), %rdi
callq 0xa780
jmp 0x64d3a
movq -0x530(%rbp), %rdi
leaq -0x148(%rbp), %rsi
leaq -0x170(%rbp), %rdx
callq 0x63770
jmp 0x64d56
leaq -0x170(%rbp), %rdi
callq 0x9c98
leaq -0x171(%rbp), %rdi
callq 0x9700
leaq -0x148(%rbp), %rdi
callq 0x9c98
leaq -0x149(%rbp), %rdi
callq 0x9700
leaq -0x199(%rbp), %rdi
movq %rdi, -0x570(%rbp)
callq 0x9b10
movq -0x570(%rbp), %rdx
leaq 0x87bb(%rip), %rsi      # 0x6d562
leaq -0x198(%rbp), %rdi
callq 0xa780
jmp 0x64db5
leaq -0x1c1(%rbp), %rdi
movq %rdi, -0x578(%rbp)
callq 0x9b10
movq -0x578(%rbp), %rdx
leaq 0x8797(%rip), %rsi      # 0x6d56d
leaq -0x1c0(%rbp), %rdi
callq 0xa780
jmp 0x64de4
movq -0x530(%rbp), %rdi
leaq -0x198(%rbp), %rsi
leaq -0x1c0(%rbp), %rdx
callq 0x63770
jmp 0x64e00
leaq -0x1c0(%rbp), %rdi
callq 0x9c98
leaq -0x1c1(%rbp), %rdi
callq 0x9700
leaq -0x198(%rbp), %rdi
callq 0x9c98
leaq -0x199(%rbp), %rdi
callq 0x9700
movq -0x530(%rbp), %rdi
callq 0x63a60
leaq -0x1e9(%rbp), %rdi
movq %rdi, -0x580(%rbp)
callq 0x9b10
movq -0x580(%rbp), %rdx
leaq 0x53ef(%rip), %rsi      # 0x6a24c
leaq -0x1e8(%rbp), %rdi
callq 0xa780
jmp 0x64e6b
leaq -0x211(%rbp), %rdi
movq %rdi, -0x588(%rbp)
callq 0x9b10
movq -0x588(%rbp), %rdx
leaq 0x5d25(%rip), %rsi      # 0x6abb1
leaq -0x210(%rbp), %rdi
callq 0xa780
jmp 0x64e9a
movq -0x530(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
leaq -0x210(%rbp), %rdx
callq 0x63770
jmp 0x64eb6
leaq -0x210(%rbp), %rdi
callq 0x9c98
leaq -0x211(%rbp), %rdi
callq 0x9700
leaq -0x1e8(%rbp), %rdi
callq 0x9c98
leaq -0x1e9(%rbp), %rdi
callq 0x9700
jmp 0x65137
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x64f37
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x64f1f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x9c98
leaq -0x171(%rbp), %rdi
callq 0x9700
leaq -0x148(%rbp), %rdi
callq 0x9c98
leaq -0x149(%rbp), %rdi
callq 0x9700
jmp 0x65554
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x64f94
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x64f7c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x9c98
leaq -0x1c1(%rbp), %rdi
callq 0x9700
leaq -0x198(%rbp), %rdi
callq 0x9c98
leaq -0x199(%rbp), %rdi
callq 0x9700
jmp 0x65554
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x64ff1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x64fd9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x9c98
leaq -0x211(%rbp), %rdi
callq 0x9700
leaq -0x1e8(%rbp), %rdi
callq 0x9c98
leaq -0x1e9(%rbp), %rdi
callq 0x9700
jmp 0x65554
movq -0x530(%rbp), %rdi
addq $0x60, %rdi
callq 0x9480
cmpq $0x64, %rax
jbe 0x65135
leaq 0x2a6fd(%rip), %rax     # 0x8f720
testb $0x1, 0xc8(%rax)
jne 0x65040
leaq 0x2a6ed(%rip), %rax     # 0x8f720
testb $0x1, 0xc9(%rax)
je 0x65135
movq -0x530(%rbp), %rdi
movq %rdi, %rsi
addq $0x60, %rsi
callq 0x63c80
leaq -0x239(%rbp), %rdi
movq %rdi, -0x590(%rbp)
callq 0x9b10
movq -0x590(%rbp), %rdx
leaq 0x5090(%rip), %rsi      # 0x6a104
leaq -0x238(%rbp), %rdi
callq 0xa780
jmp 0x65082
movq -0x530(%rbp), %rdi
addq $0x60, %rdi
callq 0x9480
movl %eax, %esi
leaq -0x260(%rbp), %rdi
callq 0x2f700
jmp 0x650a2
movq -0x530(%rbp), %rdi
leaq -0x238(%rbp), %rsi
leaq -0x260(%rbp), %rdx
callq 0x63770
jmp 0x650be
leaq -0x260(%rbp), %rdi
callq 0x9c98
leaq -0x238(%rbp), %rdi
callq 0x9c98
leaq -0x239(%rbp), %rdi
callq 0x9700
jmp 0x65135
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x65124
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x65118
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x9c98
leaq -0x238(%rbp), %rdi
callq 0x9c98
leaq -0x239(%rbp), %rdi
callq 0x9700
jmp 0x65554
jmp 0x65137
leaq -0x3e8(%rbp), %rdi
callq 0x9490
movq -0x530(%rbp), %rax
leaq -0x3d8(%rbp), %rdi
movl 0x8(%rax), %esi
callq 0x9ad0
jmp 0x6515b
leaq -0x408(%rbp), %rdi
leaq -0x3e8(%rbp), %rsi
callq 0x9660
jmp 0x65170
movb $0x0, -0x409(%rbp)
leaq 0x8b73(%rip), %rsi      # 0x6dcf1
leaq -0x470(%rbp), %rdi
leaq -0x408(%rbp), %rdx
callq 0x14000
jmp 0x65193
leaq 0x883a(%rip), %rdx      # 0x6d9d4
leaq -0x450(%rbp), %rdi
leaq -0x470(%rbp), %rsi
callq 0x13970
jmp 0x651af
movq -0x530(%rbp), %rax
movl 0x8(%rax), %esi
leaq -0x490(%rbp), %rdi
callq 0x30210
jmp 0x651c7
leaq -0x430(%rbp), %rdi
leaq -0x450(%rbp), %rsi
leaq -0x490(%rbp), %rdx
callq 0x14210
jmp 0x651e3
movq -0x540(%rbp), %rdi
leaq 0x8abf(%rip), %rdx      # 0x6dcb0
leaq -0x430(%rbp), %rsi
callq 0x13970
jmp 0x651ff
leaq -0x430(%rbp), %rdi
callq 0x9c98
leaq -0x490(%rbp), %rdi
callq 0x9c98
leaq -0x450(%rbp), %rdi
callq 0x9c98
leaq -0x470(%rbp), %rdi
callq 0x9c98
movq -0x530(%rbp), %rdi
addq $0x30, %rdi
callq 0x4ddd0
movq %rax, -0x498(%rbp)
movq -0x530(%rbp), %rdi
addq $0x30, %rdi
callq 0x4de30
movq %rax, -0x4a0(%rbp)
leaq -0x498(%rbp), %rdi
leaq -0x4a0(%rbp), %rsi
callq 0x4de00
testb $0x1, %al
jne 0x65279
jmp 0x65423
leaq -0x498(%rbp), %rdi
callq 0x4de60
movq %rax, %rsi
leaq 0x89ca(%rip), %rdx      # 0x6dc59
leaq -0x500(%rbp), %rdi
callq 0x14190
jmp 0x6529d
leaq -0x498(%rbp), %rdi
callq 0x4de60
movq %rax, %rdx
addq $0x20, %rdx
leaq -0x4e0(%rbp), %rdi
leaq -0x500(%rbp), %rsi
callq 0x14140
jmp 0x652c5
leaq 0x89e4(%rip), %rdx      # 0x6dcb0
leaq -0x4c0(%rbp), %rdi
leaq -0x4e0(%rbp), %rsi
callq 0x13970
jmp 0x652e1
movq -0x540(%rbp), %rdi
leaq -0x4c0(%rbp), %rsi
callq 0x9830
jmp 0x652f6
leaq -0x4c0(%rbp), %rdi
callq 0x9c98
leaq -0x4e0(%rbp), %rdi
callq 0x9c98
leaq -0x500(%rbp), %rdi
callq 0x9c98
leaq -0x498(%rbp), %rdi
xorl %esi, %esi
callq 0x4de80
movq %rax, -0x508(%rbp)
jmp 0x65246
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x65548
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x6553c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x653b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x653a4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x65398
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x9c98
leaq -0x490(%rbp), %rdi
callq 0x9c98
leaq -0x450(%rbp), %rdi
callq 0x9c98
leaq -0x470(%rbp), %rdi
callq 0x9c98
jmp 0x6553c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x65530
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x65412
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x65406
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x4c0(%rbp), %rdi
callq 0x9c98
leaq -0x4e0(%rbp), %rdi
callq 0x9c98
leaq -0x500(%rbp), %rdi
callq 0x9c98
jmp 0x65530
movq -0x540(%rbp), %rdi
leaq 0x887f(%rip), %rsi      # 0x6dcb0
callq 0x9650
jmp 0x65438
movq -0x530(%rbp), %rdi
addq $0x60, %rdi
callq 0x9a50
testb $0x1, %al
jne 0x6546d
testb $0x1, -0x19(%rbp)
je 0x6546d
movq -0x540(%rbp), %rdi
movq -0x530(%rbp), %rsi
addq $0x60, %rsi
callq 0x9830
jmp 0x6546b
jmp 0x6546d
movq -0x530(%rbp), %rdi
addq $0x60, %rdi
callq 0x9a50
testb $0x1, %al
jne 0x65483
jmp 0x654ec
movq -0x530(%rbp), %rax
cmpl $0x12c, 0x8(%rax)       # imm = 0x12C
jl 0x654ec
movq -0x530(%rbp), %rax
movq -0x18(%rbp), %rsi
movl 0x8(%rax), %edx
leaq -0x528(%rbp), %rdi
callq 0x4c7e0
jmp 0x654af
movq -0x540(%rbp), %rdi
leaq -0x528(%rbp), %rsi
callq 0x9830
jmp 0x654c4
leaq -0x528(%rbp), %rdi
callq 0x9c98
jmp 0x654ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x528(%rbp), %rdi
callq 0x9c98
jmp 0x65530
movb $0x1, -0x409(%rbp)
testb $0x1, -0x409(%rbp)
jne 0x65508
movq -0x540(%rbp), %rdi
callq 0x9c98
leaq -0x408(%rbp), %rdi
callq 0x9c98
leaq -0x3e8(%rbp), %rdi
callq 0x94e0
movq -0x538(%rbp), %rax
addq $0x590, %rsp            # imm = 0x590
popq %rbp
retq
movq -0x540(%rbp), %rdi
callq 0x9c98
leaq -0x408(%rbp), %rdi
callq 0x9c98
leaq -0x3e8(%rbp), %rdi
callq 0x94e0
movq -0x50(%rbp), %rdi
callq 0x9af0
nopl (%rax)