// File: /workspace/github_cpp_makefile_star2_O3/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 0x22eba
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 0x22f83
testl %eax, %eax
je 0x22dff
cmpq $0x0, 0x18(%rbx)
jne 0x22e3b
movl $0xc8, 0x8(%rbx)
leaq -0x38(%rbp), %r14
movq %r14, %rdi
movl $0xc8, %esi
callq 0x223b0
leaq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x8610
movq (%r14), %rdi
leaq -0x28(%rbp), %rax
cmpq %rax, %rdi
je 0x22e3b
movq -0x28(%rbp), %rsi
incq %rsi
callq 0x8520
cmpq $0x0, 0x50(%rbx)
jne 0x22e7e
movl 0x8(%rbx), %esi
leaq -0x38(%rbp), %r14
movq %r14, %rdi
callq 0x223b0
leaq 0x48(%rbx), %rdi
movq %r14, %rsi
callq 0x8610
movq %rbx, %rdi
callq 0xb1e4
leaq -0x28(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x22e7e
movq -0x28(%rbp), %rsi
incq %rsi
callq 0x8520
cmpl $0x1, (%rbx)
jne 0x22e9f
cmpl $0x1, 0x4(%rbx)
jne 0x22e9f
leaq 0x1d38(%rip), %rsi      # 0x24bc8
leaq 0x1d3c(%rip), %rdx      # 0x24bd3
movq %rbx, %rdi
callq 0xb126
leaq 0x36c5(%rip), %rsi      # 0x2656b
leaq 0x36c5(%rip), %rdx      # 0x26572
movq %rbx, %rdi
callq 0xb126
jmp 0x22f83
movq 0x30(%rbx), %rcx
cmpq 0x38(%rbx), %rcx
jne 0x22dca
cmpq $0x0, 0x18(%rbx)
jne 0x22dca
cmpq $0x0, 0x50(%rbx)
jne 0x22dca
callq 0x2281c
leaq -0x38(%rbp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x22fdc
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 0x230f0
cmpq -0x30(%rbp), %rax
je 0x22f61
callq 0x228a1
leaq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x2305c
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq %r14, %rdx
callq 0x23223
xorl %esi, %esi
cmpq -0x48(%rbp), %rax
sete %sil
orl $0x194, %esi            # imm = 0x194
movq %rbx, %rdi
callq 0xa54e
leaq -0x50(%rbp), %rdi
callq 0x1d4e0
jmp 0x22f6e
movq %rbx, %rdi
movl $0x1f9, %esi            # imm = 0x1F9
callq 0xa54e
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x22f83
movq -0x28(%rbp), %rsi
subq %rdi, %rsi
callq 0x8520
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x22fbb
jmp 0x22f92
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1d4e0
jmp 0x22fbe
jmp 0x22fbb
movq %rax, %rbx
leaq -0x28(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x22fd3
movq -0x28(%rbp), %rsi
incq %rsi
jmp 0x22fce
movq %rax, %rbx
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x22fd3
movq -0x28(%rbp), %rsi
subq %rdi, %rsi
callq 0x8520
movq %rbx, %rdi
callq 0x8830
nop