// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x30(%rdi), %r15
movq 0x48(%rdi), %r12
leaq 0x38(%rdi), %rbp
leaq 0x1cff(%rip), %r13      # 0x2c152
cmpq %rbp, %r12
je 0x2a4bf
leaq 0x20(%r12), %rdi
movq %r13, %rsi
callq 0x91b7
testb %al, %al
jne 0x2a476
movq %r12, %rdi
callq 0x7390
movq %rax, %r12
jmp 0x2a453
addq $0x40, %r12
leaq 0x5402(%rip), %rsi      # 0x2f883
movq %r12, %rdi
callq 0x91b7
testb %al, %al
jne 0x2a67c
leaq 0x53f5(%rip), %rsi      # 0x2f88d
movq %r12, %rdi
callq 0x91b7
testb %al, %al
jne 0x2a67c
leaq 0x53e8(%rip), %rsi      # 0x2f897
movq %r12, %rdi
callq 0x91b7
testb %al, %al
jne 0x2a67c
leaq 0x60(%rbx), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x7300
cmpb $0x1, 0xc(%rbx)
jne 0x2a565
leaq 0x190d1(%rip), %rax     # 0x435b0
cmpb $0x1, 0xc8(%rax)
jne 0x2a565
movl 0xcc(%rax), %edx
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x124cf
leaq 0x8(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x75f0
movq %r13, %rdi
callq 0x79b8
leaq 0x5388(%rip), %rsi      # 0x2f8a2
leaq 0x8(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0x8032
leaq 0x334e(%rip), %rsi      # 0x2d87e
leaq 0x28(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x8032
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
callq 0x2a124
leaq 0x28(%rsp), %rdi
callq 0x79b8
leaq 0x8(%rsp), %rdi
callq 0x79b8
cmpb $0x1, 0xd(%rbx)
jne 0x2a67c
leaq 0x1903a(%rip), %rbp     # 0x435b0
cmpb $0x1, 0xc9(%rbp)
jne 0x2a67c
movl 0xcc(%rbp), %edx
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x12374
leaq 0x8(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x75f0
movq %r13, %rdi
callq 0x79b8
leaq 0x52ed(%rip), %rsi      # 0x2f8a2
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x8032
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2b2ca
leaq 0x8(%rsp), %rdi
callq 0x79b8
cmpb $0x1, 0xc(%rbx)
jne 0x2a62a
cmpb $0x1, 0xc8(%rbp)
jne 0x2a62a
leaq 0x52b1(%rip), %rsi      # 0x2f8a2
leaq 0x8(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0x8032
leaq 0x52ac(%rip), %rsi      # 0x2f8b3
leaq 0x28(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x8032
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
callq 0x2a124
jmp 0x2a668
leaq 0x5271(%rip), %rsi      # 0x2f8a2
leaq 0x8(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0x8032
leaq 0x5275(%rip), %rsi      # 0x2f8bc
leaq 0x28(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x8032
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
callq 0x2a124
leaq 0x28(%rsp), %rdi
callq 0x79b8
leaq 0x8(%rsp), %rdi
callq 0x79b8
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2a699
jmp 0x2a6ad
jmp 0x2a6c5
jmp 0x2a699
jmp 0x2a6ad
jmp 0x2a6c5
jmp 0x2a6ad
movq %rdx, %rbp
movq %rax, %r13
leaq 0x28(%rsp), %rdi
callq 0x79b8
jmp 0x2a6b3
jmp 0x2a6c5
movq %rdx, %rbp
movq %rax, %r13
leaq 0x8(%rsp), %rdi
callq 0x79b8
jmp 0x2a6cb
jmp 0x2a6c5
jmp 0x2a6c5
jmp 0x2a6c5
movq %rdx, %rbp
movq %rax, %r13
cmpl $0x1, %ebp
jne 0x2a808
movq %r13, %rdi
callq 0x7220
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rdx
movq %rax, %rsi
callq 0x8032
leaq 0x48(%rsp), %rdi
pushq $0x2
popq %rdx
pushq $0x1
popq %rcx
xorl %esi, %esi
callq 0xbe10
leaq 0x48(%rsp), %rdi
callq 0x79b8
leaq 0x5188(%rip), %rsi      # 0x2f8a2
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x8032
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2b2ca
leaq 0x8(%rsp), %rdi
callq 0x79b8
leaq 0x1b1b(%rip), %rsi      # 0x2c262
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x8032
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2b2ca
leaq 0x8(%rsp), %rdi
callq 0x79b8
movq %r12, %rdi
movq %r14, %rsi
callq 0x7300
leaq 0x1985(%rip), %rsi      # 0x2c104
leaq 0x8(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0x8032
movl 0x8(%r14), %esi
leaq 0x28(%rsp), %rdi
callq 0x16dd9
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
callq 0x2a124
leaq 0x28(%rsp), %rdi
callq 0x79b8
leaq 0x8(%rsp), %rdi
callq 0x79b8
callq 0x77f0
jmp 0x2a67c
movq %rax, %r13
leaq 0x28(%rsp), %rdi
callq 0x79b8
jmp 0x2a7e8
jmp 0x2a7e5
jmp 0x2a800
jmp 0x2a800
jmp 0x2a7e5
jmp 0x2a800
movq %rax, %r13
leaq 0x8(%rsp), %rdi
callq 0x79b8
jmp 0x2a803
jmp 0x2a800
movq %rax, %r13
leaq 0x48(%rsp), %rdi
jmp 0x2a7ed
movq %rax, %r13
callq 0x77f0
movq %r13, %rdi
callq 0x7860
movq %rax, %rdi
callq 0x8f59