Skip to content

Incorrect response codes for HTTP proxy #1987

Open
@Vort

Description

@Vort

When internal i2pd HTTP proxy fails to make connection, it returns response with error code 500.
This is wrong, more suitable code is 503.
Most likely, other errors have wrong codes too.

This is how Host is down case is processed now:

GenericProxyError(tr("Host is down"), tr("Can't create connection to requested host, it may be down. Please try again later."));

void HTTPReqHandler::GenericProxyError(const std::string& title, const std::string& description) {
std::stringstream ss;
ss << "<h1>" << tr("Proxy error") << ": " << title << "</h1>\r\n";
ss << "<p>" << description << "</p>\r\n";
std::string content = ss.str();
SendProxyError(content);
}

void HTTPReqHandler::SendProxyError(std::string& content)
{
i2p::http::HTTPRes res;
res.code = 500;
res.add_header("Content-Type", "text/html; charset=UTF-8");
res.add_header("Connection", "close");
std::stringstream ss;
ss << "<html>\r\n" << pageHead
<< "<body>" << content << "</body>\r\n"
<< "</html>\r\n";
res.body = ss.str();
m_Response = res.to_string();
boost::asio::async_write(*m_sock, boost::asio::buffer(m_Response), boost::asio::transfer_all(),
std::bind(&HTTPReqHandler::SentHTTPFailed, shared_from_this(), std::placeholders::_1));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions