// File: /workspace/github_cpp_makefile_star2_O2/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 0x1879e(%rip), %rsi     # 0x21522
leaq -0x70(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
callq 0x9dd6
movq 0x8(%rbx), %rsi
leaq -0x90(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x9dd6
leaq 0x1877d(%rip), %rsi     # 0x2152c
leaq -0x50(%rbp), %rdi
leaq -0x2a(%rbp), %rdx
callq 0x9dd6
callq 0x1f9a3
leaq -0x1d0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x90(%rbp), %rdx
leaq -0x50(%rbp), %rcx
movq %rax, %r8
callq 0x9e12
leaq -0x50(%rbp), %rdi
callq 0x8280
leaq -0x90(%rbp), %rdi
callq 0x8280
leaq -0x70(%rbp), %rdi
callq 0x8280
leaq 0x18750(%rip), %rsi     # 0x21554
leaq -0x90(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x9dd6
leaq -0xb0(%rbp), %rbx
movq %rbx, %rdi
callq 0x1e9dc
movq (%rbx), %r12
movq 0x8(%rbx), %rbx
leaq -0x90(%rbp), %r13
leaq -0x70(%rbp), %r15
cmpq %rbx, %r12
je 0x8f06
cmpq $0x0, -0x88(%rbp)
je 0x8efd
movq -0x90(%rbp), %rax
cmpb $0x2f, (%rax)
jne 0x8efd
movq %r13, %rdi
pushq $0x2a
popq %rsi
xorl %edx, %edx
callq 0x86b0
cmpq $-0x1, %rax
je 0x8eb5
leaq 0x3a8(%rip), %rax       # 0x921e
movq %rax, -0x50(%rbp)
andq $0x0, -0x48(%rbp)
leaq -0x150(%rbp), %rax
movq %rax, -0x40(%rbp)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x153c0
leaq -0x120(%rbp), %rdi
movq %r15, %rsi
callq 0x1ea4a
movq %rax, %rdi
leaq -0x50(%rbp), %rsi
callq 0x928a
jmp 0x8ef5
leaq 0x362(%rip), %rax       # 0x921e
movq %rax, -0x50(%rbp)
andq $0x0, -0x48(%rbp)
leaq -0x150(%rbp), %r14
movq %r14, -0x40(%rbp)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x153c0
movq %r14, %rdi
movq %r15, %rsi
callq 0x1ea4a
movq %rax, %rdi
leaq -0x50(%rbp), %rsi
callq 0x928a
movq %r15, %rdi
callq 0x8280
addq $0x20, %r12
jmp 0x8e35
leaq -0xb0(%rbp), %rdi
callq 0x1a7c2
leaq -0x90(%rbp), %rdi
callq 0x8280
leaq 0x18635(%rip), %rsi     # 0x2155a
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x9dd6
leaq -0x90(%rbp), %rdi
callq 0x1f716
cmpq $0x0, -0x48(%rbp)
leaq -0x150(%rbp), %rbx
je 0x9011
movq -0x50(%rbp), %rax
cmpb $0x2f, (%rax)
jne 0x9011
leaq -0x50(%rbp), %rdi
pushq $0x2a
popq %rsi
xorl %edx, %edx
callq 0x86b0
leaq 0x430(%rip), %rcx       # 0x93a2
cmpq $-0x1, %rax
je 0x8fc3
movq %rcx, -0xb0(%rbp)
andq $0x0, -0xa8(%rbp)
movq %rbx, -0xa0(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x153c0
leaq -0x70(%rbp), %rsi
leaq -0x120(%rbp), %rdi
callq 0x1ea4a
leaq -0xb0(%rbp), %rsi
movq %rax, %rdi
callq 0x93b6
jmp 0x9008
movq %rcx, -0xb0(%rbp)
andq $0x0, -0xa8(%rbp)
movq %rbx, -0xa0(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x153c0
leaq -0x70(%rbp), %rsi
movq %rbx, %rdi
callq 0x1ea4a
leaq -0xb0(%rbp), %rsi
movq %rax, %rdi
callq 0x93b6
leaq -0x70(%rbp), %rdi
callq 0x8280
leaq -0x90(%rbp), %rdi
callq 0x8280
leaq -0x50(%rbp), %rdi
callq 0x8280
leaq 0x18535(%rip), %rsi     # 0x21562
leaq -0xb0(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x9dd6
leaq -0x50(%rbp), %rdi
callq 0x1f716
cmpq $0x0, -0xa8(%rbp)
je 0x912f
movq -0xb0(%rbp), %rax
cmpb $0x2f, (%rax)
jne 0x912f
leaq -0xb0(%rbp), %rdi
pushq $0x2a
popq %rsi
xorl %edx, %edx
callq 0x86b0
cmpq $-0x1, %rax
je 0x90d2
leaq 0x44c(%rip), %rax       # 0x94ce
movq %rax, -0x70(%rbp)
andq $0x0, -0x68(%rbp)
leaq -0x1d0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq %rbx, -0x58(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x153c0
leaq -0x90(%rbp), %rsi
leaq -0x120(%rbp), %rdi
callq 0x1ea4a
leaq -0x70(%rbp), %rsi
movq %rax, %rdi
callq 0x9548
jmp 0x9123
leaq 0x3f5(%rip), %rax       # 0x94ce
movq %rax, -0x70(%rbp)
andq $0x0, -0x68(%rbp)
leaq -0x1d0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq %rbx, -0x58(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x153c0
leaq -0x90(%rbp), %rsi
movq %rbx, %rdi
callq 0x1ea4a
leaq -0x70(%rbp), %rsi
movq %rax, %rdi
callq 0x9548
leaq -0x90(%rbp), %rdi
callq 0x8280
leaq -0x50(%rbp), %rdi
callq 0x8280
leaq -0xb0(%rbp), %rdi
callq 0x8280
leaq -0x1d0(%rbp), %rdi
callq 0x9fc6
jmp 0x9150
jmp 0x9160
jmp 0x9184
movq %rax, %rbx
jmp 0x916f
movq %rax, %rbx
jmp 0x9190
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x8280
leaq -0x50(%rbp), %rdi
callq 0x8280
leaq -0xb0(%rbp), %rdi
jmp 0x9205
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x8280
leaq -0x90(%rbp), %rdi
callq 0x8280
leaq -0x50(%rbp), %rdi
jmp 0x9205
jmp 0x91a8
jmp 0x91a8
jmp 0x91a8
movq %rax, %rbx
jmp 0x920a
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x8280
jmp 0x91be
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x8280
jmp 0x91cf
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x8280
jmp 0x9216
movq %rax, %rbx
jmp 0x9216
jmp 0x91e6
movq %rax, %rbx
jmp 0x91f2
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x8280
leaq -0xb0(%rbp), %rdi
callq 0x1a7c2
leaq -0x90(%rbp), %rdi
callq 0x8280
leaq -0x1d0(%rbp), %rdi
callq 0x9ffa
movq %rbx, %rdi
callq 0x8850