// File: /workspace/github_cpp_makefile_star2_O2/llefranc[P]42_webserv/srcs/server/Response.cpp
// Function: Response::fillError(StatusLine const&)
void Response::fillError(const StatusLine& sta)
{    
    if (sta.getCode() != _staLine.getCode())
    {
	    _staLine = sta;
	}
	
	_buffer.clear();
	
	// Filling buffer with error code + some basic headers
	fillStatusLine(sta);
	fillServerHeader();
	fillDateHeader();

    // Case HTTP redirection
    if (_staLine.getCode() == 301)
	{
        fillLocationHeader(_req->getPath());
	}

	// Value of host header field in request
	const std::string* hostField = &_req->getHeaders().find("host")->second;
	const std::string hostValue(hostField->substr(0, hostField->find(':')));

	// Looking in each virtual server names if one match host header field value, if
    // not using default server
	const ServerInfo* servMatch = findVirtServ(_infoVirServs, hostValue);
    if (!servMatch)
	{
        servMatch = &_infoVirServs->front();
	}
	
	std::string pathError;
	std::string errorCodeHTML = "/" + convertNbToString(sta.getCode()) + ".html";

    // Custom error pages if set in config file
	if (!servMatch->getError().empty())
	{
        // Adding relative file access if not well filled in config file
        pathError = (servMatch->getError()[0] == '/') ? 
                "." + servMatch->getError() + errorCodeHTML: servMatch->getError() + errorCodeHTML;

		struct stat infFile;
		if (stat(pathError.c_str(), &infFile) == -1)
			pathError = DEFAULT_PATH_ERROR_PAGES + errorCodeHTML;
	}
    
	else
		pathError = DEFAULT_PATH_ERROR_PAGES + errorCodeHTML;

    // Filling buffer
	FileParser body(pathError.c_str(), true);

	fillContentlengthHeader(convertNbToString(body.getRequestFileSize()));
	_buffer += CLRF + body.getRequestFile();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x3c0, %rsp            # imm = 0x3C0
movq %rsi, %r14
movq %rdi, %rbx
movl (%rsi), %eax
cmpl 0x10(%rdi), %eax
je 0xd120
leaq 0x10(%rbx), %r15
leaq -0x3e0(%rbp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0xef12
movq %r15, %rdi
movq %r12, %rsi
callq 0xefd6
movq %r12, %rdi
callq 0xc596
andq $0x0, 0x60(%rbx)
movq 0x58(%rbx), %rax
movb $0x0, (%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xdd08
movq %rbx, %rdi
callq 0xde5a
movq %rbx, %rdi
callq 0xde70
cmpl $0x12d, 0x10(%rbx)      # imm = 0x12D
jne 0xd164
movq 0x8(%rbx), %rdi
callq 0xb3ac
movq %rbx, %rdi
movq %rax, %rsi
callq 0xea1c
movq 0x8(%rbx), %rdi
callq 0xb380
movq %rax, %r15
leaq 0x4469(%rip), %rsi      # 0x115e0
leaq -0x398(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
callq 0x4ec8
leaq -0x398(%rbp), %rsi
movq %r15, %rdi
callq 0xf010
movq %rax, %r15
addq $0x40, %r15
leaq -0x398(%rbp), %rdi
callq 0x47d8
pushq $0x3a
popq %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x4540
leaq -0xc0(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x4460
movq (%rbx), %rdi
movq %r12, %rsi
callq 0x100b9
movq %rax, %r15
testq %rax, %rax
jne 0xd1e9
movq (%rbx), %rax
movq (%rax), %r15
leaq -0x70(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movslq (%r14), %rsi
leaq -0x60(%rbp), %rdi
callq 0xfc62
leaq 0x45a3(%rip), %rsi      # 0x117af
leaq -0x398(%rbp), %rdi
leaq -0x60(%rbp), %rdx
callq 0x4f60
leaq 0x4864(%rip), %rdx      # 0x11a87
leaq -0xa0(%rbp), %rdi
leaq -0x398(%rbp), %rsi
callq 0x4f37
leaq -0x398(%rbp), %rdi
callq 0x47d8
leaq -0x60(%rbp), %rdi
callq 0x47d8
movq %r15, %rdi
callq 0x5994
cmpq $0x0, 0x8(%rax)
je 0xd2a2
movq %r15, %rdi
callq 0x5994
movq (%rax), %rax
movb (%rax), %r12b
cmpb $0x2f, %r12b
jne 0xd2c9
movq %r15, %rdi
callq 0x5994
leaq 0x453c(%rip), %rsi      # 0x117b9
leaq -0x60(%rbp), %rdi
movq %rax, %rdx
callq 0x5f8b
leaq -0x398(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0xaf33
jmp 0xd2e7
leaq 0x47e4(%rip), %rsi      # 0x11a8d
leaq -0x398(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x5f8b
leaq -0x80(%rbp), %rdi
leaq -0x398(%rbp), %r14
jmp 0xd345
movq %r15, %rdi
callq 0x5994
leaq -0x398(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
movq %rax, %rsi
callq 0xef9e
leaq -0x80(%rbp), %rdi
leaq -0x398(%rbp), %r14
movq %r14, %rsi
callq 0x44f0
movq %r14, %rdi
callq 0x47d8
cmpb $0x2f, %r12b
jne 0xd311
leaq -0x60(%rbp), %rdi
callq 0x47d8
movq -0x80(%rbp), %rdi
leaq -0x398(%rbp), %rsi
callq 0x43c0
cmpl $-0x1, %eax
jne 0xd355
leaq 0x4760(%rip), %rsi      # 0x11a8d
leaq -0x40(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x5f8b
leaq -0x80(%rbp), %rdi
leaq -0x40(%rbp), %r14
movq %r14, %rsi
callq 0x44f0
movq %r14, %rdi
callq 0x47d8
movq -0x80(%rbp), %rsi
leaq -0x398(%rbp), %rdi
pushq $0x1
popq %rdx
callq 0x65f6
leaq -0x398(%rbp), %rdi
callq 0x6b02
leaq -0x40(%rbp), %rdi
movq %rax, %rsi
callq 0xfc62
leaq -0x40(%rbp), %rsi
movq %rbx, %rdi
callq 0xe164
leaq -0x40(%rbp), %rdi
callq 0x47d8
leaq -0x398(%rbp), %rdi
callq 0x69bc
leaq 0x4888(%rip), %rsi      # 0x11c30
leaq -0x40(%rbp), %rdi
movq %rax, %rdx
callq 0x5f8b
addq $0x58, %rbx
leaq -0x40(%rbp), %rsi
movq %rbx, %rdi
callq 0x47a0
leaq -0x40(%rbp), %rdi
callq 0x47d8
leaq -0x398(%rbp), %rdi
callq 0x695c
leaq -0xa0(%rbp), %rdi
callq 0x47d8
leaq -0x80(%rbp), %rdi
callq 0x47d8
leaq -0xc0(%rbp), %rdi
callq 0x47d8
addq $0x3c0, %rsp            # imm = 0x3C0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0xd434
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x47d8
jmp 0xd47f
jmp 0xd434
jmp 0xd434
jmp 0xd434
jmp 0xd434
jmp 0xd424
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x47d8
jmp 0xd473
jmp 0xd434
movq %rax, %rbx
jmp 0xd47f
movq %rax, %rbx
leaq -0x398(%rbp), %rdi
callq 0x47d8
jmp 0xd44d
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
jmp 0xd486
movq %rax, %rbx
jmp 0xd48b
movq %rax, %rbx
jmp 0xd494
movq %rax, %rbx
leaq -0x398(%rbp), %rdi
jmp 0xd49b
movq %rax, %rbx
jmp 0xd4a0
jmp 0xd470
movq %rax, %rbx
leaq -0x398(%rbp), %rdi
callq 0x695c
leaq -0xa0(%rbp), %rdi
callq 0x47d8
leaq -0x80(%rbp), %rdi
callq 0x47d8
leaq -0xc0(%rbp), %rdi
callq 0x47d8
movq %rbx, %rdi
callq 0x46d0