// File: alfanick[P]rest-cpp/src/rest/request.cpp
// Function: REST::Request::parse_header(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void Request::parse_header(std::string const &line) {
  if (line.find("GET") == 0) {
    method = Method::GET;
  } else
  if (line.find("POST") == 0) {
    method = Method::POST;
  } else
  if (line.find("PUT") == 0) {
    method = Method::PUT;
  } else
  if (line.find("DELETE") == 0) {
    method = Method::DELETE;
  } else
  if (line.find("HEAD") == 0) {
    method = Method::HEAD;
  } else
  if (line.find("PATCH") == 0) {
    method = Method::PATCH;
  } else
  if (line.find("TRACE") == 0) {
    method = Method::TRACE;
  } else
  if (line.find("CONNECT") == 0) {
    method = Method::CONNECT;
  } else
  if (line.find("OPTIONS") == 0) {
    method = Method::OPTIONS;
  }

  size_t path_start = line.find_first_of(" ")+1;
  size_t path_end = line.rfind("HTTP/1.")-1;

  path = line.substr(path_start, path_end - path_start);

  // TODO config
  if (path.size() >= 2048)
    throw HTTP::URITooLong();

  size_t path_query = path.find("?");

  if (path_query != std::string::npos) {
    std::string query = path.substr(path_query+1, path.size() - path_query);

    parse_query_string(query);

    path.erase(path_query, query.size()+1);
  }
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0xa8(%rsp), %rdi
leaq 0x49895(%rip), %rsi     # 0xe42c8
xorl %eax, %eax
movl %eax, %edx
callq 0x995d0
cmpq $0x0, %rax
jne 0x9aa52
movq 0x38(%rsp), %rax
movl $0x0, (%rax)
jmp 0x9abc7
movq 0xa8(%rsp), %rdi
leaq 0x4986b(%rip), %rsi     # 0xe42cc
xorl %eax, %eax
movl %eax, %edx
callq 0x995d0
cmpq $0x0, %rax
jne 0x9aa80
movq 0x38(%rsp), %rax
movl $0x2, (%rax)
jmp 0x9abc5
movq 0xa8(%rsp), %rdi
leaq 0x49842(%rip), %rsi     # 0xe42d1
xorl %eax, %eax
movl %eax, %edx
callq 0x995d0
cmpq $0x0, %rax
jne 0x9aaae
movq 0x38(%rsp), %rax
movl $0x3, (%rax)
jmp 0x9abc3
movq 0xa8(%rsp), %rdi
leaq 0x49818(%rip), %rsi     # 0xe42d5
xorl %eax, %eax
movl %eax, %edx
callq 0x995d0
cmpq $0x0, %rax
jne 0x9aadc
movq 0x38(%rsp), %rax
movl $0x4, (%rax)
jmp 0x9abc1
movq 0xa8(%rsp), %rdi
leaq 0x497f1(%rip), %rsi     # 0xe42dc
xorl %eax, %eax
movl %eax, %edx
callq 0x995d0
cmpq $0x0, %rax
jne 0x9ab0a
movq 0x38(%rsp), %rax
movl $0x1, (%rax)
jmp 0x9abbf
movq 0xa8(%rsp), %rdi
leaq 0x497c8(%rip), %rsi     # 0xe42e1
xorl %eax, %eax
movl %eax, %edx
callq 0x995d0
cmpq $0x0, %rax
jne 0x9ab38
movq 0x38(%rsp), %rax
movl $0x8, (%rax)
jmp 0x9abbd
movq 0xa8(%rsp), %rdi
leaq 0x497a0(%rip), %rsi     # 0xe42e7
xorl %eax, %eax
movl %eax, %edx
callq 0x995d0
cmpq $0x0, %rax
jne 0x9ab63
movq 0x38(%rsp), %rax
movl $0x5, (%rax)
jmp 0x9abbb
movq 0xa8(%rsp), %rdi
leaq 0x4977b(%rip), %rsi     # 0xe42ed
xorl %eax, %eax
movl %eax, %edx
callq 0x995d0
cmpq $0x0, %rax
jne 0x9ab8e
movq 0x38(%rsp), %rax
movl $0x6, (%rax)
jmp 0x9abb9
movq 0xa8(%rsp), %rdi
leaq 0x49758(%rip), %rsi     # 0xe42f5
xorl %eax, %eax
movl %eax, %edx
callq 0x995d0
cmpq $0x0, %rax
jne 0x9abb7
movq 0x38(%rsp), %rax
movl $0x7, (%rax)
jmp 0x9abb9
jmp 0x9abbb
jmp 0x9abbd
jmp 0x9abbf
jmp 0x9abc1
jmp 0x9abc3
jmp 0x9abc5
jmp 0x9abc7
movq 0xa8(%rsp), %rdi
leaq 0x4a56e(%rip), %rsi     # 0xe5144
xorl %eax, %eax
movl %eax, %edx
callq 0x8fb50
addq $0x1, %rax
movq %rax, 0xa0(%rsp)
movq 0xa8(%rsp), %rdi
leaq 0x49703(%rip), %rsi     # 0xe42fd
movq $-0x1, %rdx
callq 0x97a30
subq $0x1, %rax
movq %rax, 0x98(%rsp)
movq 0xa8(%rsp), %rsi
movq 0xa0(%rsp), %rdx
movq 0x98(%rsp), %rcx
subq 0xa0(%rsp), %rcx
leaq 0x78(%rsp), %rdi
callq 0x93510
movq 0x38(%rsp), %rdi
addq $0x8, %rdi
leaq 0x78(%rsp), %rsi
callq 0x94870
leaq 0x78(%rsp), %rdi
callq 0x99830
movq 0x38(%rsp), %rdi
addq $0x8, %rdi
callq 0x91060
cmpq $0x800, %rax            # imm = 0x800
jb 0x9acaf
movl $0x8, %edi
callq 0x8f970
movq %rax, %rdi
movq %rdi, 0x30(%rsp)
xorl %esi, %esi
movl $0x8, %edx
callq 0x8ffc0
movq 0x30(%rsp), %rdi
callq 0x93040
movq 0x30(%rsp), %rdi
movq 0x6b175(%rip), %rsi     # 0x105e18
movq 0x6b1fe(%rip), %rdx     # 0x105ea8
callq 0x97c60
movq 0x38(%rsp), %rdi
addq $0x8, %rdi
leaq 0x49646(%rip), %rsi     # 0xe4305
xorl %eax, %eax
movl %eax, %edx
callq 0x995d0
movq %rax, 0x70(%rsp)
cmpq $-0x1, 0x70(%rsp)
je 0x9ad8d
movq 0x38(%rsp), %rdi
addq $0x8, %rdi
movq %rdi, 0x18(%rsp)
movq 0x70(%rsp), %rax
incq %rax
movq %rax, 0x20(%rsp)
callq 0x91060
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %rax, %rcx
movq 0x70(%rsp), %rax
subq %rax, %rcx
leaq 0x50(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x93510
movq 0x38(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x959a0
jmp 0x9ad2e
movq 0x38(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x8(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x91060
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %rax, %rdx
incq %rdx
callq 0x8e070
jmp 0x9ad67
leaq 0x50(%rsp), %rdi
callq 0x99830
jmp 0x9ad8d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x99830
jmp 0x9ad95
addq $0xb8, %rsp
retq
movq 0x48(%rsp), %rdi
callq 0x981c0
nop