// File: /workspace/github_cpp_makefile_star2_O2/dentiny[P]HTTP-Cache-Proxy/Proxy.cpp
// Function: Proxy::handleRequest(int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void handleRequest(int client_id, int client_fd, const std::string & client_ip)
	{
		int server_fd = -1;
		Request request;

		try
		{
			// try to accept the request,
			// if an error occurs, throw the exception
			try
			{
				request = acceptRequest(client_fd);

				// record request to log
				std::string log_content = std::to_string(client_id) + ": " + request.httpAction + " from " + client_ip + " @ " + request.request_time;
				logger.log(log_content);
			}
			catch(std::exception & e)
			{
				throw e;
			}

			// try to connect server, and get the server fd
			// if an error occurs, throw the exception
			try
			{
				connectServer(request, server_fd);	
			}
			catch(std::exception & e)
			{
				throw e;
			}

			// handle specific http request
			try
			{
				std::string httpAction = request.httpAction;

				// record request to log, applied to GET, POST and CONNECT
				std::string log_content = std::to_string(client_id) + ": Requesting " + request.first_line + " from " + request.url;
				logger.log(log_content);

				if(httpAction == "CONNECT")
				{
					handleConnect(client_id, client_fd, server_fd, request);

					// write tunnel status to log
					std::string log_content = std::to_string(client_id) + ": Tunnel closed";
					logger.log(log_content); 
				}
				else if(httpAction == "GET")
				{
					// for GET http action, check caching first
					// if get return value true,
					// (1) either the cache is valid, has been sent by cache
					// (2) or the cache is invalid, needs to update the cache and resend it to client
					// anyway, the response has been sent to the client
					try
					{
						bool cacheValid = checkCaching(client_id, client_fd, server_fd, request);
						if(!cacheValid)
						{
							handleGetPost(client_id, client_fd, server_fd, request);
						}
					}
					catch(std::exception & e)
					{
						throw e;
					}
				}
				else if(httpAction == "POST")
				{
					std::cout << "begin post action" << std::endl;
					handleGetPost(client_id, client_fd, server_fd, request);
				}	
				else
				{
					throw ProxyException("Unknown HTTP request category");
				}

				// release client and server fd
				close(server_fd);
				close(client_fd);
			}
			catch(std::exception & e)
			{
				throw e;
			}
		}

		// when an exception happens, write the exception into log and quit the thread
		catch(std::exception & e)
		{
			// write exception into log
			std::string errMsg(e.what());
			std::string log_content = std::to_string(client_id) + ": ERROR " + errMsg;
			logger.log(log_content);

			// close the allocated resource
			close(client_fd);
			if(server_fd != -1) close(server_fd);
			return;
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x298, %rsp            # imm = 0x298
orl $-0x1, (%rsp)
leaq 0x1d0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %r8d, %r8d
movb %r8b, (%rax)
leaq 0x1f0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %r8b, (%rax)
leaq 0x210(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %r8b, (%rax)
leaq 0x230(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %r8b, (%rax)
leaq 0x250(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %rcx, %r15
movl %edx, %ebx
movb %r8b, (%rax)
leaq 0x270(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movl %esi, %ebp
movq %rdi, %r14
movb %r8b, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
andq $0x0, 0x20(%rax)
leaq 0xe8(%rsp), %rdi
movq %r14, %rsi
callq 0x47b0
leaq 0x1c0(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x4946
leaq 0xe8(%rsp), %rdi
callq 0x49c4
leaq 0xa8(%rsp), %rdi
movl %ebp, %esi
callq 0x4a4e
leaq 0x6386(%rip), %rdx      # 0xa338
leaq 0x68(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x4a2f
leaq 0x200(%rsp), %r12
leaq 0x88(%rsp), %rdi
leaq 0x68(%rsp), %rsi
movq %r12, %rdx
callq 0x4a10
leaq 0x6122(%rip), %rdx      # 0xa10a
leaq 0x28(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x4a2f
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movq %r15, %rdx
callq 0x4a10
leaq 0x60fe(%rip), %rdx      # 0xa111
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x4a2f
leaq 0xe8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x1c0(%rsp), %rdx
callq 0x4a10
leaq 0x48(%rsp), %rdi
callq 0x3150
leaq 0x8(%rsp), %rdi
callq 0x3150
leaq 0x28(%rsp), %rdi
callq 0x3150
leaq 0x88(%rsp), %rdi
callq 0x3150
leaq 0x68(%rsp), %rdi
callq 0x3150
leaq 0xa8(%rsp), %rdi
callq 0x3150
leaq 0x8(%r14), %r15
leaq 0xe8(%rsp), %rsi
movq %r15, %rdi
callq 0x4aa8
leaq 0xe8(%rsp), %rdi
callq 0x3150
leaq 0x1c0(%rsp), %rsi
movq %rsp, %rdx
movq %r14, %rdi
callq 0x4b28
leaq 0xe8(%rsp), %rdi
movq %r12, %rsi
callq 0x33d0
leaq 0x68(%rsp), %rdi
movl %ebp, %esi
callq 0x4a4e
leaq 0x6040(%rip), %rdx      # 0xa115
leaq 0x88(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x4a2f
leaq 0x1e0(%rsp), %rdx
leaq 0x28(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x4a10
leaq 0x6002(%rip), %rdx      # 0xa10a
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x4a2f
leaq 0x220(%rsp), %rdx
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x4a10
leaq 0x8(%rsp), %rdi
callq 0x3150
leaq 0x28(%rsp), %rdi
callq 0x3150
leaq 0x88(%rsp), %rdi
callq 0x3150
leaq 0x68(%rsp), %rdi
callq 0x3150
leaq 0x48(%rsp), %rsi
movq %r15, %rdi
callq 0x4aa8
leaq 0x5fb6(%rip), %rsi      # 0xa123
leaq 0xe8(%rsp), %rdi
callq 0x4cf4
testb %al, %al
je 0x41dd
movl (%rsp), %ecx
leaq 0x1c0(%rsp), %r8
movq %r14, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x4d02
leaq 0x28(%rsp), %rdi
movl %ebp, %esi
callq 0x4a4e
leaq 0x5f83(%rip), %rdx      # 0xa12b
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x4a2f
leaq 0x28(%rsp), %rdi
callq 0x3150
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x4aa8
leaq 0x8(%rsp), %rdi
callq 0x3150
jmp 0x4273
leaq 0x5f57(%rip), %rsi      # 0xa13b
leaq 0xe8(%rsp), %rdi
callq 0x4cf4
testb %al, %al
je 0x4229
movl (%rsp), %ecx
leaq 0x1c0(%rsp), %r8
movq %r14, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x506e
testb %al, %al
jne 0x4273
movl (%rsp), %ecx
leaq 0x1c0(%rsp), %r8
movq %r14, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x5558
jmp 0x4273
leaq 0x5f0f(%rip), %rsi      # 0xa13f
leaq 0xe8(%rsp), %rdi
callq 0x4cf4
testb %al, %al
je 0x42b8
movq 0xbd70(%rip), %rdi      # 0xffb8
leaq 0x5ef5(%rip), %rsi      # 0xa144
callq 0x3300
movq %rax, %rdi
callq 0x3180
movl (%rsp), %ecx
leaq 0x1c0(%rsp), %r8
movq %r14, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x5558
movl (%rsp), %edi
callq 0x3520
movl %ebx, %edi
callq 0x3520
leaq 0x48(%rsp), %rdi
callq 0x3150
leaq 0xe8(%rsp), %rdi
callq 0x3150
leaq 0x1c0(%rsp), %rdi
callq 0x49c4
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x28
popq %rdi
callq 0x3190
movq %rax, %r13
leaq 0x5e8c(%rip), %rsi      # 0xa156
leaq 0xc8(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x386c
movb $0x1, %al
movl %eax, 0x4(%rsp)
leaq 0xc8(%rsp), %rsi
movq %r13, %rdi
callq 0x55e8
movl $0x0, 0x4(%rsp)
leaq 0xba07(%rip), %rsi      # 0xfd08
leaq 0x1316(%rip), %rdx      # 0x561e
movq %r13, %rdi
callq 0x3490
jmp 0x4688
movq %rdx, %r12
movq %rax, %r15
leaq 0xc8(%rsp), %rdi
callq 0x3150
cmpb $0x0, 0x4(%rsp)
jne 0x433a
jmp 0x4570
movq %rdx, %r12
movq %rax, %r15
movq %r13, %rdi
callq 0x3240
jmp 0x4570
movq %rdx, %r12
movq %rax, %r15
cmpl $0x1, %r12d
jne 0x4570
movq %r15, %rdi
callq 0x3100
pushq $0x8
popq %rdi
callq 0x3190
movq 0xbc42(%rip), %rcx      # 0xffb0
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0xbc54(%rip), %rsi      # 0xffd0
movq 0xbc6d(%rip), %rdx      # 0xfff0
movq %rax, %rdi
callq 0x3490
jmp 0x4688
movq %rdx, %r12
movq %rax, %r15
callq 0x3470
jmp 0x4570
movq %rdx, %r12
movq %rax, %r15
leaq 0x8(%rsp), %rdi
jmp 0x43b8
movq %rdx, %r12
movq %rax, %r15
leaq 0x28(%rsp), %rdi
callq 0x3150
jmp 0x4570
jmp 0x456a
movq %rdx, %r12
movq %rax, %r15
leaq 0x8(%rsp), %rdi
callq 0x3150
jmp 0x43df
movq %rdx, %r12
movq %rax, %r15
leaq 0x28(%rsp), %rdi
callq 0x3150
jmp 0x43f1
movq %rdx, %r12
movq %rax, %r15
leaq 0x88(%rsp), %rdi
callq 0x3150
jmp 0x4406
movq %rdx, %r12
movq %rax, %r15
leaq 0x68(%rsp), %rdi
jmp 0x4575
movq %rdx, %r12
movq %rax, %r15
jmp 0x457a
movq %rdx, %r12
movq %rax, %r15
jmp 0x4587
movq %rdx, %r12
movq %rax, %r15
cmpl $0x1, %r12d
jne 0x4591
movq %r15, %rdi
callq 0x3100
pushq $0x8
popq %rdi
callq 0x3190
movq 0xbb63(%rip), %rcx      # 0xffb0
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0xbb75(%rip), %rsi      # 0xffd0
movq 0xbb8e(%rip), %rdx      # 0xfff0
movq %rax, %rdi
callq 0x3490
jmp 0x4688
movq %rdx, %r12
movq %rax, %r15
callq 0x3470
jmp 0x4591
movq %rdx, %r12
movq %rax, %r15
leaq 0xe8(%rsp), %rdi
jmp 0x44f2
movq %rdx, %r12
movq %rax, %r15
leaq 0x48(%rsp), %rdi
callq 0x3150
jmp 0x44a7
movq %rdx, %r12
movq %rax, %r15
leaq 0x8(%rsp), %rdi
callq 0x3150
jmp 0x44b9
movq %rdx, %r12
movq %rax, %r15
leaq 0x28(%rsp), %rdi
callq 0x3150
jmp 0x44cb
movq %rdx, %r12
movq %rax, %r15
leaq 0x88(%rsp), %rdi
callq 0x3150
jmp 0x44e0
movq %rdx, %r12
movq %rax, %r15
leaq 0x68(%rsp), %rdi
callq 0x3150
leaq 0xa8(%rsp), %rdi
callq 0x3150
jmp 0x451e
movq %rdx, %r12
movq %rax, %r15
jmp 0x44ea
jmp 0x4518
movq %rdx, %r12
movq %rax, %r15
leaq 0xe8(%rsp), %rdi
callq 0x49c4
jmp 0x451e
movq %rdx, %r12
movq %rax, %r15
cmpl $0x1, %r12d
jne 0x4591
movq %r15, %rdi
callq 0x3100
pushq $0x8
popq %rdi
callq 0x3190
movq 0xba75(%rip), %rcx      # 0xffb0
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0xba87(%rip), %rsi      # 0xffd0
movq 0xbaa0(%rip), %rdx      # 0xfff0
movq %rax, %rdi
callq 0x3490
jmp 0x4688
movq %rdx, %r12
movq %rax, %r15
callq 0x3470
jmp 0x4591
movq %rdx, %r12
movq %rax, %r15
leaq 0x48(%rsp), %rdi
callq 0x3150
leaq 0xe8(%rsp), %rdi
callq 0x3150
cmpl $0x1, %r12d
je 0x4654
cmpl $0x1, %r12d
jne 0x46df
movq %r15, %rdi
callq 0x3100
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
leaq 0xe8(%rsp), %rdi
leaq 0x48(%rsp), %rdx
movq %rax, %rsi
callq 0x386c
leaq 0x28(%rsp), %rdi
movl %ebp, %esi
callq 0x4a4e
leaq 0x5ba0(%rip), %rdx      # 0xa174
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x4a2f
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0xe8(%rsp), %rdx
callq 0x4a10
leaq 0x8(%rsp), %rdi
callq 0x3150
leaq 0x28(%rsp), %rdi
callq 0x3150
addq $0x8, %r14
leaq 0x48(%rsp), %rsi
movq %r14, %rdi
callq 0x4aa8
movl %ebx, %edi
callq 0x3520
movl (%rsp), %edi
cmpl $-0x1, %edi
je 0x4633
callq 0x3520
leaq 0x48(%rsp), %rdi
callq 0x3150
leaq 0xe8(%rsp), %rdi
callq 0x3150
callq 0x3470
jmp 0x4299
movq %r15, %rdi
callq 0x3100
pushq $0x8
popq %rdi
callq 0x3190
movq 0xb945(%rip), %rcx      # 0xffb0
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0xb957(%rip), %rsi      # 0xffd0
movq 0xb970(%rip), %rdx      # 0xfff0
movq %rax, %rdi
callq 0x3490
movq %rdx, %r12
movq %rax, %r15
callq 0x3470
jmp 0x4591
movq %rax, %r15
jmp 0x46df
movq %rax, %r15
leaq 0x8(%rsp), %rdi
callq 0x3150
jmp 0x46af
movq %rax, %r15
leaq 0x28(%rsp), %rdi
jmp 0x46c8
movq %rax, %r15
jmp 0x46cd
movq %rax, %r15
jmp 0x46da
movq %rax, %r15
leaq 0x48(%rsp), %rdi
callq 0x3150
leaq 0xe8(%rsp), %rdi
callq 0x3150
callq 0x3470
leaq 0x1c0(%rsp), %rdi
callq 0x49c4
movq %r15, %rdi
callq 0x34b0
movq %rax, %rdi
callq 0x3b8d