mirror of
https://github.com/moparisthebest/spdylay
synced 2024-12-22 07:38:52 -05:00
shrpx: Add content-length header field to SPDY upstream error page
create_error_html() is rewritten without std::stringstream.
This commit is contained in:
parent
7342ce7145
commit
c48fb56d3f
@ -24,8 +24,6 @@
|
|||||||
*/
|
*/
|
||||||
#include "shrpx_http.h"
|
#include "shrpx_http.h"
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "shrpx_config.h"
|
#include "shrpx_config.h"
|
||||||
#include "shrpx_log.h"
|
#include "shrpx_log.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@ -86,16 +84,20 @@ const char* get_status_string(int status_code)
|
|||||||
|
|
||||||
std::string create_error_html(int status_code)
|
std::string create_error_html(int status_code)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::string res;
|
||||||
|
res.reserve(512);
|
||||||
const char *status = http::get_status_string(status_code);
|
const char *status = http::get_status_string(status_code);
|
||||||
ss << "<html><head><title>" << status << "</title></head><body>"
|
res += "<html><head><title>";
|
||||||
<< "<h1>" << status << "</h1>"
|
res += status;
|
||||||
<< "<hr>"
|
res += "</title></head><body><h1>";
|
||||||
<< "<address>" << get_config()->server_name << " at port "
|
res += status;
|
||||||
<< get_config()->port
|
res += "</h1><hr><address>";
|
||||||
<< "</address>"
|
res += get_config()->server_name;
|
||||||
<< "</body></html>\n";
|
res += " at port ";
|
||||||
return ss.str();
|
res += util::utos(get_config()->port);
|
||||||
|
res += "</address>";
|
||||||
|
res += "</body></html>";
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string create_via_header_value(int major, int minor)
|
std::string create_via_header_value(int major, int minor)
|
||||||
|
@ -680,11 +680,14 @@ int SpdyUpstream::error_reply(Downstream *downstream, int status_code)
|
|||||||
data_prd.source.ptr = downstream;
|
data_prd.source.ptr = downstream;
|
||||||
data_prd.read_callback = spdy_data_read_callback;
|
data_prd.read_callback = spdy_data_read_callback;
|
||||||
|
|
||||||
|
std::string content_length = util::utos(html.size());
|
||||||
|
|
||||||
const char *nv[] = {
|
const char *nv[] = {
|
||||||
":status", http::get_status_string(status_code),
|
":status", http::get_status_string(status_code),
|
||||||
":version", "http/1.1",
|
":version", "http/1.1",
|
||||||
"content-type", "text/html; charset=UTF-8",
|
"content-type", "text/html; charset=UTF-8",
|
||||||
"server", get_config()->server_name,
|
"server", get_config()->server_name,
|
||||||
|
"content-length", content_length.c_str(),
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
19
src/util.h
19
src/util.h
@ -298,6 +298,25 @@ char upcase(char c);
|
|||||||
|
|
||||||
char lowcase(char c);
|
char lowcase(char c);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::string utos(T n)
|
||||||
|
{
|
||||||
|
std::string res;
|
||||||
|
if(n == 0) {
|
||||||
|
res = "0";
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
T t = n;
|
||||||
|
for(; t; t /= 10, ++i);
|
||||||
|
res.resize(i);
|
||||||
|
--i;
|
||||||
|
for(; n; --i, n /= 10) {
|
||||||
|
res[i] = (n%10) + '0';
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
|
||||||
} // namespace spdylay
|
} // namespace spdylay
|
||||||
|
Loading…
Reference in New Issue
Block a user