// File: /workspace/github_cpp_makefile_star2_O2/mbourand[P]webserv/srcs/tcp-server.cpp
// Function: handle_server_response(Client&)
bool	handle_server_response(Client &client)
{
	try
	{
		if (g_webserv.debug)
			std::cout << *client.req << std::endl;
		VirtualHost vhost = VirtualHost::getServerByName(client.req->getHeaderValue("Host"), client.sckt->getServerPort(), g_webserv.vhosts);
		Response response;
		if (client.req->_error_code)
			response.setCode(client.req->_error_code);
		try
		{
			if (!response.getCode() && !vhost.getConfig().getConfigPath(client.req->_url._path).getParam("auth_basic").front().empty())
			{
				std::string	credentials = client.req->getHeaderValue(AuthorizationHeader().getType());
					if (credentials.empty())
					{
						response.setCode(401); //Unauthorized (force sign-in)
						response.addHeader(WWWAuthenticateHeader().getType(), "Basic realm=\""+vhost.getConfig().getConfigPath(client.req->_url._path).getParam("auth_basic").front()+"\"");
					}
					else if (!g_webserv.creds->Check_Credentials(vhost.getConfig().getConfigPath(client.req->_url._path).getParam("auth_basic_user_file").front(), credentials.substr(6))) //TODO: comparer credentials avec ceux dans le fichier	login:password -> bG9naW46cGFzc3dvcmQ=
						response.setCode(403); //forbidden (wrong credentials)
			}
		}
		catch (std::exception& e)
		{
			response.setCode(500);
		}
		if (!response.getCode())
		{
			if (!ft::contains(vhost.getConfig().getConfigPath(client.req->_url._path).getAllowedMethods(), client.req->_method))
				response.setCode(405);
		}
		if (!response.getCode())
			response = client.req->_method->process(*client.req, vhost.getConfig().getConfigPath(client.req->_url._path), *client.sckt);
		if (client.req->_protocolVersion == "HTTP/1.0")
			response.addHeader("Connection", "keep-alive");
		*client.sckt << response.getResponseText(vhost.getConfig().getConfigPath(client.req->_url._path), (client.req->_method ? client.req->_method->getType() != "HEAD" : true));
		if (g_webserv.debug)
			std::cout << "served response " << response.getCode() << std::endl;
		if (response.getCode() != 200)
			return true;
		Logger::print("Success", NULL, SUCCESS, VERBOSE);
	}
	catch(ServerSocket::ServerSocketException &e)
	{
		Logger::print(e.what(), NULL, ERROR, NORMAL);
	}
	catch(std::invalid_argument &e)
	{
		client.req->_error_code = 500;
		Logger::print(e.what(), NULL, ERROR, NORMAL);
	}
	if (client.req && client.sckt->Success())
	{
		delete client.req;
		client.req = new Request(client.sckt->getServerPort());
	}
	return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x380, %rsp            # imm = 0x380
movq %rdi, %rbx
cmpb $0x1, 0x1ef6f(%rip)     # 0x435b1
jne 0x2465c
movq 0x8(%rbx), %rsi
movq 0x1e959(%rip), %rdi     # 0x42fa8
callq 0x29408
movq %rax, %rdi
callq 0x7280
movq 0x8(%rbx), %r14
leaq 0x7b52(%rip), %rsi      # 0x2c1b9
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x8032
leaq 0x108(%rsp), %rdi
leaq 0x48(%rsp), %rdx
movq %r14, %rsi
callq 0x292c2
movq (%rbx), %rdi
callq 0xf19a
leaq 0x1efbe(%rip), %rdx     # 0x43658
leaq 0x108(%rsp), %rdi
movl %eax, %esi
callq 0x2b724
leaq 0x248(%rsp), %rdi
movq %rax, %rsi
callq 0x2b4ca
leaq 0x108(%rsp), %rdi
callq 0x79b8
leaq 0x48(%rsp), %rdi
callq 0x79b8
leaq 0x108(%rsp), %rdi
callq 0x29ea4
movq 0x8(%rbx), %rax
movl 0x188(%rax), %esi
testl %esi, %esi
je 0x246f8
leaq 0x108(%rsp), %rdi
callq 0x2a818
leaq 0x108(%rsp), %rdi
callq 0x2a820
testl %eax, %eax
jne 0x24975
leaq 0x248(%rsp), %rdi
callq 0x2b716
movl $0xb8, %esi
addq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x21cc6
movq %rax, %r14
leaq 0xa5e9(%rip), %rsi      # 0x2ed1e
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x8032
leaq 0x48(%rsp), %rsi
movq %r14, %rdi
callq 0x2167a
movq (%rax), %rax
movq 0x18(%rax), %r14
leaq 0x48(%rsp), %rdi
callq 0x79b8
testq %r14, %r14
je 0x24975
movq 0x8(%rbx), %r14
leaq 0x48(%rsp), %rdi
callq 0x830c
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x8364
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %r14, %rsi
callq 0x292c2
leaq 0x28(%rsp), %rdi
callq 0x79b8
leaq 0x48(%rsp), %rdi
callq 0x8344
cmpq $0x0, 0x10(%rsp)
je 0x2486a
movq 0x1eebf(%rip), %r14     # 0x43680
leaq 0x248(%rsp), %rdi
callq 0x2b716
movl $0xb8, %esi
addq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x21cc6
movq %rax, %r15
leaq 0x84ff(%rip), %rsi      # 0x2cce8
leaq 0x48(%rsp), %rdi
leaq 0xe8(%rsp), %rdx
callq 0x8032
leaq 0x48(%rsp), %rsi
movq %r15, %rdi
callq 0x2167a
movq (%rax), %r15
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
pushq $0x6
popq %rdx
pushq $-0x1
popq %rcx
callq 0x7540
addq $0x10, %r15
leaq 0x28(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x129da
movl %eax, %ebp
leaq 0x28(%rsp), %rdi
callq 0x79b8
leaq 0x48(%rsp), %rdi
callq 0x79b8
testb %bpl, %bpl
jne 0x2496b
leaq 0x108(%rsp), %rdi
movl $0x193, %esi            # imm = 0x193
callq 0x2a818
jmp 0x2496b
leaq 0x108(%rsp), %rdi
movl $0x191, %esi            # imm = 0x191
callq 0x2a818
leaq 0x48(%rsp), %rdi
callq 0x94e4
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x953c
leaq 0x248(%rsp), %rdi
callq 0x2b716
movl $0xb8, %esi
addq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x21cc6
movq %rax, %r14
leaq 0xa461(%rip), %rsi      # 0x2ed1e
leaq 0x208(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x8032
leaq 0x208(%rsp), %rsi
movq %r14, %rdi
callq 0x2167a
movq (%rax), %rdx
addq $0x10, %rdx
leaq 0xa82e(%rip), %rsi      # 0x2f11b
leaq 0x228(%rsp), %rdi
callq 0xc154
leaq 0xaf71(%rip), %rdx      # 0x2f872
leaq 0xe8(%rsp), %rdi
leaq 0x228(%rsp), %rsi
callq 0xbe83
leaq 0x108(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0xe8(%rsp), %rdx
callq 0x2a124
leaq 0xe8(%rsp), %rdi
callq 0x79b8
leaq 0x228(%rsp), %rdi
callq 0x79b8
leaq 0x208(%rsp), %rdi
callq 0x79b8
leaq 0x28(%rsp), %rdi
callq 0x79b8
leaq 0x48(%rsp), %rdi
callq 0x951c
leaq 0x8(%rsp), %rdi
callq 0x79b8
leaq 0x108(%rsp), %rdi
callq 0x2a820
testl %eax, %eax
jne 0x249d2
leaq 0x248(%rsp), %rdi
callq 0x2b716
movl $0xb8, %esi
addq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x21cc6
movq %rax, %rdi
callq 0x2166a
movq 0x8(%rbx), %rsi
addq $0x28, %rsi
movq %rax, %rdi
callq 0x26e08
testb %al, %al
jne 0x249d2
leaq 0x108(%rsp), %rdi
movl $0x195, %esi            # imm = 0x195
callq 0x2a818
leaq 0x108(%rsp), %rdi
callq 0x2a820
testl %eax, %eax
jne 0x24a3d
movq 0x8(%rbx), %r14
movq 0x28(%r14), %r15
leaq 0x248(%rsp), %rdi
callq 0x2b716
movl $0xb8, %esi
addq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x21cc6
movq (%rbx), %r8
movq (%r15), %r9
leaq 0x48(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rax, %rcx
callq *0x70(%r9)
leaq 0x108(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x2a01e
leaq 0x48(%rsp), %rdi
callq 0x29f10
movl $0x120, %edi            # imm = 0x120
addq 0x8(%rbx), %rdi
leaq 0xa6dc(%rip), %rsi      # 0x2f129
callq 0x91b7
testb %al, %al
je 0x24ab0
leaq 0xa6d5(%rip), %rsi      # 0x2f132
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x8032
leaq 0xa6ca(%rip), %rsi      # 0x2f13d
leaq 0x8(%rsp), %rdi
leaq 0xe8(%rsp), %rdx
callq 0x8032
leaq 0x108(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x2a124
leaq 0x8(%rsp), %rdi
callq 0x79b8
leaq 0x48(%rsp), %rdi
callq 0x79b8
movq (%rbx), %r14
leaq 0x248(%rsp), %rdi
callq 0x2b716
movl $0xb8, %esi
addq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x21cc6
movq %rax, %r15
movq 0x8(%rbx), %rax
movq 0x28(%rax), %r12
testq %r12, %r12
je 0x24b03
movq (%r12), %rax
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
callq *0x10(%rax)
leaq 0x7cb6(%rip), %rsi      # 0x2c7ad
leaq 0x8(%rsp), %rdi
callq 0x8f4f
jmp 0x24b05
movb $0x1, %al
movzbl %al, %ecx
leaq 0x48(%rsp), %rdi
leaq 0x108(%rsp), %rsi
movq %r15, %rdx
callq 0x2a996
leaq 0x48(%rsp), %rsi
movq %r14, %rdi
callq 0xef44
leaq 0x48(%rsp), %rdi
callq 0x79b8
testq %r12, %r12
je 0x24b43
leaq 0x8(%rsp), %rdi
callq 0x79b8
cmpb $0x1, 0x1ea67(%rip)     # 0x435b1
jne 0x24b81
movq 0x1e455(%rip), %rdi     # 0x42fa8
leaq 0xa5ee(%rip), %rsi      # 0x2f148
callq 0x7510
movq %rax, %r14
leaq 0x108(%rsp), %rdi
callq 0x2a820
movq %r14, %rdi
movl %eax, %esi
callq 0x7840
movq %rax, %rdi
callq 0x7280
leaq 0x108(%rsp), %rdi
callq 0x2a820
cmpl $0xc8, %eax
jne 0x24c36
leaq 0xa5b9(%rip), %rsi      # 0x2f159
leaq 0x1e8(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x8032
leaq 0x1e8(%rsp), %rdi
pushq $0x1
popq %rdx
xorl %esi, %esi
xorl %ecx, %ecx
callq 0xbe10
leaq 0x1e8(%rsp), %rdi
callq 0x79b8
leaq 0x108(%rsp), %rdi
callq 0x29f10
leaq 0x248(%rsp), %rdi
callq 0x2b6d6
cmpq $0x0, 0x8(%rbx)
je 0x24c32
movq (%rbx), %rdi
callq 0xf2ec
testb %al, %al
je 0x24c32
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x24c0f
movq (%rdi), %rax
callq *0x8(%rax)
movl $0x1a0, %edi            # imm = 0x1A0
callq 0x7520
movq %rax, %r15
movq (%rbx), %rdi
callq 0xf19a
movq %r15, %rdi
movl %eax, %esi
callq 0x274d8
movq %r15, 0x8(%rbx)
xorl %eax, %eax
jmp 0x24c52
leaq 0x108(%rsp), %rdi
callq 0x29f10
leaq 0x248(%rsp), %rdi
callq 0x2b6d6
movb $0x1, %al
addq $0x380, %rsp            # imm = 0x380
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r15
movq %rax, %r14
leaq 0xe8(%rsp), %rdi
callq 0x79b8
jmp 0x24c7d
movq %rdx, %r15
movq %rax, %r14
leaq 0x228(%rsp), %rdi
callq 0x79b8
jmp 0x24ccf
jmp 0x24cde
movq %rdx, %r15
movq %rax, %r14
jmp 0x24cee
jmp 0x24d65
movq %rdx, %r15
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x79b8
jmp 0x24cb5
jmp 0x24caf
movq %rdx, %r15
movq %rax, %r14
leaq 0x48(%rsp), %rdi
callq 0x79b8
jmp 0x24d6b
jmp 0x24d65
movq %rdx, %r15
movq %rax, %r14
leaq 0x208(%rsp), %rdi
callq 0x79b8
jmp 0x24ce4
movq %rdx, %r15
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x79b8
leaq 0x48(%rsp), %rdi
callq 0x951c
jmp 0x24d6b
movq %rdx, %r15
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x79b8
jmp 0x24d12
movq %rdx, %r15
movq %rax, %r14
leaq 0x48(%rsp), %rdi
callq 0x8344
jmp 0x24e10
jmp 0x24e0a
movq %rax, %r14
movl $0x1a0, %esi            # imm = 0x1A0
movq %r15, %rdi
callq 0x7530
movq %r14, %rdi
callq 0x7860
movq %rdx, %r15
movq %rax, %r14
leaq 0x48(%rsp), %rdi
callq 0x29f10
jmp 0x24e70
movq %rdx, %r15
movq %rax, %r14
leaq 0x48(%rsp), %rdi
jmp 0x24d70
jmp 0x24e0a
movq %rdx, %r15
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x79b8
jmp 0x24e10
movq %rdx, %r15
movq %rax, %r14
leaq 0x1e8(%rsp), %rdi
jmp 0x24dde
jmp 0x24e6a
movq %rdx, %r15
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x79b8
jmp 0x24da7
movq %rdx, %r15
movq %rax, %r14
leaq 0x48(%rsp), %rdi
jmp 0x24dde
jmp 0x24e6a
jmp 0x24e6a
movq %rdx, %r15
movq %rax, %r14
leaq 0x48(%rsp), %rdi
callq 0x79b8
jmp 0x24dd0
movq %rdx, %r15
movq %rax, %r14
testq %r12, %r12
je 0x24e70
leaq 0x8(%rsp), %rdi
callq 0x79b8
jmp 0x24e70
movq %rdx, %r15
movq %rax, %r14
jmp 0x24e7d
movq %rdx, %r15
movq %rax, %r14
jmp 0x24e5e
jmp 0x24dfd
movq %rdx, %r15
movq %rax, %r14
jmp 0x24e8a
jmp 0x24e6a
movq %rdx, %r15
movq %rax, %r14
cmpl $0x3, %r15d
jne 0x24e70
movq %r14, %rdi
callq 0x7220
leaq 0x108(%rsp), %rdi
movl $0x1f4, %esi            # imm = 0x1F4
callq 0x2a818
callq 0x77f0
jmp 0x24975
jmp 0x24e6a
movq %rdx, %r15
movq %rax, %r14
callq 0x77f0
jmp 0x24e70
jmp 0x24e6a
movq %rdx, %r15
movq %rax, %r14
leaq 0x108(%rsp), %rdi
callq 0x79b8
leaq 0x48(%rsp), %rdi
callq 0x79b8
jmp 0x24e8a
movq %rdx, %r15
movq %rax, %r14
leaq 0x108(%rsp), %rdi
callq 0x29f10
leaq 0x248(%rsp), %rdi
callq 0x2b6d6
cmpl $0x2, %r15d
jne 0x24ed8
movq %r14, %rdi
callq 0x7220
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
leaq 0x1a8(%rsp), %rdi
leaq 0x248(%rsp), %rdx
movq %rax, %rsi
callq 0x8032
leaq 0x1a8(%rsp), %rdi
pushq $0x3
popq %rdx
pushq $0x1
popq %rcx
xorl %esi, %esi
callq 0xbe10
leaq 0x1a8(%rsp), %rdi
jmp 0x24f36
cmpl $0x1, %r15d
jne 0x24d36
movq %r14, %rdi
callq 0x7220
movq 0x8(%rbx), %rcx
movl $0x1f4, 0x188(%rcx)     # imm = 0x1F4
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
leaq 0x1c8(%rsp), %rdi
leaq 0x248(%rsp), %rdx
movq %rax, %rsi
callq 0x8032
leaq 0x1c8(%rsp), %rdi
pushq $0x3
popq %rdx
pushq $0x1
popq %rcx
xorl %esi, %esi
callq 0xbe10
leaq 0x1c8(%rsp), %rdi
callq 0x79b8
callq 0x77f0
jmp 0x24bed
movq %rax, %r14
leaq 0x1c8(%rsp), %rdi
callq 0x79b8
jmp 0x24f5a
movq %rax, %r14
callq 0x77f0
jmp 0x24d36
movq %rax, %r14
leaq 0x1a8(%rsp), %rdi
callq 0x79b8
jmp 0x24f79
movq %rax, %r14
callq 0x77f0
jmp 0x24d36
movq %rax, %rdi
callq 0x8f59