// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %rbx
subq $0x38, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movl 0x8(%rdx), %eax
testl %eax, %eax
je 0x235ca
movl 0x90(%r14), %ecx
movl %ecx, (%rbx)
movl 0x94(%r14), %edx
movl %edx, 0x4(%rbx)
cmpl $0x1, %ecx
sete %cl
cmpl $0x2, %edx
setb %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x23693
testl %eax, %eax
je 0x2350f
cmpq $0x0, 0x18(%rbx)
jne 0x2354b
movl $0xc8, 0x8(%rbx)
leaq -0x38(%rbp), %r14
movq %r14, %rdi
movl $0xc8, %esi
callq 0x22aa4
leaq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x8610
movq (%r14), %rdi
leaq -0x28(%rbp), %rax
cmpq %rax, %rdi
je 0x2354b
movq -0x28(%rbp), %rsi
incq %rsi
callq 0x8520
cmpq $0x0, 0x50(%rbx)
jne 0x2358e
movl 0x8(%rbx), %esi
leaq -0x38(%rbp), %r14
movq %r14, %rdi
callq 0x22aa4
leaq 0x48(%rbx), %rdi
movq %r14, %rsi
callq 0x8610
movq %rbx, %rdi
callq 0xb256
leaq -0x28(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2358e
movq -0x28(%rbp), %rsi
incq %rsi
callq 0x8520
cmpl $0x1, (%rbx)
jne 0x235af
cmpl $0x1, 0x4(%rbx)
jne 0x235af
leaq 0x1628(%rip), %rsi      # 0x24bc8
leaq 0x162c(%rip), %rdx      # 0x24bd3
movq %rbx, %rdi
callq 0xb198
leaq 0x2fb5(%rip), %rsi      # 0x2656b
leaq 0x2fb5(%rip), %rdx      # 0x26572
movq %rbx, %rdi
callq 0xb198
jmp 0x23693
movq 0x30(%rbx), %rcx
cmpq 0x38(%rbx), %rcx
jne 0x234da
cmpq $0x0, 0x18(%rbx)
jne 0x234da
cmpq $0x0, 0x50(%rbx)
jne 0x234da
callq 0x22f10
leaq -0x38(%rbp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x236ec
movq (%r15), %rdi
movq 0x8(%r15), %rsi
movl 0x90(%r14), %eax
leal (%rax,%rax,4), %eax
addl %eax, %eax
addl 0x94(%r14), %eax
leaq -0x50(%rbp), %rdx
movl %eax, (%rdx)
callq 0x23800
cmpq -0x30(%rbp), %rax
je 0x23671
callq 0x22f95
leaq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x2376c
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq %r14, %rdx
callq 0x23927
xorl %esi, %esi
cmpq -0x48(%rbp), %rax
sete %sil
orl $0x194, %esi            # imm = 0x194
movq %rbx, %rdi
callq 0xa5ba
leaq -0x50(%rbp), %rdi
callq 0x1d986
jmp 0x2367e
movq %rbx, %rdi
movl $0x1f9, %esi            # imm = 0x1F9
callq 0xa5ba
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x23693
movq -0x28(%rbp), %rsi
subq %rdi, %rsi
callq 0x8520
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x236cb
jmp 0x236a2
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1d986
jmp 0x236ce
jmp 0x236cb
movq %rax, %rbx
leaq -0x28(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x236e3
movq -0x28(%rbp), %rsi
incq %rsi
jmp 0x236de
movq %rax, %rbx
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x236e3
movq -0x28(%rbp), %rsi
subq %rdi, %rsi
callq 0x8520
movq %rbx, %rdi
callq 0x8830
nop