shrpx: HttpsUpstream::error_reply() without std::stringstream

This commit is contained in:
Tatsuhiro Tsujikawa 2013-01-16 22:51:33 +09:00
parent c48fb56d3f
commit 87c1f07013
1 changed files with 11 additions and 8 deletions

View File

@ -526,16 +526,19 @@ void https_downstream_eventcb(bufferevent *bev, short events, void *ptr)
int HttpsUpstream::error_reply(int status_code) int HttpsUpstream::error_reply(int status_code)
{ {
std::string html = http::create_error_html(status_code); std::string html = http::create_error_html(status_code);
std::stringstream ss; std::string header;
ss << "HTTP/1.1 " << http::get_status_string(status_code) << "\r\n" header.reserve(512);
<< "Server: " << get_config()->server_name << "\r\n" header += "HTTP/1.1 ";
<< "Content-Length: " << html.size() << "\r\n" header += http::get_status_string(status_code);
<< "Content-Type: " << "text/html; charset=UTF-8\r\n"; header += "\r\nServer: ";
header += get_config()->server_name;
header += "\r\nContent-Length: ";
header += util::utos(html.size());
header += "\r\nContent-Type: text/html; charset=UTF-8\r\n";
if(get_client_handler()->get_should_close_after_write()) { if(get_client_handler()->get_should_close_after_write()) {
ss << "Connection: close\r\n"; header += "Connection: close\r\n";
} }
ss << "\r\n"; header += "\r\n";
std::string header = ss.str();
evbuffer *output = bufferevent_get_output(handler_->get_bev()); evbuffer *output = bufferevent_get_output(handler_->get_bev());
if(evbuffer_add(output, header.c_str(), header.size()) != 0 || if(evbuffer_add(output, header.c_str(), header.size()) != 0 ||
evbuffer_add(output, html.c_str(), html.size()) != 0) { evbuffer_add(output, html.c_str(), html.size()) != 0) {