// File: /workspace/github_cpp_makefile_star2_O3/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 0x1b4bc(%rip), %rsi     # 0x24522
leaq 0x1b4be(%rip), %rdx     # 0x2452b
leaq -0x48(%rbp), %rdi
callq 0x11e6e
movq 0x8(%rbx), %rsi
leaq -0x68(%rbp), %rdi
leaq -0xa8(%rbp), %rdx
callq 0xa96a
leaq -0x78(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x1b493(%rip), %rsi     # 0x2452c
leaq 0x1b4b3(%rip), %rdx     # 0x24553
leaq -0x88(%rbp), %rdi
callq 0x11e6e
callq 0x22a1f
leaq -0x1c8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x68(%rbp), %rdx
leaq -0x88(%rbp), %rcx
movq %rax, %r8
callq 0xa9a8
movq -0x88(%rbp), %rdi
cmpq %r14, %rdi
je 0x90e7
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x8520
leaq -0x58(%rbp), %rbx
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0x9100
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x9119
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x8520
leaq -0x68(%rbp), %rdi
movq %rbx, (%rdi)
leaq 0x1b42d(%rip), %rsi     # 0x24554
leaq 0x1b42b(%rip), %rdx     # 0x24559
callq 0x11e6e
leaq -0xa8(%rbp), %rbx
movq %rbx, %rdi
callq 0x2196a
movq (%rbx), %r15
movq 0x8(%rbx), %r12
cmpq %r12, %r15
je 0x9245
leaq -0x68(%rbp), %r13
leaq -0x48(%rbp), %rbx
cmpq $0x0, -0x60(%rbp)
je 0x9238
movq -0x68(%rbp), %rax
cmpb $0x2f, (%rax)
jne 0x9238
movq %r13, %rdi
movl $0x2a, %esi
xorl %edx, %edx
callq 0x8680
cmpq $-0x1, %rax
je 0x91d6
leaq 0x50a(%rip), %rax       # 0x9698
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 0x17c65
leaq -0x118(%rbp), %rdi
movq %rbx, %rsi
callq 0x219fa
movq %rax, %rdi
leaq -0x88(%rbp), %rsi
callq 0x989c
jmp 0x921f
leaq 0x4bb(%rip), %rax       # 0x9698
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 0x17c65
movq %r14, %rdi
movq %rbx, %rsi
callq 0x219fa
movq %rax, %rdi
leaq -0x88(%rbp), %rsi
callq 0x989c
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x9238
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x8520
addq $0x20, %r15
cmpq %r12, %r15
jne 0x915a
leaq -0xa8(%rbp), %rdi
callq 0x1d4e0
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %r15
cmpq %r15, %rdi
je 0x926a
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x8520
leaq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rbx
movq %rbx, (%rdi)
leaq 0x1b2db(%rip), %rsi     # 0x2455a
leaq 0x1b2db(%rip), %rdx     # 0x24561
callq 0x11e6e
leaq -0x68(%rbp), %rdi
callq 0x22753
cmpq $0x0, -0x80(%rbp)
leaq -0x148(%rbp), %r12
je 0x938c
movq -0x88(%rbp), %rax
cmpb $0x2f, (%rax)
jne 0x938c
leaq -0x88(%rbp), %rdi
movl $0x2a, %esi
xorl %edx, %edx
callq 0x8680
cmpq $-0x1, %rax
je 0x9324
leaq 0x6e2(%rip), %rax       # 0x99b8
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 0x17c65
leaq -0x118(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x219fa
leaq -0xa8(%rbp), %rsi
movq %rax, %rdi
callq 0x99ec
jmp 0x9373
leaq 0x68d(%rip), %rax       # 0x99b8
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 0x17c65
leaq -0x48(%rbp), %rsi
movq %r12, %rdi
callq 0x219fa
leaq -0xa8(%rbp), %rsi
movq %rax, %rdi
callq 0x99ec
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x938c
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x93a1
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0x88(%rbp), %rdi
cmpq %rbx, %rdi
je 0x93b9
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x8520
leaq -0x98(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x1b197(%rip), %rsi     # 0x24562
leaq 0x1b19c(%rip), %rdx     # 0x2456e
leaq -0xa8(%rbp), %rdi
callq 0x11e6e
leaq -0x88(%rbp), %rdi
callq 0x22753
cmpq $0x0, -0xa0(%rbp)
je 0x94de
movq -0xa8(%rbp), %rax
cmpb $0x2f, (%rax)
jne 0x94de
leaq -0xa8(%rbp), %rdi
movl $0x2a, %esi
xorl %edx, %edx
callq 0x8680
cmpq $-0x1, %rax
je 0x9478
leaq 0x6e0(%rip), %rax       # 0x9b08
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 0x17c65
leaq -0x118(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x219fa
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x9c0a
jmp 0x94c9
leaq 0x689(%rip), %rax       # 0x9b08
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 0x17c65
leaq -0x68(%rbp), %rsi
movq %r12, %rdi
callq 0x219fa
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x9c0a
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x94de
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0x88(%rbp), %rdi
cmpq %rbx, %rdi
je 0x94f6
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0xa8(%rbp), %rdi
cmpq %r14, %rdi
je 0x9511
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x8520
leaq -0x1c8(%rbp), %rdi
callq 0xabfa
jmp 0x951d
jmp 0x952d
jmp 0x957d
movq %rax, %rbx
jmp 0x9545
movq %rax, %rbx
jmp 0x9599
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x9545
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x9561
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0xa8(%rbp), %rdi
cmpq %r14, %rdi
je 0x9683
movq -0x98(%rbp), %rsi
jmp 0x967b
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x9599
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x95b2
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x8520
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x9683
movq -0x78(%rbp), %rsi
jmp 0x967b
jmp 0x95d5
jmp 0x95d5
jmp 0x95d5
movq %rax, %rbx
jmp 0x9683
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r14, %rdi
je 0x95fd
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x8520
jmp 0x95fd
movq %rax, %rbx
leaq -0x58(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x961b
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x8520
jmp 0x961b
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x968f
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x8520
jmp 0x968f
movq %rax, %rbx
jmp 0x968f
jmp 0x9642
movq %rax, %rbx
jmp 0x965e
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x965e
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x8520
leaq -0xa8(%rbp), %rdi
callq 0x1d4e0
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x9683
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x8520
leaq -0x1c8(%rbp), %rdi
callq 0xac38
movq %rbx, %rdi
callq 0x8830
nop