// File: 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:
subq $0x3b8, %rsp            # imm = 0x3B8
movq %rdi, 0x3a8(%rsp)
movq %rsi, 0x3a0(%rsp)
movq %rdx, 0x398(%rsp)
leaq 0x377(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x5670
movq 0x68(%rsp), %rdx
leaq 0x13b3c(%rip), %rsi     # 0x28a19
leaq 0x378(%rsp), %rdi
callq 0x54d0
jmp 0x14eec
leaq 0x377(%rsp), %rdi
callq 0x5400
leaq 0x33f(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x5670
movq 0x60(%rsp), %rdx
leaq 0x13b00(%rip), %rsi     # 0x28a17
leaq 0x340(%rsp), %rdi
callq 0x54d0
jmp 0x14f26
leaq 0x33f(%rsp), %rdi
callq 0x5400
movq $0x0, 0x330(%rsp)
movq $0x0, 0x328(%rsp)
leaq 0x300(%rsp), %rdi
callq 0x54f0
leaq 0x2e0(%rsp), %rdi
callq 0x54f0
movb $0x0, 0x2df(%rsp)
movq 0x3a0(%rsp), %rdi
movq 0x330(%rsp), %rdx
leaq 0x378(%rsp), %rsi
callq 0x5710
movq %rax, 0x328(%rsp)
cmpq $-0x1, %rax
je 0x15120
movq 0x3a0(%rsp), %rsi
movq 0x330(%rsp), %rdx
movq 0x328(%rsp), %rcx
subq %rdx, %rcx
leaq 0x2b8(%rsp), %rdi
callq 0x53d0
jmp 0x14fc6
movq 0x328(%rsp), %rax
movq %rax, 0x330(%rsp)
movl $0x10, %edi
movl $0x8, %esi
callq 0x16a40
movl %eax, 0x5c(%rsp)
jmp 0x14feb
movl 0x5c(%rsp), %edx
leaq 0x130(%rsp), %rdi
leaq 0x2b8(%rsp), %rsi
callq 0x55a0
jmp 0x15006
movq 0x398(%rsp), %rsi
leaq 0x130(%rsp), %rdi
callq 0x5490
jmp 0x1501d
movq 0x398(%rsp), %rsi
addq $0x20, %rsi
leaq 0x130(%rsp), %rdi
callq 0x5490
jmp 0x15038
movq 0x398(%rsp), %rsi
addq $0x40, %rsi
leaq 0x130(%rsp), %rdi
callq 0x5490
jmp 0x15053
leaq 0x130(%rsp), %rdi
callq 0x52e0
leaq 0x2b8(%rsp), %rdi
callq 0x5270
jmp 0x151c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x368(%rsp)
movl %eax, 0x364(%rsp)
leaq 0x377(%rsp), %rdi
callq 0x5400
jmp 0x15521
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x368(%rsp)
movl %eax, 0x364(%rsp)
leaq 0x33f(%rsp), %rdi
callq 0x5400
jmp 0x15514
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x368(%rsp)
movl %eax, 0x364(%rsp)
jmp 0x154ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x368(%rsp)
movl %eax, 0x364(%rsp)
jmp 0x1510e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x368(%rsp)
movl %eax, 0x364(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x52e0
leaq 0x2b8(%rsp), %rdi
callq 0x5270
jmp 0x154ed
movq 0x25e89(%rip), %rdi     # 0x3afb0
leaq 0x138ee(%rip), %rsi     # 0x28a1c
callq 0x53a0
movq %rax, 0x50(%rsp)
jmp 0x1513a
movq 0x50(%rsp), %rdi
movq 0x3a0(%rsp), %rsi
callq 0x5340
movq %rax, 0x48(%rsp)
jmp 0x15153
movq 0x48(%rsp), %rdi
movq 0x25e21(%rip), %rsi     # 0x3af80
callq 0x53f0
jmp 0x15166
movq 0x25e43(%rip), %rdi     # 0x3afb0
leaq 0x138ac(%rip), %rsi     # 0x28a20
callq 0x53a0
movq %rax, 0x40(%rsp)
jmp 0x15180
movq 0x40(%rsp), %rdi
movq 0x25df4(%rip), %rsi     # 0x3af80
callq 0x53f0
jmp 0x15193
movb $0x0, 0x2df(%rsp)
movq 0x3a0(%rsp), %rdi
callq 0x54b0
movb 0x2df(%rsp), %al
andb $0x1, %al
movb %al, 0x3b7(%rsp)
movl $0x1, 0x12c(%rsp)
jmp 0x154a8
movq $0x0, 0x120(%rsp)
movq 0x3a0(%rsp), %rdi
movq 0x330(%rsp), %rdx
leaq 0x340(%rsp), %rsi
callq 0x5710
movq %rax, 0x120(%rsp)
cmpq $-0x1, %rax
je 0x153cf
jmp 0x15205
movq 0x330(%rsp), %rax
cmpq 0x120(%rsp), %rax
je 0x153cd
movq 0x3a0(%rsp), %rdi
movq 0x330(%rsp), %rdx
addq $0x2, %rdx
leaq 0x378(%rsp), %rsi
callq 0x5710
movq %rax, 0x328(%rsp)
movq 0x3a0(%rsp), %rdi
movq 0x330(%rsp), %rdx
addq $0x2, %rdx
leaq 0x1417b(%rip), %rsi     # 0x293da
callq 0x56f0
movq %rax, 0x320(%rsp)
movq 0x3a0(%rsp), %rsi
movq 0x330(%rsp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq 0x320(%rsp), %rcx
subq %rax, %rcx
addq $-0x2, %rcx
leaq 0x100(%rsp), %rdi
callq 0x53d0
jmp 0x152a1
leaq 0x300(%rsp), %rdi
leaq 0x100(%rsp), %rsi
movq %rsi, 0x38(%rsp)
callq 0x5470
movq 0x38(%rsp), %rdi
callq 0x5270
movq 0x3a0(%rsp), %rsi
movq 0x320(%rsp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq 0x328(%rsp), %rcx
subq %rax, %rcx
addq $-0x2, %rcx
leaq 0xe0(%rsp), %rdi
callq 0x53d0
jmp 0x152fa
leaq 0x2e0(%rsp), %rdi
movq %rdi, 0x28(%rsp)
leaq 0xe0(%rsp), %rsi
movq %rsi, 0x20(%rsp)
callq 0x5470
movq 0x20(%rsp), %rdi
callq 0x5270
movq 0x28(%rsp), %rdx
movq 0x328(%rsp), %rax
movq %rax, 0x330(%rsp)
movq 0x398(%rsp), %rax
addq $0x60, %rax
movq %rax, 0x30(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x300(%rsp), %rsi
callq 0x16ab0
jmp 0x15360
movq 0x30(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x16a60
movb %dl, 0x17(%rsp)
movq %rax, 0x18(%rsp)
jmp 0x1537d
movb 0x17(%rsp), %al
movq 0x18(%rsp), %rcx
movq %rcx, 0x90(%rsp)
movb %al, 0x98(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x16b20
jmp 0x15205
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x368(%rsp)
movl %eax, 0x364(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x16b20
jmp 0x154ed
jmp 0x1542e
movq 0x25bda(%rip), %rdi     # 0x3afb0
leaq 0x1367a(%rip), %rsi     # 0x28a57
callq 0x53a0
movq %rax, 0x8(%rsp)
jmp 0x153e9
movq 0x8(%rsp), %rdi
movq 0x25b8b(%rip), %rsi     # 0x3af80
callq 0x53f0
jmp 0x153fc
movb $0x0, 0x2df(%rsp)
movq 0x3a0(%rsp), %rdi
callq 0x54b0
movb 0x2df(%rsp), %al
andb $0x1, %al
movb %al, 0x3b7(%rsp)
movl $0x1, 0x12c(%rsp)
jmp 0x154a8
movq 0x3a0(%rsp), %rsi
movq 0x120(%rsp), %rdx
addq $0x4, %rdx
leaq 0x70(%rsp), %rdi
movq $-0x1, %rcx
callq 0x53d0
jmp 0x15455
movq 0x398(%rsp), %rdi
addq $0x90, %rdi
leaq 0x70(%rsp), %rsi
callq 0x5470
leaq 0x70(%rsp), %rdi
callq 0x5270
movb $0x1, 0x2df(%rsp)
movq 0x3a0(%rsp), %rdi
callq 0x54b0
movb 0x2df(%rsp), %al
andb $0x1, %al
movb %al, 0x3b7(%rsp)
movl $0x1, 0x12c(%rsp)
leaq 0x2e0(%rsp), %rdi
callq 0x5270
leaq 0x300(%rsp), %rdi
callq 0x5270
leaq 0x340(%rsp), %rdi
callq 0x5270
leaq 0x378(%rsp), %rdi
callq 0x5270
movb 0x3b7(%rsp), %al
andb $0x1, %al
addq $0x3b8, %rsp            # imm = 0x3B8
retq
leaq 0x2e0(%rsp), %rdi
callq 0x5270
leaq 0x300(%rsp), %rdi
callq 0x5270
leaq 0x340(%rsp), %rdi
callq 0x5270
leaq 0x378(%rsp), %rdi
callq 0x5270
movq 0x368(%rsp), %rdi
callq 0x5660
nop