// File: trisolaris233[P]httpc/src/request_handler.cpp
// Function: httpc::RequestHandler::Respond(httpc::Request&, httpc::Response&)
void RequestHandler::Respond(Request& request, Response& response) {
        if (response.Empty()) {
            //std::cout << "empty" << std::endl;
            // check whether http version is supported
            auto HttpVersionSupported = GetHttpVersionSupported();
            if (std::find(
                HttpVersionSupported.begin(), 
                HttpVersionSupported.end(), 
                request.http_major_version * 10 + request.http_minor_version
            ) == HttpVersionSupported.end()) {
                //debug().dg("ver").lf();
                response.SetDefault(HTTPStatusCodeEnum::kHTTPVersionNotSupported);
                return;
            }

            // check whether the http method is supported
            auto HttpMethodSupported = GetHttpMethodSupported();
            if (std::find(
                HttpMethodSupported.begin(),
                HttpMethodSupported.end(), 
                request.method
            ) == HttpMethodSupported.end()) {
                response.SetDefault(HTTPStatusCodeEnum::kMethodNotAllowed);
                return;
            }

            return response.SetDefault(HTTPStatusCodeEnum::kNotFound);   
        }
        
        response.http_major_version = request.http_major_version;
        response.http_minor_version = request.http_minor_version;

        if (response.http_major_version == 1) {
            // http/1.1
            if (response.http_minor_version == 1 || response.http_minor_version == 0) {
                if (response.IsEmptyReasonPhrase() || response.IsEmptyStatusCode()) {
                    response.SetStatusCode(HTTPStatusCodeEnum::kOk);
                }
                if (response.IsEmptyMessageBody()) {
                    response.RenderString(GetHTTPReasonPhrase(response.status_code));
                }
                
                response.SetDefaultHeaders();
            }
        }
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x57090
testb $0x1, %al
jne 0x56d29
jmp 0x56f01
callq 0x553a0
movq %rax, %rsi
leaq -0x30(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x57100
movq -0xd8(%rbp), %rdi
callq 0x57280
movq -0xd8(%rbp), %rdi
movq %rax, -0x40(%rbp)
callq 0x572b0
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl 0x90(%rax), %edx
movl 0x94(%rax), %ecx
movl %edx, %eax
leal (%rax,%rax,4), %edx
movl %ecx, %eax
movl %edx, %ecx
leal (%rax,%rcx,2), %eax
movl %eax, -0x4c(%rbp)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
leaq -0x4c(%rbp), %rdx
callq 0x57230
movq %rax, -0xd0(%rbp)
jmp 0x56d9a
movq -0xd0(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x572b0
movq %rax, -0x68(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x571f0
testb $0x1, %al
jne 0x56dc5
jmp 0x56df2
movq -0x18(%rbp), %rdi
movl $0x1f9, %esi            # imm = 0x1F9
callq 0xf680
jmp 0x56dd5
movl $0x1, -0x6c(%rbp)
jmp 0x56ee5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x56ef3
callq 0x55450
movq %rax, %rsi
leaq -0x88(%rbp), %rdi
callq 0x572e0
jmp 0x56e08
leaq -0x88(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x44760
movq -0xe8(%rbp), %rdi
movq %rax, -0x98(%rbp)
callq 0x445a0
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rdx
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %rsi
callq 0x57410
movq %rax, -0xe0(%rbp)
jmp 0x56e55
movq -0xe0(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x445a0
movq %rax, -0xa8(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x573d0
testb $0x1, %al
jne 0x56e8f
jmp 0x56ec2
movq -0x18(%rbp), %rdi
movl $0x195, %esi            # imm = 0x195
callq 0xf680
jmp 0x56e9f
movl $0x1, -0x6c(%rbp)
jmp 0x56ed9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x43ff0
jmp 0x56ef3
movq -0x18(%rbp), %rdi
movl $0x194, %esi            # imm = 0x194
callq 0xf680
jmp 0x56ed2
movl $0x1, -0x6c(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x43ff0
leaq -0x30(%rbp), %rdi
callq 0x55750
jmp 0x56fe9
leaq -0x30(%rbp), %rdi
callq 0x55750
jmp 0x56ff2
movq -0x10(%rbp), %rax
movl 0x90(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl 0x94(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x56fe9
movq -0x18(%rbp), %rax
cmpl $0x1, 0x4(%rax)
je 0x56f47
movq -0x18(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x56fe7
movq -0x18(%rbp), %rdi
callq 0x57460
testb $0x1, %al
jne 0x56f63
movq -0x18(%rbp), %rdi
callq 0x57490
testb $0x1, %al
jne 0x56f63
jmp 0x56f71
movq -0x18(%rbp), %rdi
movl $0xc8, %esi
callq 0x574b0
movq -0x18(%rbp), %rdi
callq 0x57500
testb $0x1, %al
jne 0x56f80
jmp 0x56fde
movq -0x18(%rbp), %rax
movq %rax, -0xf8(%rbp)
movl 0x8(%rax), %esi
leaq -0xc8(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x54730
movq -0xf8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
callq 0x57530
jmp 0x56fb6
leaq -0xc8(%rbp), %rdi
callq 0xa450
jmp 0x56fde
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0xa450
jmp 0x56ff2
movq -0x18(%rbp), %rdi
callq 0x57560
jmp 0x56fe9
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0xab10
nopl (%rax,%rax)