// File: /workspace/github_cpp_makefile_star2_O1/trisolaris233[P]httpc/src/main2.cpp
// Function: main
int main(int argc, char* argv[]) {

    httpc::Server server(
        "127.0.0.1", 
        std::string(argv[1]), 
        "/home/sakakiyukiho/dev/cpp/httpc/static"
    );
    // constexpr auto GET = httpc::HttpMethodEnum::GET;
    // constexpr auto POST = httpc::HttpMethodEnum::POST;
    server.AddRouter<httpc::HttpMethodEnum::GET, httpc::HttpMethodEnum::POST>
    ("/root", [](Request& req, Response& res) {
        
        httpc::debug().dg("bussiness filesize received => ").dg(req.GetFileSize()).lf();
        if (req.GetFileSize() != 0) {
            // req.DenyNextFile(); // refuse to recv next file
            req.RecvNextFile();
        } else {
            // std::cout << "53?" << std::endl;
            res.RenderString("hello, world");
        }
        if (req.RecvComplete() && req.RecvSuccessfully()) {
            // std::cout << "go render" << std::endl;
            res.RenderString(req.GetFiles()[0].GetContent());
        }
    });
    server.AddRouter("/root/*",[](Request&, Response& res) {
        res.RenderString("hello, root");
    });
    server.AddRouter("/static_file", [&server](Request& req, Response& res) {
        res.RenderFromStaticFile(server.GetDocumentRoot() + "/index.html");
    });

    // server.AddRouter("/", [](Request&, Response& res){
    //     //std::cout << "enter bussiness" << std::endl;
    //     res.RenderString("hello world");
    //     httpc::debug().dg("root").lf();
    // });
    // server.AddRouter("/index/?", [](Request&, Response& res) {
    //     std::cout << "enter /index?" << std::endl;
    //     res.RenderString("This is the index page of router /index?");
    // });
    // server.AddRouter(
    //     std::regex("/[^/]+/[^/]+/[^/]+/{0,1}"),
    //     [](Request&, Response& res) {
    //         std::cout << "enter regex" << std::endl;
    //         res.RenderString("If you see this page that means you've entered /*/*[/] route");
    //     });
    // server.AddRouter("/index.html", [&server](Request&, Response& res) {
    //     res.RenderFromStaticFile(server.GetDocumentRoot() + "/index.html");
    // });
    // server.AddRouter("/index2.html", [&server](Request&, Response& res) {
    //     res.AsyncRenderFromStaticFile(server.GetDocumentRoot() + "/index.html");
    // });

    server.Start();

    for(;;) {}
    // testDefaultResponse();
    return 0;
    
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rsi, %rbx
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x1b46c(%rip), %rsi     # 0x24522
leaq 0x1b46e(%rip), %rdx     # 0x2452b
leaq -0x48(%rbp), %rdi
callq 0x120b6
movq 0x8(%rbx), %rsi
leaq -0x68(%rbp), %rdi
leaq -0xa8(%rbp), %rdx
callq 0xa9d6
leaq -0x78(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x1b443(%rip), %rsi     # 0x2452c
leaq 0x1b463(%rip), %rdx     # 0x24553
leaq -0x88(%rbp), %rdi
callq 0x120b6
callq 0x23113
leaq -0x1c8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x68(%rbp), %rdx
leaq -0x88(%rbp), %rcx
movq %rax, %r8
callq 0xaa14
movq -0x88(%rbp), %rdi
cmpq %r14, %rdi
je 0x9137
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x8520
leaq -0x58(%rbp), %rbx
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0x9150
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x9169
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x8520
leaq -0x68(%rbp), %rdi
movq %rbx, (%rdi)
leaq 0x1b3dd(%rip), %rsi     # 0x24554
leaq 0x1b3db(%rip), %rdx     # 0x24559
callq 0x120b6
leaq -0xa8(%rbp), %rbx
movq %rbx, %rdi
callq 0x2202e
movq (%rbx), %r15
movq 0x8(%rbx), %r12
cmpq %r12, %r15
je 0x9295
leaq -0x68(%rbp), %r13
leaq -0x48(%rbp), %rbx
cmpq $0x0, -0x60(%rbp)
je 0x9288
movq -0x68(%rbp), %rax
cmpb $0x2f, (%rax)
jne 0x9288
movq %r13, %rdi
movl $0x2a, %esi
xorl %edx, %edx
callq 0x8680
cmpq $-0x1, %rax
je 0x9226
leaq 0x50a(%rip), %rax       # 0x96e8
movq %rax, -0x88(%rbp)
movq $0x0, -0x80(%rbp)
leaq -0x148(%rbp), %rax
movq %rax, -0x78(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x180e1
leaq -0x118(%rbp), %rdi
movq %rbx, %rsi
callq 0x220be
movq %rax, %rdi
leaq -0x88(%rbp), %rsi
callq 0x98c4
jmp 0x926f
leaq 0x4bb(%rip), %rax       # 0x96e8
movq %rax, -0x88(%rbp)
movq $0x0, -0x80(%rbp)
leaq -0x148(%rbp), %r14
movq %r14, -0x78(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x180e1
movq %r14, %rdi
movq %rbx, %rsi
callq 0x220be
movq %rax, %rdi
leaq -0x88(%rbp), %rsi
callq 0x98c4
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x9288
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x8520
addq $0x20, %r15
cmpq %r12, %r15
jne 0x91aa
leaq -0xa8(%rbp), %rdi
callq 0x1d986
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %r15
cmpq %r15, %rdi
je 0x92ba
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x8520
leaq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rbx
movq %rbx, (%rdi)
leaq 0x1b28b(%rip), %rsi     # 0x2455a
leaq 0x1b28b(%rip), %rdx     # 0x24561
callq 0x120b6
leaq -0x68(%rbp), %rdi
callq 0x22e47
cmpq $0x0, -0x80(%rbp)
leaq -0x148(%rbp), %r12
je 0x93dc
movq -0x88(%rbp), %rax
cmpb $0x2f, (%rax)
jne 0x93dc
leaq -0x88(%rbp), %rdi
movl $0x2a, %esi
xorl %edx, %edx
callq 0x8680
cmpq $-0x1, %rax
je 0x9374
leaq 0x6ca(%rip), %rax       # 0x99f0
movq %rax, -0xa8(%rbp)
movq $0x0, -0xa0(%rbp)
movq %r12, -0x98(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0x180e1
leaq -0x118(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x220be
leaq -0xa8(%rbp), %rsi
movq %rax, %rdi
callq 0x9a24
jmp 0x93c3
leaq 0x675(%rip), %rax       # 0x99f0
movq %rax, -0xa8(%rbp)
movq $0x0, -0xa0(%rbp)
movq %r12, -0x98(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0x180e1
leaq -0x48(%rbp), %rsi
movq %r12, %rdi
callq 0x220be
leaq -0xa8(%rbp), %rsi
movq %rax, %rdi
callq 0x9a24
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x93dc
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x93f1
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0x88(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9409
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x8520
leaq -0x98(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x1b147(%rip), %rsi     # 0x24562
leaq 0x1b14c(%rip), %rdx     # 0x2456e
leaq -0xa8(%rbp), %rdi
callq 0x120b6
leaq -0x88(%rbp), %rdi
callq 0x22e47
cmpq $0x0, -0xa0(%rbp)
je 0x952e
movq -0xa8(%rbp), %rax
cmpb $0x2f, (%rax)
jne 0x952e
leaq -0xa8(%rbp), %rdi
movl $0x2a, %esi
xorl %edx, %edx
callq 0x8680
cmpq $-0x1, %rax
je 0x94c8
leaq 0x6d8(%rip), %rax       # 0x9b50
movq %rax, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
leaq -0x1c8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq %r12, -0x30(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
callq 0x180e1
leaq -0x118(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x220be
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x9c52
jmp 0x9519
leaq 0x681(%rip), %rax       # 0x9b50
movq %rax, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
leaq -0x1c8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq %r12, -0x30(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
callq 0x180e1
leaq -0x68(%rbp), %rsi
movq %r12, %rdi
callq 0x220be
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x9c52
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x952e
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0x88(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9546
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0xa8(%rbp), %rdi
cmpq %r14, %rdi
je 0x9561
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x8520
leaq -0x1c8(%rbp), %rdi
callq 0xac6c
jmp 0x956d
jmp 0x957d
jmp 0x95cd
movq %rax, %rbx
jmp 0x9595
movq %rax, %rbx
jmp 0x95e9
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x9595
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x95b1
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0xa8(%rbp), %rdi
cmpq %r14, %rdi
je 0x96d3
movq -0x98(%rbp), %rsi
jmp 0x96cb
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x95e9
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x9602
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x96d3
movq -0x78(%rbp), %rsi
jmp 0x96cb
jmp 0x9625
jmp 0x9625
jmp 0x9625
movq %rax, %rbx
jmp 0x96d3
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r14, %rdi
je 0x964d
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x8520
jmp 0x964d
movq %rax, %rbx
leaq -0x58(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x966b
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x8520
jmp 0x966b
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x96df
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x8520
jmp 0x96df
movq %rax, %rbx
jmp 0x96df
jmp 0x9692
movq %rax, %rbx
jmp 0x96ae
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x96ae
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x8520
leaq -0xa8(%rbp), %rdi
callq 0x1d986
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x96d3
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x8520
leaq -0x1c8(%rbp), %rdi
callq 0xacaa
movq %rbx, %rdi
callq 0x8830
nop