// File: solaldunckel[P]webserv/srcs/HTTP/Response.cpp
// Function: Response::build()
void Response::build() {
  std::string &method = config_.getMethod();

  file_.set_path(config_.getRoot() + "/" + config_.getTarget());

  if (error_code_ > 1)
    status_code_ = error_code_;
  else if (!config_.methodAccepted(method)) {
    status_code_ = 405;
    headers_["Allow"] = buildMethodList();
  }
  else if (config_.getClientMaxBodySize() > 0 && config_.getBody().length() > config_.getClientMaxBodySize()) {
    status_code_ = 413;
  }
  else if (config_.getAuth() != "off" && !checkAuth())
    status_code_ = 401;
  else
    status_code_ = handleMethods();

  if (status_code_ >= 300 && !body_.length())
    status_code_ = buildErrorPage(status_code_);

  if (!redirect_)
    createResponse();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq (%rax), %rdi
callq 0x13030
movq %rax, %rcx
movq -0xb8(%rbp), %rax
movq %rcx, -0x10(%rbp)
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0xc0(%rbp)
movq (%rax), %rdi
callq 0x12eb0
movq %rax, %rsi
leaq 0x1cf63(%rip), %rdx     # 0x435a3
leaq -0x50(%rbp), %rdi
callq 0x8f70
movq -0xb8(%rbp), %rax
movq (%rax), %rdi
callq 0x12dc0
movq %rax, -0xb0(%rbp)
jmp 0x26661
movq -0xb0(%rbp), %rdx
leaq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x6a30
jmp 0x26677
movq -0xc0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0x35840
jmp 0x2668b
leaq -0x30(%rbp), %rdi
callq 0x5aa8
leaq -0x50(%rbp), %rdi
callq 0x5aa8
movq -0xb8(%rbp), %rax
cmpl $0x1, 0xa8(%rax)
jle 0x266f6
movq -0xb8(%rbp), %rax
movl 0xa8(%rax), %ecx
movl %ecx, 0xb8(%rax)
jmp 0x268cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x266e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x5aa8
leaq -0x50(%rbp), %rdi
callq 0x5aa8
jmp 0x26941
movq -0xb8(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x12cc0
testb $0x1, %al
jne 0x26800
movq -0xb8(%rbp), %rsi
movl $0x195, 0xb8(%rsi)      # imm = 0x195
leaq -0x80(%rbp), %rdi
callq 0x264d0
movq -0xb8(%rbp), %rax
addq $0x190, %rax            # imm = 0x190
movq %rax, -0xd0(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x5960
movq -0xc8(%rbp), %rdx
leaq 0x1d105(%rip), %rsi     # 0x43865
leaq -0xa0(%rbp), %rdi
callq 0x6be0
jmp 0x2676e
movq -0xd0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x20e30
movq %rax, -0xd8(%rbp)
jmp 0x2678a
movq -0xd8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x56d0
leaq -0xa0(%rbp), %rdi
callq 0x5aa8
leaq -0xa1(%rbp), %rdi
callq 0x55e0
leaq -0x80(%rbp), %rdi
callq 0x5aa8
jmp 0x268cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x267e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x5aa8
leaq -0xa1(%rbp), %rdi
callq 0x55e0
leaq -0x80(%rbp), %rdi
callq 0x5aa8
jmp 0x26941
movq -0xb8(%rbp), %rax
movq (%rax), %rdi
callq 0x12f50
cmpq $0x0, (%rax)
jbe 0x26867
movq -0xb8(%rbp), %rax
movq (%rax), %rdi
callq 0x13010
movq %rax, %rdi
callq 0x5830
movq %rax, %rcx
movq -0xb8(%rbp), %rax
movq %rcx, -0xe0(%rbp)
movq (%rax), %rdi
callq 0x12f50
movq %rax, %rcx
movq -0xe0(%rbp), %rax
cmpq (%rcx), %rax
jbe 0x26867
movq -0xb8(%rbp), %rax
movl $0x19d, 0xb8(%rax)      # imm = 0x19D
jmp 0x268cb
movq -0xb8(%rbp), %rax
movq (%rax), %rdi
callq 0x12ed0
movq %rax, %rdi
leaq 0x1d877(%rip), %rsi     # 0x440f7
callq 0x9360
testb $0x1, %al
jne 0x2688b
jmp 0x268ae
movq -0xb8(%rbp), %rdi
callq 0x25680
testb $0x1, %al
jne 0x268ae
movq -0xb8(%rbp), %rax
movl $0x191, 0xb8(%rax)      # imm = 0x191
jmp 0x268c9
movq -0xb8(%rbp), %rdi
callq 0x26950
movl %eax, %ecx
movq -0xb8(%rbp), %rax
movl %ecx, 0xb8(%rax)
jmp 0x268cb
jmp 0x268cd
jmp 0x268cf
movq -0xb8(%rbp), %rax
cmpl $0x12c, 0xb8(%rax)      # imm = 0x12C
jl 0x2691c
movq -0xb8(%rbp), %rdi
addq $0xe0, %rdi
callq 0x5830
cmpq $0x0, %rax
jne 0x2691c
movq -0xb8(%rbp), %rdi
movl 0xb8(%rdi), %esi
callq 0x25910
movl %eax, %ecx
movq -0xb8(%rbp), %rax
movl %ecx, 0xb8(%rax)
movq -0xb8(%rbp), %rax
testb $0x1, 0x100(%rax)
jne 0x26938
movq -0xb8(%rbp), %rdi
callq 0x27d30
addq $0xe0, %rsp
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x5950
nopw (%rax,%rax)