// File: /workspace/github_cpp_makefile_star2_O2/lega911[P]ijson/src/connect.cpp
// Function: Connect::header_completed()
void Connect::header_completed() {
    this->loop->stat_request++;
    this->keep_alive = http_version == 11;

    if(server->log & 32) {
        Buffer repr(250);
        if(start_time) {
            i64 dur = (get_time() - start_time) / 1000;
            if(dur >= 10000) {
                repr.add_number(dur / 1000);
                repr.add("sec ");
            } else {
                repr.add_number(dur);
                repr.add("ms ");
            }
            start_time = 0;
        }
        if(this->body.size() > 150) {
            repr.add(this->body.ptr(), 147);
            repr.add("...");
        } else if(this->body.size()) {
            repr.add(this->body);
        }
        for(int i=0;i<repr.size();i++) {
            if(repr.ptr()[i] < 32) repr.ptr()[i] = '.';
        }
        repr.add("\n", 2);
        std::cout << ltime() << this->path.as_string() << " " << this->body.size() << "b " << repr.ptr();
    }
    
    if(this->path == "echo") {
        Slice response("ok");
        this->send.status("200 OK")->done(response);
        return;
    }


    #ifdef DEBUG
    if(this->path == "rpc/migrate") {
        this->send.status("200 OK")->done();
        this->need_loop = this->nloop + 1;
        if(this->need_loop >= server->threads) this->need_loop = 0;
        this->go_loop = true;
        return;
    }

    if(this->path == "debug") {
        Buffer r(32);
        r.add("Memory allocated: ");
        r.add_number(get_memory_allocated());
        r.add("\n");
        this->send.status("200 OK")->done(r);
        return;
    }
    #endif

    if(worker_mode) {
        if(status != Status::worker_mode_async) loop->worker_result_noid(this);
        if(header_option == "stop") {
            if(worker_item) worker_item->pop();
            worker_mode = false;
            this->send.status("200 OK")->done(1);
            status = Status::net;
            return;
        }
        //if(go_loop)  // TODO move worker
        rpc_add();
        return;
    }

    if(noid) {
        if(this->path != "rpc/result" && type != RequestType::result) {
            this->send.status("400 Result expected")->done(-1);
            return;
        };
        int r = loop->worker_result_noid(this);
        if(r == 0) {
            this->send.status("200 OK")->done(1);
        } else if(r == -2) {
            if(server->log & 4) std::cout << ltime() << "499 Client is gone\n";
            this->send.status("499 Closed")->done(-1);
        }
        status = Status::net;
        return;
    }

    Slice method;
    Slice id(this->id);
    json.load(this->body);

    if(type != RequestType::none) {
        name.set(path);
        switch(type) {
        case RequestType::async:
            no_response = true;
            loop->client_request(name, this);
            break;
        case RequestType::get_plus:
            this->noid = true;
            this->fail_on_disconnect = true;
        case RequestType::get:
            rpc_add();
            break;
        case RequestType::worker:
            worker_mode = true;
            rpc_add();
            break;
        case RequestType::pub:
            pub(name);
            break;
        case RequestType::result:
            if(id.empty() && path != "/") id.set(path);
            rpc_result(id);
            break;
        case RequestType::create:
            create_queue(path);
            break;
        case RequestType::del:
            delete_queue(path);
            break;
        default:
            this->send.status("400 Wrong type")->done(-32602);
        }
        return;
    }

    if(this->path == "rpc/call") {
        Slice params;
        while(json.scan()) {
            if(json.key == "method") method = json.value;
            else if(json.key == "id" && id.empty()) {
                id = json.value;
                this->id.set(id);
            } else if(json.key == "params") params = json.value;
        }
        if(!params.empty()) json.load(params, 1);

        if(!method.empty() && method.ptr()[0] == '/') method.remove(1);
        if(method.empty()) {
            this->send.status("400 No method")->done(-32601);
            return;
        }
    } else {
        method = this->path;
    };

    if(method == "rpc/worker") {
        worker_mode = true;
        rpc_add();
        return;
    } else if(method == "rpc/add") {
        rpc_add();
        return;
    } else if(method == "rpc/result") {
        rpc_result(id);
        return;
    } else if(method == "rpc/details") {
        send_details();
        return;
    } else if(method == "/" || method == "rpc/help") {
        send_help();
        return;
    }

    no_response = header_option == "async";
    loop->client_request(method, this);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movq 0x30(%rdi), %rax
incq 0x78(%rax)
cmpl $0xb, 0x80(%rdi)
sete 0x10(%rdi)
movq 0x48(%rdi), %rax
testb $0x20, 0x20(%rax)
je 0xb2ca
leaq -0x38(%rbp), %rdi
movl $0xfa, %esi
callq 0xd53a
cmpq $0x0, 0x1e0(%rbx)
je 0xb1d5
callq 0x16a40
subq 0x1e0(%rbx), %rax
cmpq $0x989680, %rax         # imm = 0x989680
jb 0xb1a8
movl $0xf4240, %ecx          # imm = 0xF4240
xorl %edx, %edx
divq %rcx
leaq -0x38(%rbp), %rdi
movq %rax, %rsi
callq 0xd54a
leaq 0xd07b(%rip), %rsi      # 0x18221
jmp 0xb1c4
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
leaq -0x38(%rbp), %rdi
movq %rax, %rsi
callq 0xd54a
leaq 0xd062(%rip), %rsi      # 0x18226
leaq -0x38(%rbp), %rdi
callq 0xd5ee
andq $0x0, 0x1e0(%rbx)
leaq 0xd0(%rbx), %rsi
movl 0xd8(%rbx), %eax
cmpl $0x97, %eax
jl 0xb20c
movq (%rsi), %rsi
leaq -0x38(%rbp), %rdi
movl $0x93, %edx
callq 0xd24c
leaq 0xd029(%rip), %rsi      # 0x1822a
leaq -0x38(%rbp), %rdi
callq 0xd5ee
jmp 0xb219
testl %eax, %eax
je 0xb219
leaq -0x38(%rbp), %rdi
callq 0xd300
xorl %eax, %eax
movslq -0x30(%rbp), %rcx
cmpq %rcx, %rax
jge 0xb237
movq -0x38(%rbp), %rcx
cmpb $0x1f, (%rcx,%rax)
jg 0xb232
movb $0x2e, (%rcx,%rax)
incq %rax
jmp 0xb21b
leaq 0xd464(%rip), %rsi      # 0x186a2
leaq -0x38(%rbp), %rdi
pushq $0x2
popq %rdx
callq 0xd24c
callq 0x16a89
movq 0x14d7a(%rip), %rdi     # 0x1ffd0
movq %rax, %rsi
callq 0xa2e0
movq %rax, %r14
leaq 0x98(%rbx), %rsi
leaq -0x58(%rbp), %rdi
pushq $-0x1
popq %rdx
callq 0xd636
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0xa280
leaq 0xd425(%rip), %rsi      # 0x186ac
movq %rax, %rdi
callq 0xa2e0
movl 0xd8(%rbx), %esi
movq %rax, %rdi
callq 0xa460
leaq 0xcf8a(%rip), %rsi      # 0x1822e
movq %rax, %rdi
callq 0xa2e0
movq -0x38(%rbp), %rsi
movq %rax, %rdi
callq 0xa2e0
leaq -0x58(%rbp), %rdi
callq 0xa130
leaq -0x38(%rbp), %rdi
callq 0xd6dc
leaq 0x98(%rbx), %r14
leaq 0xcf59(%rip), %rsi      # 0x18231
movq %r14, %rdi
callq 0xd9a0
testb %al, %al
je 0xb31d
leaq 0xcf4b(%rip), %rax      # 0x18236
leaq -0x58(%rbp), %r14
movq %rax, (%r14)
movl $0x2, 0x8(%r14)
addq $0x18, %rbx
leaq 0xcf34(%rip), %rsi      # 0x18239
movq %rbx, %rdi
callq 0xb93e
movq %rbx, %rdi
movq %r14, %rsi
callq 0xbe84
jmp 0xb7ad
leaq 0xcf1c(%rip), %rsi      # 0x18240
movq %r14, %rdi
callq 0xd9a0
testb %al, %al
je 0xb368
leaq 0x18(%rbx), %r14
leaq 0xcefe(%rip), %rsi      # 0x18239
movq %r14, %rdi
callq 0xb93e
movq %r14, %rdi
callq 0xbf60
movl 0x38(%rbx), %eax
incl %eax
movq 0x48(%rbx), %rcx
xorl %edx, %edx
cmpl 0x28(%rcx), %eax
cmovll %eax, %edx
movl %edx, 0x3c(%rbx)
movb $0x1, 0x40(%rbx)
jmp 0xb7ad
leaq 0xcedd(%rip), %rsi      # 0x1824c
movq %r14, %rdi
callq 0xd9a0
testb %al, %al
je 0xb3e7
leaq -0x58(%rbp), %r14
pushq $0x20
popq %rsi
movq %r14, %rdi
callq 0xd53a
leaq 0xcec1(%rip), %rsi      # 0x18252
movq %r14, %rdi
callq 0xd5ee
callq 0xfb08
movslq %eax, %rsi
leaq -0x58(%rbp), %rdi
callq 0xd54a
leaq 0xd2f1(%rip), %rsi      # 0x186a2
leaq -0x58(%rbp), %rdi
callq 0xd5ee
addq $0x18, %rbx
leaq 0xce74(%rip), %rsi      # 0x18239
movq %rbx, %rdi
callq 0xb93e
leaq -0x58(%rbp), %rsi
movq %rbx, %rdi
callq 0xbe84
leaq -0x58(%rbp), %rdi
callq 0xd6dc
jmp 0xb7ad
cmpb $0x1, 0xf3(%rbx)
jne 0xb456
cmpl $0x6, 0xcc(%rbx)
je 0xb405
movq 0x30(%rbx), %rdi
movq %rbx, %rsi
callq 0x12edc
leaq 0xa8(%rbx), %rdi
leaq 0xce52(%rip), %rsi      # 0x18265
callq 0xd9a0
testb %al, %al
je 0xb7a5
movq 0x178(%rbx), %rdi
testq %rdi, %rdi
je 0xb431
callq 0x1700a
movb $0x0, 0xf3(%rbx)
leaq 0x18(%rbx), %r14
leaq 0xcdf6(%rip), %rsi      # 0x18239
movq %r14, %rdi
callq 0xb93e
pushq $0x1
popq %rsi
movq %r14, %rdi
jmp 0xb77f
cmpb $0x1, 0xf1(%rbx)
jne 0xb4a6
leaq 0xce04(%rip), %rsi      # 0x1826a
movq %r14, %rdi
callq 0xd706
testb %al, %al
je 0xb55b
cmpl $0x6, 0xc8(%rbx)
je 0xb55b
addq $0x18, %rbx
leaq 0xcde7(%rip), %rsi      # 0x18275
movq %rbx, %rdi
callq 0xb93e
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xb9b2
jmp 0xb7ad
andq $0x0, -0x58(%rbp)
andl $0x0, -0x50(%rbp)
movq 0xe0(%rbx), %rax
movl 0xe8(%rbx), %r12d
movq %rax, -0x38(%rbp)
movl %r12d, -0x30(%rbp)
movq 0xd0(%rbx), %rax
movl 0xd8(%rbx), %ecx
andq $0x0, 0x128(%rbx)
andl $0x0, 0x130(%rbx)
andq $0x0, 0x138(%rbx)
andl $0x0, 0x140(%rbx)
andl $0x0, 0x160(%rbx)
movq %rax, 0x150(%rbx)
movl %ecx, 0x158(%rbx)
andq $0x0, 0x148(%rbx)
xorl %eax, %eax
cmpl %eax, 0xc8(%rbx)
je 0xb5b9
leaq 0xb8(%rbx), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xd3d0
movl 0xc8(%rbx), %eax
decl %eax
cmpl $0x7, %eax
ja 0xb84a
leaq 0xcadc(%rip), %rcx      # 0x18020
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movw $0x101, 0xf0(%rbx)      # imm = 0x101
jmp 0xb7a5
movq 0x30(%rbx), %rdi
movq %rbx, %rsi
callq 0x12edc
testl %eax, %eax
je 0xb75f
cmpl $-0x2, %eax
jne 0xb784
pushq $-0x1
popq %r14
movq 0x48(%rbx), %rax
leaq 0xcd16(%rip), %r15      # 0x1829d
testb $0x4, 0x20(%rax)
je 0xb76a
callq 0x16a89
movq 0x14a33(%rip), %rdi     # 0x1ffd0
movq %rax, %rsi
callq 0xa2e0
leaq 0xccdd(%rip), %rsi      # 0x18289
movq %rax, %rdi
callq 0xa2e0
jmp 0xb76a
leaq 0xccf9(%rip), %rsi      # 0x182b9
movq %r14, %rdi
callq 0xd9a0
testb %al, %al
je 0xb693
leaq 0xe0(%rbx), %rax
movq %rax, -0x70(%rbp)
leaq 0x128(%rbx), %r15
leaq 0x138(%rbx), %r14
movq $0x0, -0x68(%rbp)
leaq 0xccd8(%rip), %r12      # 0x182d0
leaq 0xcd4d(%rip), %r13      # 0x1834c
movl $0x0, -0x5c(%rbp)
movq %r15, %rdi
callq 0xe798
testb %al, %al
je 0xb6ac
movq %r15, %rdi
movq %r12, %rsi
callq 0xd9a0
testb %al, %al
je 0xb635
movl 0x8(%r14), %eax
movl %eax, -0x50(%rbp)
movq (%r14), %rax
movq %rax, -0x58(%rbp)
jmp 0xb606
movq %r15, %rdi
movq %r13, %rsi
callq 0xd9a0
testb %al, %al
je 0xb667
cmpl $0x0, -0x30(%rbp)
jne 0xb667
movl 0x8(%r14), %eax
movl %eax, -0x30(%rbp)
movq (%r14), %rax
movq %rax, -0x38(%rbp)
movq -0x70(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xd3d0
jmp 0xb606
movq %r15, %rdi
leaq 0xcc51(%rip), %rsi      # 0x182c2
callq 0xd9a0
testb %al, %al
je 0xb606
movq 0x138(%rbx), %rax
movq %rax, -0x68(%rbp)
movl 0x140(%rbx), %eax
movl %eax, -0x5c(%rbp)
jmp 0xb606
movq 0x98(%rbx), %rax
movl 0xa0(%rbx), %ecx
movq %rax, -0x58(%rbp)
movl %ecx, -0x50(%rbp)
jmp 0xb742
movl -0x5c(%rbp), %ecx
testl %ecx, %ecx
je 0xb6f4
andq $0x0, 0x128(%rbx)
andl $0x0, 0x130(%rbx)
andq $0x0, 0x138(%rbx)
andl $0x0, 0x140(%rbx)
andl $0x0, 0x160(%rbx)
movq -0x68(%rbp), %rax
movq %rax, 0x150(%rbx)
movl %ecx, 0x158(%rbx)
movq $0x1, 0x148(%rbx)
movl -0x50(%rbp), %eax
testl %eax, %eax
je 0xb722
movq -0x58(%rbp), %rcx
cmpb $0x2f, (%rcx)
jne 0xb742
testl %eax, %eax
pushq $0x1
popq %rdx
cmovlel %eax, %edx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, -0x58(%rbp)
movl %eax, %ecx
subl %edx, %ecx
movl %ecx, -0x50(%rbp)
cmpl $0x1, %eax
jg 0xb742
addq $0x18, %rbx
leaq 0xcb9c(%rip), %rsi      # 0x182c9
movq %rbx, %rdi
callq 0xb93e
movq %rbx, %rdi
movl $0xffff80a7, %esi       # imm = 0xFFFF80A7
jmp 0xb49c
leaq 0xcb8e(%rip), %rsi      # 0x182d7
leaq -0x58(%rbp), %rdi
callq 0xd9a0
testb %al, %al
je 0xb78d
movb $0x1, 0xf3(%rbx)
jmp 0xb7a5
pushq $0x1
popq %r14
leaq 0xcacf(%rip), %r15      # 0x18239
leaq 0x18(%rbx), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0xb93e
movq %r12, %rdi
movl %r14d, %esi
callq 0xb9b2
andl $0x0, 0xcc(%rbx)
jmp 0xb7ad
leaq 0xcb4e(%rip), %rsi      # 0x182e2
leaq -0x58(%rbp), %rdi
callq 0xd9a0
testb %al, %al
je 0xb86a
movq %rbx, %rdi
callq 0xbfe8
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %r15, %rsi
callq 0xc1ac
jmp 0xb7ad
movb $0x1, 0xf2(%rbx)
movq 0x30(%rbx), %rdi
movq 0xb8(%rbx), %rsi
movl 0xc0(%rbx), %edx
movq %rbx, %rcx
callq 0x11514
jmp 0xb7ad
movq 0x98(%rbx), %rsi
movl 0xa0(%rbx), %edx
movq %rbx, %rdi
callq 0xc5fc
jmp 0xb7ad
testl %r12d, %r12d
jne 0xb87e
leaq 0xca9a(%rip), %rsi      # 0x182a8
movq %r14, %rdi
callq 0xd706
testb %al, %al
je 0xb87e
movq 0x98(%rbx), %rax
movl 0xa0(%rbx), %ecx
movq %rax, -0x38(%rbp)
movl %ecx, -0x30(%rbp)
jmp 0xb87e
movq 0x98(%rbx), %rsi
movl 0xa0(%rbx), %edx
movq %rbx, %rdi
callq 0xc598
jmp 0xb7ad
addq $0x18, %rbx
leaq 0xca55(%rip), %rsi      # 0x182aa
movq %rbx, %rdi
callq 0xb93e
movq %rbx, %rdi
movl $0xffff80a6, %esi       # imm = 0xFFFF80A6
jmp 0xb49c
leaq 0xc9f9(%rip), %rsi      # 0x1826a
leaq -0x58(%rbp), %rdi
callq 0xd9a0
testb %al, %al
je 0xb88f
leaq -0x38(%rbp), %rsi
movq %rbx, %rdi
callq 0xc464
jmp 0xb7ad
leaq 0xca54(%rip), %rsi      # 0x182ea
leaq -0x58(%rbp), %rdi
callq 0xd9a0
testb %al, %al
je 0xb8b0
movq %rbx, %rdi
callq 0xc65c
jmp 0xb7ad
leaq 0xc9f1(%rip), %rsi      # 0x182a8
leaq -0x58(%rbp), %rdi
callq 0xd9a0
testb %al, %al
jne 0xb8d8
leaq 0xca2b(%rip), %rsi      # 0x182f6
leaq -0x58(%rbp), %rdi
callq 0xd9a0
testb %al, %al
je 0xb8e5
movq %rbx, %rdi
callq 0xcb14
jmp 0xb7ad
leaq 0xa8(%rbx), %rdi
leaq 0xc8c2(%rip), %rsi      # 0x181b5
callq 0xd9a0
movb %al, 0xf2(%rbx)
movq 0x30(%rbx), %rdi
movq -0x58(%rbp), %rsi
movl -0x50(%rbp), %edx
jmp 0xb7e1
jmp 0xb91b
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
jmp 0xb930
jmp 0xb91b
movq %rax, %rbx
jmp 0xb92c
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0xa130
leaq -0x38(%rbp), %rdi
callq 0xd6dc
movq %rbx, %rdi
callq 0xa470
nop