// File: mbourand[P]webserv/srcs/Response.cpp
// Function: Response::compressBody(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void	Response::compressBody(const std::string &str)
{
	for (std::map<std::string, std::string>::iterator it = _headers.begin(); it != _headers.end(); it++) {
		if (it->first == "Content-Type") {
			if (it->second == "image/jpg" || it->second == "video/mp4" || it->second == "audio/mpeg") //skip format that are already compressed
				return;
			else
				break;
		}
	}
	try
	{
		_body = str;
		if (_candeflate && g_webserv.compression_deflate)
		{
			_body = compress_deflate(_body, g_webserv.compression_level);
			this->addHeader("Content-Encoding", "deflate");
		}
		if (_cangzip && g_webserv.compression_gzip)
		{
			_body = compress_gzip(_body, g_webserv.compression_level);
			this->removeHeader("Content-Encoding");
			if (_candeflate  && g_webserv.compression_deflate)
				this->addHeader("Content-Encoding", "deflate, gzip");
			else
				this->addHeader("Content-Encoding", "gzip");
		}
	}
	catch(const std::runtime_error& e)
	{
		Logger::print(e.what(), NULL, WARNING, NORMAL);
		removeHeader("Content-Encoding");
		removeHeader("Transfer-Encoding");
		_body = str;
		this->addHeader("Content-Length", ft::toString(str.size()));
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2d0, %rsp            # imm = 0x2D0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x260(%rbp)
addq $0x30, %rdi
callq 0x4ddd0
movq %rax, -0x18(%rbp)
movq -0x260(%rbp), %rdi
addq $0x30, %rdi
callq 0x4de30
movq %rax, -0x20(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x4de00
testb $0x1, %al
jne 0x63cd5
jmp 0x63d72
leaq -0x18(%rbp), %rdi
callq 0x4de60
movq %rax, %rdi
leaq 0x646a(%rip), %rsi      # 0x6a152
callq 0xdf50
testb $0x1, %al
jne 0x63cf3
jmp 0x63d5c
leaq -0x18(%rbp), %rdi
callq 0x4de60
movq %rax, %rdi
addq $0x20, %rdi
leaq 0x9fa9(%rip), %rsi      # 0x6dcb3
callq 0xdf50
testb $0x1, %al
jne 0x63d55
leaq -0x18(%rbp), %rdi
callq 0x4de60
movq %rax, %rdi
addq $0x20, %rdi
leaq 0x9f93(%rip), %rsi      # 0x6dcbd
callq 0xdf50
testb $0x1, %al
jne 0x63d55
leaq -0x18(%rbp), %rdi
callq 0x4de60
movq %rax, %rdi
addq $0x20, %rdi
leaq 0x9f7d(%rip), %rsi      # 0x6dcc7
callq 0xdf50
testb $0x1, %al
jne 0x63d55
jmp 0x63d5a
jmp 0x64431
jmp 0x63d72
jmp 0x63d5e
leaq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x4de80
movq %rax, -0x28(%rbp)
jmp 0x63cab
movq -0x260(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x60, %rdi
callq 0x9070
jmp 0x63d88
movq -0x260(%rbp), %rax
testb $0x1, 0xc(%rax)
je 0x63efc
leaq 0x2b980(%rip), %rax     # 0x8f720
testb $0x1, 0xc8(%rax)
je 0x63efc
movq -0x260(%rbp), %rsi
addq $0x60, %rsi
leaq 0x2b961(%rip), %rax     # 0x8f720
movl 0xcc(%rax), %edx
leaq -0x58(%rbp), %rdi
callq 0x22e90
jmp 0x63dd0
movq -0x260(%rbp), %rdi
addq $0x60, %rdi
leaq -0x58(%rbp), %rsi
movq %rsi, -0x270(%rbp)
callq 0x97e0
movq -0x270(%rbp), %rdi
callq 0x9c98
leaq -0x79(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x9b10
movq -0x268(%rbp), %rdx
leaq 0x9ebd(%rip), %rsi      # 0x6dcd2
leaq -0x78(%rbp), %rdi
callq 0xa780
jmp 0x63e20
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x278(%rbp)
callq 0x9b10
movq -0x278(%rbp), %rdx
leaq 0x7e65(%rip), %rsi      # 0x6bca6
leaq -0xa0(%rbp), %rdi
callq 0xa780
jmp 0x63e4f
movq -0x260(%rbp), %rdi
leaq -0x78(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0x63770
jmp 0x63e68
leaq -0xa0(%rbp), %rdi
callq 0x9c98
leaq -0xa1(%rbp), %rdi
callq 0x9700
leaq -0x78(%rbp), %rdi
callq 0x9c98
leaq -0x79(%rbp), %rdi
callq 0x9700
jmp 0x63efc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x6423c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x63eee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x63ed9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x9c98
leaq -0xa1(%rbp), %rdi
callq 0x9700
leaq -0x78(%rbp), %rdi
callq 0x9c98
leaq -0x79(%rbp), %rdi
callq 0x9700
jmp 0x6423c
movq -0x260(%rbp), %rax
testb $0x1, 0xd(%rax)
je 0x6443c
leaq 0x2b80c(%rip), %rax     # 0x8f720
testb $0x1, 0xc9(%rax)
je 0x6443c
movq -0x260(%rbp), %rsi
addq $0x60, %rsi
leaq 0x2b7ed(%rip), %rax     # 0x8f720
movl 0xcc(%rax), %edx
leaq -0xc8(%rbp), %rdi
callq 0x22c20
jmp 0x63f47
movq -0x260(%rbp), %rdi
addq $0x60, %rdi
leaq -0xc8(%rbp), %rsi
movq %rsi, -0x288(%rbp)
callq 0x97e0
movq -0x288(%rbp), %rdi
callq 0x9c98
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0x9b10
movq -0x280(%rbp), %rdx
leaq 0x9d40(%rip), %rsi      # 0x6dcd2
leaq -0xe8(%rbp), %rdi
callq 0xa780
jmp 0x63fa0
movq -0x260(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x637b0
jmp 0x63fb5
leaq -0xe8(%rbp), %rdi
callq 0x9c98
leaq -0xe9(%rbp), %rdi
callq 0x9700
movq -0x260(%rbp), %rax
testb $0x1, 0xc(%rax)
je 0x64135
leaq 0x2b73b(%rip), %rax     # 0x8f720
testb $0x1, 0xc8(%rax)
je 0x64135
leaq -0x111(%rbp), %rdi
movq %rdi, -0x290(%rbp)
callq 0x9b10
movq -0x290(%rbp), %rdx
leaq 0x9cbf(%rip), %rsi      # 0x6dcd2
leaq -0x110(%rbp), %rdi
callq 0xa780
jmp 0x64021
leaq -0x139(%rbp), %rdi
movq %rdi, -0x298(%rbp)
callq 0x9b10
movq -0x298(%rbp), %rdx
leaq 0x9ca1(%rip), %rsi      # 0x6dce3
leaq -0x138(%rbp), %rdi
callq 0xa780
jmp 0x64050
movq -0x260(%rbp), %rdi
leaq -0x110(%rbp), %rsi
leaq -0x138(%rbp), %rdx
callq 0x63770
jmp 0x6406c
leaq -0x138(%rbp), %rdi
callq 0x9c98
leaq -0x139(%rbp), %rdi
callq 0x9700
leaq -0x110(%rbp), %rdi
callq 0x9c98
leaq -0x111(%rbp), %rdi
callq 0x9700
jmp 0x6443a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x640c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x9c98
leaq -0xe9(%rbp), %rdi
callq 0x9700
jmp 0x6423c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x64124
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x6410c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x9c98
leaq -0x139(%rbp), %rdi
callq 0x9700
leaq -0x110(%rbp), %rdi
callq 0x9c98
leaq -0x111(%rbp), %rdi
callq 0x9700
jmp 0x6423c
leaq -0x161(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x9b10
movq -0x2a0(%rbp), %rdx
leaq 0x9b7c(%rip), %rsi      # 0x6dcd2
leaq -0x160(%rbp), %rdi
callq 0xa780
jmp 0x64164
leaq -0x189(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x9b10
movq -0x2a8(%rbp), %rdx
leaq 0x9b67(%rip), %rsi      # 0x6dcec
leaq -0x188(%rbp), %rdi
callq 0xa780
jmp 0x64193
movq -0x260(%rbp), %rdi
leaq -0x160(%rbp), %rsi
leaq -0x188(%rbp), %rdx
callq 0x63770
jmp 0x641af
leaq -0x188(%rbp), %rdi
callq 0x9c98
leaq -0x189(%rbp), %rdi
callq 0x9700
leaq -0x160(%rbp), %rdi
callq 0x9c98
leaq -0x161(%rbp), %rdi
callq 0x9700
jmp 0x6443a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x64230
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x64218
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x9c98
leaq -0x189(%rbp), %rdi
callq 0x9700
leaq -0x160(%rbp), %rdi
callq 0x9c98
leaq -0x161(%rbp), %rdi
callq 0x9700
movl -0x34(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x64543
movq -0x30(%rbp), %rdi
callq 0x92a0
movq %rax, -0x198(%rbp)
movq -0x198(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq %rax, -0x2b8(%rbp)
leaq -0x1b9(%rbp), %rdi
movq %rdi, -0x2b0(%rbp)
callq 0x9b10
movq -0x2b8(%rbp), %rsi
movq -0x2b0(%rbp), %rdx
leaq -0x1b8(%rbp), %rdi
callq 0xa780
jmp 0x642a2
xorl %eax, %eax
movl %eax, %esi
leaq -0x1b8(%rbp), %rdi
movl $0x2, %edx
movl $0x1, %ecx
callq 0x138a0
jmp 0x642be
leaq -0x1b8(%rbp), %rdi
callq 0x9c98
leaq -0x1b9(%rbp), %rdi
callq 0x9700
leaq -0x1e1(%rbp), %rdi
movq %rdi, -0x2c0(%rbp)
callq 0x9b10
movq -0x2c0(%rbp), %rdx
leaq 0x99db(%rip), %rsi      # 0x6dcd2
leaq -0x1e0(%rbp), %rdi
callq 0xa780
jmp 0x64305
movq -0x260(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x637b0
jmp 0x6431a
leaq -0x1e0(%rbp), %rdi
callq 0x9c98
leaq -0x1e1(%rbp), %rdi
callq 0x9700
leaq -0x209(%rbp), %rdi
movq %rdi, -0x2c8(%rbp)
callq 0x9b10
movq -0x2c8(%rbp), %rdx
leaq 0x5f0f(%rip), %rsi      # 0x6a262
leaq -0x208(%rbp), %rdi
callq 0xa780
jmp 0x64361
movq -0x260(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x637b0
jmp 0x64376
leaq -0x208(%rbp), %rdi
callq 0x9c98
leaq -0x209(%rbp), %rdi
callq 0x9700
movq -0x260(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x60, %rdi
callq 0x9070
jmp 0x643a4
leaq -0x231(%rbp), %rdi
movq %rdi, -0x2d0(%rbp)
callq 0x9b10
movq -0x2d0(%rbp), %rdx
leaq 0x5d3f(%rip), %rsi      # 0x6a104
leaq -0x230(%rbp), %rdi
callq 0xa780
jmp 0x643d3
movq -0x10(%rbp), %rdi
callq 0x9480
movl %eax, %esi
leaq -0x258(%rbp), %rdi
callq 0x2f700
jmp 0x643ec
movq -0x260(%rbp), %rdi
leaq -0x230(%rbp), %rsi
leaq -0x258(%rbp), %rdx
callq 0x63770
jmp 0x64408
leaq -0x258(%rbp), %rdi
callq 0x9c98
leaq -0x230(%rbp), %rdi
callq 0x9c98
leaq -0x231(%rbp), %rdi
callq 0x9700
callq 0x9a40
addq $0x2d0, %rsp            # imm = 0x2D0
popq %rbp
retq
jmp 0x6443c
jmp 0x64431
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x64464
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x9c98
leaq -0x1b9(%rbp), %rdi
callq 0x9700
jmp 0x6453a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x6449b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x9c98
leaq -0x1e1(%rbp), %rdi
callq 0x9700
jmp 0x6453a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x644d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x9c98
leaq -0x209(%rbp), %rdi
callq 0x9700
jmp 0x6453a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x6453a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x6452e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x64522
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x9c98
leaq -0x230(%rbp), %rdi
callq 0x9c98
leaq -0x231(%rbp), %rdi
callq 0x9700
callq 0x9a40
jmp 0x64541
jmp 0x64543
movq -0x30(%rbp), %rdi
callq 0x9af0
movq %rax, %rdi
callq 0xaa90
nopw %cs:(%rax,%rax)