// File: llefranc[P]42_webserv/srcs/server/Request.cpp
// Function: Request::parseURI(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Request::parseURI(std::string token)
{
	if (token[0] != '/')
		throw StatusLine(400, REASON_400, "URI must begin with a /");
	
    // URI is case insensitive, transforming it to lowercase
    std::transform(token.begin(), token.end(), token.begin(), asciiToLower);
    
	// Case there is a query in the URI
	size_t querryChar = token.find("?");
	if (querryChar != std::string::npos)
	{
		_reqLine.setPath(token.substr(0, querryChar));
		_reqLine.setQuery(token.substr(querryChar + 1, token.size()));
	}

	// Case there is only path in the URI
	else
		_reqLine.setPath(token);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rsi, -0xc8(%rbp)
movq %rdi, %rax
movq -0xc8(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
movq %rax, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x59f0
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x18e1f
movb $0x1, -0x45(%rbp)
movl $0x48, %edi
callq 0x5290
movq %rax, -0xd8(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x58f0
movq -0xd0(%rbp), %rdx
leaq 0xaa18(%rip), %rsi      # 0x237a6
leaq -0x30(%rbp), %rdi
callq 0x63e0
jmp 0x18d99
movq -0xd8(%rbp), %rdi
leaq 0xa850(%rip), %rdx      # 0x235f7
movl $0x190, %esi            # imm = 0x190
leaq -0x30(%rbp), %rcx
callq 0x199d0
jmp 0x18db7
movq -0xd8(%rbp), %rdi
movb $0x0, -0x45(%rbp)
leaq 0x17fc7(%rip), %rsi     # 0x30d90
leaq 0xcb0(%rip), %rdx       # 0x19a80
callq 0x58a0
jmp 0x18fb6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x18dfd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x5a08
leaq -0x31(%rbp), %rdi
callq 0x55c0
testb $0x1, -0x45(%rbp)
jne 0x18e0e
jmp 0x18e1a
movq -0xd8(%rbp), %rdi
callq 0x53f0
jmp 0x18fad
movq -0xc0(%rbp), %rdi
callq 0x5480
movq -0xc0(%rbp), %rdi
movq %rax, -0x50(%rbp)
callq 0x5320
movq -0xc0(%rbp), %rdi
movq %rax, -0x58(%rbp)
callq 0x5480
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
leaq 0x7d6e(%rip), %rcx      # 0x20bd0
callq 0x19da0
movq -0xc0(%rbp), %rdi
movq %rax, -0x68(%rbp)
leaq 0xa945(%rip), %rsi      # 0x237be
xorl %eax, %eax
movl %eax, %edx
callq 0x59e0
movq %rax, -0x70(%rbp)
cmpq $-0x1, -0x70(%rbp)
je 0x18f8d
movq -0xc0(%rbp), %rsi
movq -0xb8(%rbp), %rax
addq $0x30, %rax
movq %rax, -0xe8(%rbp)
movq -0x70(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x90(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x5590
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
callq 0x198d0
jmp 0x18eda
leaq -0x90(%rbp), %rdi
callq 0x5a08
movq -0xb8(%rbp), %rax
movq -0xc0(%rbp), %rdi
addq $0x30, %rax
movq %rax, -0xf8(%rbp)
movq -0x70(%rbp), %rax
incq %rax
movq %rax, -0x100(%rbp)
callq 0x53b0
movq -0xc0(%rbp), %rsi
movq -0x100(%rbp), %rdx
movq %rax, %rcx
leaq -0xb0(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x5590
movq -0xf8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
callq 0x19ed0
jmp 0x18f4b
leaq -0xb0(%rbp), %rdi
callq 0x5a08
jmp 0x18fa4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x5a08
jmp 0x18fad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x5a08
jmp 0x18fad
movq -0xc0(%rbp), %rsi
movq -0xb8(%rbp), %rdi
addq $0x30, %rdi
callq 0x198d0
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x58e0
nopw %cs:(%rax,%rax)