// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq 0x48(%rdi), %r15
leaq 0x38(%rdi), %r13
cmpq %r13, %r15
je 0x37a2f
leaq 0x278e(%rip), %r12      # 0x3a152
leaq 0x20(%r15), %rdi
movq %r12, %rsi
callq 0x7180
testl %eax, %eax
je 0x379e6
movq %r15, %rdi
callq 0x7350
movq %rax, %r15
cmpq %r13, %rax
jne 0x379c4
jmp 0x37a2f
addq $0x40, %r15
leaq 0x5f02(%rip), %rsi      # 0x3d8f3
movq %r15, %rdi
callq 0x7180
testl %eax, %eax
je 0x37cb6
leaq 0x5ef5(%rip), %rsi      # 0x3d8fd
movq %r15, %rdi
callq 0x7180
testl %eax, %eax
je 0x37cb6
leaq 0x5ee8(%rip), %rsi      # 0x3d907
movq %r15, %rdi
callq 0x7180
testl %eax, %eax
je 0x37cb6
leaq 0x30(%r14), %r15
leaq 0x60(%r14), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x72c0
cmpb $0x1, 0xc(%r14)
jne 0x37b23
leaq 0x16b14(%rip), %rax     # 0x4e568
cmpb $0x1, 0xc8(%rax)
jne 0x37b23
movl 0xcc(%rax), %edx
leaq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x1702a
leaq 0x18(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x7590
movq (%r13), %rdi
leaq 0x28(%rsp), %r13
cmpq %r13, %rdi
je 0x37a9f
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x18(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x5e64(%rip), %rsi      # 0x3d912
leaq 0x5e6d(%rip), %rdx      # 0x3d922
callq 0x80f4
leaq 0x48(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x3e00(%rip), %rsi      # 0x3b8ca
leaq 0x3e00(%rip), %rdx      # 0x3b8d1
leaq 0x38(%rsp), %rdi
callq 0x80f4
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x38cee
leaq 0x38(%rsp), %rsi
movq %rax, %rdi
callq 0x72c0
movq 0x38(%rsp), %rdi
cmpq %rbp, %rdi
je 0x37b0c
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x37b23
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
cmpb $0x1, 0xd(%r14)
jne 0x37cb6
leaq 0x16a33(%rip), %rbp     # 0x4e568
cmpb $0x1, 0xc9(%rbp)
jne 0x37cb6
movl 0xcc(%rbp), %edx
leaq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x16eb4
leaq 0x18(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x7590
movq (%r13), %rdi
leaq 0x28(%rsp), %r13
cmpq %r13, %rdi
je 0x37b80
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x18(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x5d83(%rip), %rsi      # 0x3d912
leaq 0x5d8c(%rip), %rdx      # 0x3d922
callq 0x80f4
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x38ff4
movq %r15, %rdi
movq %rax, %rsi
callq 0x3909c
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x37bca
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
cmpb $0x1, 0xc(%r14)
jne 0x37c32
cmpb $0x1, 0xc8(%rbp)
jne 0x37c32
leaq 0x18(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x5d29(%rip), %rsi      # 0x3d912
leaq 0x5d32(%rip), %rdx      # 0x3d922
callq 0x80f4
leaq 0x48(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x5d1e(%rip), %rsi      # 0x3d923
leaq 0x5d24(%rip), %rdx      # 0x3d930
leaq 0x38(%rsp), %rdi
callq 0x80f4
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x38cee
leaq 0x38(%rsp), %rsi
movq %rax, %rdi
callq 0x72c0
jmp 0x37c88
leaq 0x18(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x5cd1(%rip), %rsi      # 0x3d912
leaq 0x5cda(%rip), %rdx      # 0x3d922
callq 0x80f4
leaq 0x48(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x5ccf(%rip), %rsi      # 0x3d92c
leaq 0x5ccc(%rip), %rdx      # 0x3d930
leaq 0x38(%rsp), %rdi
callq 0x80f4
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x38cee
leaq 0x38(%rsp), %rsi
movq %rax, %rdi
callq 0x72c0
movq 0x38(%rsp), %rdi
cmpq %rbp, %rdi
je 0x37c9f
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x37cb6
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x37cdb
jmp 0x37d21
jmp 0x37ce7
jmp 0x37cdb
jmp 0x37d21
jmp 0x37d21
jmp 0x37cdb
jmp 0x37d21
jmp 0x37d21
jmp 0x37d21
jmp 0x37ce7
movq %rdx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
jmp 0x37d08
movq %rdx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq 0x38(%rsp), %rdi
cmpq %rbp, %rdi
je 0x37d08
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x37d2b
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x37d2b
movq %rdx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
cmpl $0x1, 0x10(%rsp)
jne 0x37f09
movq 0x8(%rsp), %rdi
callq 0x7210
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
leaq 0x58(%rsp), %rdi
leaq 0x18(%rsp), %rdx
movq %rax, %rsi
callq 0xde9a
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
movl $0x2, %edx
movl $0x1, %ecx
callq 0xded8
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x37d8c
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x28(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x5b76(%rip), %rsi      # 0x3d912
leaq 0x5b7f(%rip), %rdx      # 0x3d922
leaq 0x18(%rsp), %rdi
callq 0x80f4
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0x37466
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x37dd1
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x18(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x24cd(%rip), %rsi      # 0x3a2ad
leaq 0x24d7(%rip), %rdx      # 0x3a2be
callq 0x80f4
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0x37466
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x37e10
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
movq %r12, %rdi
movq %rbx, %rsi
callq 0x72c0
leaq 0x18(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x22da(%rip), %rsi      # 0x3a104
leaq 0x22e1(%rip), %rdx      # 0x3a112
callq 0x80f4
movl 0x8(%rbx), %esi
leaq 0x38(%rsp), %rdi
callq 0x1c07f
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x38cee
leaq 0x38(%rsp), %rsi
movq %rax, %rdi
callq 0x72c0
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x37e78
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x37e8f
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
callq 0x7780
jmp 0x37cb6
jmp 0x37ea3
jmp 0x37ec6
jmp 0x37ec6
jmp 0x37ea3
jmp 0x37ec6
movq %rax, 0x8(%rsp)
jmp 0x37eed
jmp 0x37ec6
movq %rax, 0x8(%rsp)
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x37f04
movq 0x68(%rsp), %rsi
jmp 0x37efc
movq %rax, 0x8(%rsp)
jmp 0x37f04
movq %rax, 0x8(%rsp)
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x37eed
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x37f04
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
callq 0x7780
movq 0x8(%rsp), %rdi
callq 0x7810
movq %rax, %rdi
callq 0x96cc
nop