// File: /workspace/github_cpp_makefile_star2_O2/tylerkaraszewski[P]Argyle/HttpResponse.cpp
// Function: HttpResponse::HttpResponse(HttpRequest const&, Logger&, Config const&)
HttpResponse::HttpResponse(const HttpRequest& request, Logger& logger, const Config& config) :
m_request(request),
m_keepAlive(true),
m_reader(NULL),
m_config(config)
{
  if (request.getHttpError())
  {
    m_reader = new ErrorReader(request.getHttpError());
    m_keepAlive = false; // If we had an error while parsing this request, we reset the whole connection.
    return;
  }

  string redirectPath;
  time_t mtime = 0;
  m_path = FilenameResolver::resolve(unescapeUri(m_request.getPath()), m_config, redirectPath, &mtime);
  if (!redirectPath.empty())
  {
    m_reader = new ErrorReader(301, "", "Location: " + redirectPath + "\r\n");
    m_path = redirectPath;
  }
  else if (m_path.empty())
  {
    m_path = m_request.getPath();
    if (isGone(m_path))
    {
      m_reader = new ErrorReader(410);
    }
    else
    {
      m_reader = new ErrorReader(404);
    }
  }
  else if (!pathLooksSafe(m_path))
  {
    m_reader = new ErrorReader(400);
  }
  else if (pathIsCgiScript(m_path))
  {
    // @TODO: Add 'CgiReader' class.
    m_reader = new ErrorReader(501, "CGI Not Yet Implemented.");
  }
  else
  {
    m_reader = new FileReader(m_path, logger);
    int code = m_reader->getHttpResponseCode();
    if (code != 200)
    {
      delete m_reader;
      m_reader = new ErrorReader(code);
    }
  }
  int code = m_reader->getHttpResponseCode();
  m_keepAlive = m_reader->lengthKnown();
  m_headerBuffer = "HTTP/1.1 " + Utils::llToString(code) + " " + ErrorReader::getErrorMessage(code) + "\r\n";
  m_headerBuffer += S_STANDARD_HEADERS;
  if (mtime != 0)
  {
    m_headerBuffer += "Last-Modified: " + Utils::getHttpDate(mtime) + "\r\n";
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %r13
movq %rdi, %r15
movq %rsi, (%rdi)
movb $0x1, 0x8(%rdi)
andq $0x0, 0x10(%rdi)
leaq 0x28(%rdi), %rax
movq %rax, 0x18(%rdi)
andq $0x0, 0x20(%rdi)
movq %rdx, %r12
xorl %eax, %eax
movb %al, 0x28(%rdi)
leaq 0x48(%rdi), %rdx
movq %rdx, 0x38(%rdi)
andq $0x0, 0x40(%rdi)
leaq 0x18(%rdi), %rbx
leaq 0x38(%rdi), %r14
movb %al, 0x48(%rdi)
movq %rcx, 0x58(%rdi)
movq %rsi, %rdi
callq 0x5ea0
testl %eax, %eax
je 0x630d
pushq $0x40
popq %rdi
callq 0x32c0
movq %rax, %r12
movq %r13, %rdi
callq 0x5ea0
movl %eax, %ebp
leaq 0x2eac(%rip), %rsi      # 0x9160
leaq 0x68(%rsp), %rdi
movq %rsp, %rdx
callq 0x438c
leaq 0x2e98(%rip), %rsi      # 0x9160
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x438c
leaq 0x68(%rsp), %rdx
leaq 0x20(%rsp), %rcx
movq %r12, %rdi
movl %ebp, %esi
callq 0x7a10
movq %r12, 0x10(%r15)
leaq 0x20(%rsp), %rdi
callq 0x35d8
leaq 0x68(%rsp), %rdi
callq 0x35d8
movb $0x0, 0x8(%r15)
jmp 0x67aa
leaq 0x78(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
andq $0x0, 0x60(%rsp)
movq (%r15), %rdi
callq 0x5e9a
movq %rsp, %rdi
movq %rax, %rsi
callq 0x6920
movq 0x58(%r15), %rdx
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0x68(%rsp), %rcx
leaq 0x60(%rsp), %r8
callq 0x6c24
leaq 0x20(%rsp), %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3380
movq %r13, %rdi
callq 0x35d8
movq %rsp, %rdi
callq 0x35d8
cmpq $0x0, 0x70(%rsp)
je 0x6413
pushq $0x40
popq %rdi
callq 0x32c0
movq %rax, %r12
leaq 0x2dd0(%rip), %rsi      # 0x9160
leaq 0x20(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x438c
leaq 0x2ef6(%rip), %rsi      # 0x929f
leaq 0x40(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x6b93
leaq 0x2e77(%rip), %rdx      # 0x9236
movq %rsp, %rdi
leaq 0x40(%rsp), %rsi
callq 0x42dc
leaq 0x20(%rsp), %rdx
movq %rsp, %rcx
movq %r12, %rdi
movl $0x12d, %esi            # imm = 0x12D
callq 0x7a10
movq %r12, 0x10(%r15)
movq %rsp, %rdi
callq 0x35d8
leaq 0x40(%rsp), %rdi
callq 0x35d8
leaq 0x20(%rsp), %rdi
callq 0x35d8
leaq 0x68(%rsp), %rsi
movq %rbx, %rdi
callq 0x31a0
jmp 0x6644
cmpq $0x0, 0x20(%r15)
je 0x648c
movq %rbx, %rdi
callq 0x6a36
testb %al, %al
je 0x6501
movq %rbx, %rdi
callq 0x6a96
testb %al, %al
je 0x65a5
pushq $0x40
popq %rdi
callq 0x32c0
movq %rax, %r12
leaq 0x2e5e(%rip), %rsi      # 0x92aa
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x438c
leaq 0x2cfe(%rip), %rsi      # 0x9160
movq %rsp, %rdi
leaq 0x88(%rsp), %rdx
callq 0x438c
leaq 0x20(%rsp), %rdx
movq %rsp, %rcx
movq %r12, %rdi
movl $0x1f5, %esi            # imm = 0x1F5
callq 0x7a10
jmp 0x662e
movq (%r15), %rdi
callq 0x5e9a
movq %rbx, %rdi
movq %rax, %rsi
callq 0x31a0
movq %rbx, %rdi
callq 0x69fa
testb %al, %al
je 0x6553
pushq $0x40
popq %rdi
callq 0x32c0
movq %rax, %r12
leaq 0x2c9f(%rip), %rsi      # 0x9160
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x438c
leaq 0x2c89(%rip), %rsi      # 0x9160
movq %rsp, %rdi
leaq 0x88(%rsp), %rdx
callq 0x438c
leaq 0x20(%rsp), %rdx
movq %rsp, %rcx
movq %r12, %rdi
movl $0x19a, %esi            # imm = 0x19A
callq 0x7a10
jmp 0x662e
pushq $0x40
popq %rdi
callq 0x32c0
movq %rax, %r12
leaq 0x2c4d(%rip), %rsi      # 0x9160
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x438c
leaq 0x2c37(%rip), %rsi      # 0x9160
movq %rsp, %rdi
leaq 0x88(%rsp), %rdx
callq 0x438c
leaq 0x20(%rsp), %rdx
movq %rsp, %rcx
movq %r12, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0x7a10
jmp 0x662e
pushq $0x40
popq %rdi
callq 0x32c0
movq %rax, %r12
leaq 0x2bfb(%rip), %rsi      # 0x9160
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x438c
leaq 0x2be5(%rip), %rsi      # 0x9160
movq %rsp, %rdi
leaq 0x88(%rsp), %rdx
callq 0x438c
leaq 0x20(%rsp), %rdx
movq %rsp, %rcx
movq %r12, %rdi
movl $0x194, %esi            # imm = 0x194
callq 0x7a10
jmp 0x662e
pushq $0x78
popq %rdi
callq 0x32c0
movq %rax, %r13
movq %rax, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x7358
movq %r13, 0x10(%r15)
movq (%r13), %rax
movq %r13, %rdi
callq *0x28(%rax)
movl %eax, %ebp
cmpl $0xc8, %eax
je 0x6644
movq 0x10(%r15), %rdi
testq %rdi, %rdi
je 0x65e4
movq (%rdi), %rax
callq *0x8(%rax)
pushq $0x40
popq %rdi
callq 0x32c0
movq %rax, %r12
leaq 0x2b6a(%rip), %rsi      # 0x9160
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x438c
leaq 0x2b54(%rip), %rsi      # 0x9160
movq %rsp, %rdi
leaq 0x88(%rsp), %rdx
callq 0x438c
leaq 0x20(%rsp), %rdx
movq %rsp, %rcx
movq %r12, %rdi
movl %ebp, %esi
callq 0x7a10
movq %r12, 0x10(%r15)
movq %rsp, %rdi
callq 0x35d8
leaq 0x20(%rsp), %rdi
callq 0x35d8
movq 0x10(%r15), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
movl %eax, %ebp
movq 0x10(%r15), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
movb %al, 0x8(%r15)
movslq %ebp, %rsi
leaq 0xc8(%rsp), %rdi
callq 0x8104
leaq 0x2c4e(%rip), %rsi      # 0x92c3
leaq 0x88(%rsp), %rdi
leaq 0xc8(%rsp), %rdx
callq 0x42fb
leaq 0x30f6(%rip), %rdx      # 0x9787
leaq 0x40(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x42dc
leaq 0xa8(%rsp), %rdi
movl %ebp, %esi
callq 0x7c1c
movq %rsp, %rdi
leaq 0x40(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
callq 0x512c
leaq 0x2b68(%rip), %rdx      # 0x9236
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x42dc
leaq 0x20(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x3380
movq %r15, %rdi
callq 0x35d8
movq %rsp, %rdi
callq 0x35d8
leaq 0xa8(%rsp), %rdi
callq 0x35d8
leaq 0x40(%rsp), %rdi
callq 0x35d8
leaq 0x88(%rsp), %rdi
callq 0x35d8
leaq 0xc8(%rsp), %rdi
callq 0x35d8
leaq 0x7c6d(%rip), %rsi      # 0xe3a0
movq %r14, %rdi
callq 0x3590
movq 0x60(%rsp), %rsi
testq %rsi, %rsi
je 0x67a0
leaq 0x40(%rsp), %rdi
callq 0x8274
leaq 0x2b77(%rip), %rsi      # 0x92cd
movq %rsp, %rdi
leaq 0x40(%rsp), %rdx
callq 0x42fb
leaq 0x2acc(%rip), %rdx      # 0x9236
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x42dc
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x3590
leaq 0x20(%rsp), %rdi
callq 0x35d8
movq %rsp, %rdi
callq 0x35d8
leaq 0x40(%rsp), %rdi
callq 0x35d8
leaq 0x68(%rsp), %rdi
callq 0x35d8
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x67ed
jmp 0x6843
jmp 0x6852
jmp 0x67ed
jmp 0x6843
movq %rax, %r15
pushq $0x78
popq %rsi
movq %r13, %rdi
jmp 0x685b
jmp 0x6852
jmp 0x67ed
jmp 0x67ed
jmp 0x6843
jmp 0x6843
jmp 0x6852
jmp 0x6852
jmp 0x68f5
movq %rax, %r15
movq %rsp, %rdi
jmp 0x683c
jmp 0x6843
jmp 0x6852
movq %rax, %r15
leaq 0x20(%rsp), %rdi
callq 0x35d8
jmp 0x680b
movq %rax, %r15
movq %rsp, %rdi
callq 0x35d8
jmp 0x6818
movq %rax, %r15
leaq 0x40(%rsp), %rdi
jmp 0x68b0
jmp 0x68f5
movq %rax, %r15
movq %rsp, %rdi
callq 0x35d8
jmp 0x6837
movq %rax, %r15
leaq 0x40(%rsp), %rdi
callq 0x35d8
jmp 0x6846
movq %rax, %r15
leaq 0x20(%rsp), %rdi
callq 0x35d8
jmp 0x6855
movq %rax, %r15
pushq $0x40
popq %rsi
movq %r12, %rdi
callq 0x32d0
jmp 0x68f8
movq %rax, %r15
movq %rsp, %rdi
callq 0x35d8
jmp 0x6875
movq %rax, %r15
leaq 0xa8(%rsp), %rdi
callq 0x35d8
jmp 0x6887
movq %rax, %r15
leaq 0x40(%rsp), %rdi
callq 0x35d8
jmp 0x6896
movq %rax, %r15
leaq 0x88(%rsp), %rdi
callq 0x35d8
jmp 0x68a8
movq %rax, %r15
leaq 0xc8(%rsp), %rdi
callq 0x35d8
jmp 0x68f8
jmp 0x68f5
movq %rax, %r15
movq %rsp, %rdi
jmp 0x68b0
movq %rax, %r15
leaq 0x20(%rsp), %rdi
callq 0x35d8
jmp 0x68d3
movq %rax, %r15
leaq 0x68(%rsp), %rdi
callq 0x35d8
jmp 0x68e4
jmp 0x68e1
movq %rax, %r15
pushq $0x40
popq %rsi
movq %r12, %rdi
callq 0x32d0
jmp 0x6902
jmp 0x68f5
jmp 0x68f5
movq %rax, %r15
leaq 0x68(%rsp), %rdi
callq 0x35d8
movq %r14, %rdi
callq 0x35d8
movq %rbx, %rdi
callq 0x35d8
movq %r15, %rdi
callq 0x3510
movq %rax, %r15
jmp 0x6902
nop