// File: /workspace/github_cpp_makefile_star2_O2/guoxuanhan[P]NetServer/httpsession.cpp
// Function: HttpSession::PraseHttpRequest(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, _HttpRequestContext&)
bool HttpSession::PraseHttpRequest(std::string &msg, HttpRequestContext &httprequestcontext)
{
    //std::cout << "HttpServer::HttpParser" << std::endl;
    std::string crlf("\r\n"), crlfcrlf("\r\n\r\n");
    size_t prev = 0, next = 0, pos_colon;
    std::string key, value;

    bool praseresult = false;
    //以下解析可以改成状态机，解决一次收Http报文不完整问题
    //prase http request line
    if ((next = msg.find(crlf, prev)) != std::string::npos)
    {
        std::string first_line(msg.substr(prev, next - prev));
        prev = next;
        std::stringstream sstream(first_line);
        sstream >> (httprequestcontext.method);
        sstream >> (httprequestcontext.url);
        sstream >> (httprequestcontext.version);
    }
    else
    {
        std::cout << "msg" << msg << std::endl;
        std::cout << "Error in httpPraser: http_request_line isn't complete!" << std::endl;
        praseresult = false;
        msg.clear();
        return praseresult;
        //可以临时存起来，凑齐了再解析
    }
    //prase http request header
    size_t pos_crlfcrlf = 0;
    if (( pos_crlfcrlf = msg.find(crlfcrlf, prev)) != std::string::npos)
    {
        while (prev != pos_crlfcrlf)
        {
            next = msg.find(crlf, prev + 2);
            pos_colon = msg.find(":", prev + 2);
            key = msg.substr(prev + 2, pos_colon - prev-2);
            value = msg.substr(pos_colon + 2, next-pos_colon-2);
            prev = next;
            httprequestcontext.header.insert(std::pair<std::string, std::string>(key, value));
        }
    }
    else
    {
        std::cout << "Error in httpPraser: http_request_header isn't complete!" << std::endl;
        praseresult = false;
        msg.clear();
        return praseresult;
    }
    //prase http request body
    httprequestcontext.body = msg.substr(pos_crlfcrlf + 4);
    praseresult = true;
    msg.clear();
    return praseresult;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movq %rdx, %r15
movq %rsi, %rbx
leaq 0x670f(%rip), %rsi      # 0xea39
leaq 0x20(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
callq 0x4130
leaq 0x66f4(%rip), %rsi      # 0xea37
leaq 0xa0(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
callq 0x4130
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x4600
cmpq $-0x1, %rax
je 0x8560
movq %rax, %r12
leaq 0x40(%rsp), %rdi
movq %rbx, (%rsp)
movq %rbx, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x4330
leaq 0xc0(%rsp), %rdi
leaq 0x40(%rsp), %rsi
pushq $0x18
popq %rdx
callq 0x44d0
leaq 0xc0(%rsp), %rdi
movq %r15, %rsi
callq 0x43e0
leaq 0x20(%r15), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x43e0
leaq 0x40(%r15), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x43e0
leaq 0xc0(%rsp), %rdi
callq 0x4270
leaq 0x40(%rsp), %rdi
callq 0x4170
leaq 0xa0(%rsp), %rsi
movq (%rsp), %rdi
movq %r12, %rdx
callq 0x4600
movq %rax, 0x8(%rsp)
cmpq $-0x1, %rax
je 0x85a5
movq %r15, 0x10(%rsp)
leaq 0x60(%r15), %rax
movq %rax, 0x18(%rsp)
leaq 0x80(%rsp), %r15
movq (%rsp), %r14
cmpq 0x8(%rsp), %r12
je 0x851a
movq %r15, %rbx
leaq 0x2(%r12), %r15
movq %r14, %rdi
leaq 0x20(%rsp), %rsi
movq %r15, %rdx
callq 0x4600
movq %rax, %rbp
movq %r14, %rdi
leaq 0x6f80(%rip), %rsi      # 0xf3fa
movq %r15, %rdx
callq 0x45f0
movq %rax, %r13
movq %rax, %rcx
subq %r12, %rcx
addq $-0x2, %rcx
leaq 0xc0(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4330
movq %rbx, %r15
movq %rbx, %rdi
movq %r12, %rsi
callq 0x43c0
movq %r12, %rdi
callq 0x4170
movq %rbp, %rcx
subq %r13, %rcx
addq $0x2, %r13
addq $-0x2, %rcx
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x4330
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x43c0
movq %r12, %rdi
callq 0x4170
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x925a
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x9612
movq %r12, %rdi
callq 0x9290
movq %rbp, %r12
jmp 0x844a
movq 0x8(%rsp), %rdx
addq $0x4, %rdx
leaq 0xc0(%rsp), %rdi
pushq $-0x1
popq %rcx
movq (%rsp), %rsi
callq 0x4330
movq 0x10(%rsp), %rdi
addq $0x90, %rdi
leaq 0xc0(%rsp), %r14
movq %r14, %rsi
callq 0x43c0
movq %r14, %rdi
callq 0x4170
movb $0x1, %bpl
jmp 0x85c2
movq 0xfa51(%rip), %rdi      # 0x17fb8
leaq 0x64ce(%rip), %rsi      # 0xea3c
callq 0x4300
movq %rax, %rdi
movq %rbx, %rsi
callq 0x42c0
movq %rax, %rdi
callq 0x41a0
movq 0xfa2b(%rip), %rdi      # 0x17fb8
leaq 0x64ac(%rip), %rsi      # 0xea40
callq 0x4300
movq %rax, %rdi
callq 0x41a0
xorl %ebp, %ebp
jmp 0x85c6
movq 0xfa0c(%rip), %rdi      # 0x17fb8
leaq 0x64c4(%rip), %rsi      # 0xea77
callq 0x4300
movq %rax, %rdi
callq 0x41a0
xorl %ebp, %ebp
movq (%rsp), %rbx
andq $0x0, 0x8(%rbx)
movq (%rbx), %rax
movb $0x0, (%rax)
leaq 0x60(%rsp), %rdi
callq 0x4170
leaq 0x80(%rsp), %rdi
callq 0x4170
leaq 0xa0(%rsp), %rdi
callq 0x4170
leaq 0x20(%rsp), %rdi
callq 0x4170
movl %ebp, %eax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8645
jmp 0x8645
movq %rax, %rbx
jmp 0x8633
jmp 0x8645
movq %rax, %rbx
jmp 0x867e
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x4270
leaq 0x40(%rsp), %rdi
callq 0x4170
jmp 0x865a
jmp 0x8645
jmp 0x8645
jmp 0x8645
movq %rax, %rbx
jmp 0x865a
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x9290
leaq 0x60(%rsp), %rdi
callq 0x4170
leaq 0x80(%rsp), %rdi
callq 0x4170
leaq 0xa0(%rsp), %rdi
callq 0x4170
leaq 0x20(%rsp), %rdi
callq 0x4170
movq %rbx, %rdi
callq 0x4570