nghttpx: Fix missing extension HTTP status code in response

This commit is contained in:
Tatsuhiro Tsujikawa 2013-10-02 23:29:44 +09:00
parent c7ce6d811e
commit f355187176
10 changed files with 24 additions and 23 deletions

View File

@ -30,7 +30,7 @@ namespace nghttp2 {
namespace http2 { namespace http2 {
const char* get_status_string(int status_code) std::string get_status_string(unsigned int status_code)
{ {
switch(status_code) { switch(status_code) {
case 100: return "100 Continue"; case 100: return "100 Continue";
@ -74,7 +74,7 @@ const char* get_status_string(int status_code)
case 503: return "503 Service Unavailable"; case 503: return "503 Service Unavailable";
case 504: return "504 Gateway Timeout"; case 504: return "504 Gateway Timeout";
case 505: return "505 HTTP Version Not Supported"; case 505: return "505 HTTP Version Not Supported";
default: return ""; default: return util::utos(status_code);
} }
} }

View File

@ -38,7 +38,7 @@ namespace nghttp2 {
namespace http2 { namespace http2 {
const char* get_status_string(int status_code); std::string get_status_string(unsigned int status_code);
void capitalize(std::string& s, size_t offset); void capitalize(std::string& s, size_t offset);

View File

@ -64,7 +64,7 @@ void upstream_connect(const std::string& client_ip)
} }
namespace { namespace {
const char* status_code_color(int status_code) const char* status_code_color(unsigned int status_code)
{ {
if(status_code <= 199) { if(status_code <= 199) {
return "\033[1;36m"; return "\033[1;36m";
@ -82,13 +82,13 @@ const char* status_code_color(int status_code)
} }
} // namespace } // namespace
void upstream_response(const std::string& client_ip, int status_code, void upstream_response(const std::string& client_ip, unsigned int status_code,
Downstream *downstream) Downstream *downstream)
{ {
char datestr[64]; char datestr[64];
get_datestr(datestr); get_datestr(datestr);
if(downstream) { if(downstream) {
fprintf(stderr, "%s%s [%s] %d%s %d \"%s %s HTTP/%u.%u\"\n", fprintf(stderr, "%s%s [%s] %u%s %d \"%s %s HTTP/%u.%u\"\n",
get_config()->tty ? status_code_color(status_code) : "", get_config()->tty ? status_code_color(status_code) : "",
client_ip.c_str(), datestr, client_ip.c_str(), datestr,
status_code, status_code,
@ -100,7 +100,7 @@ void upstream_response(const std::string& client_ip, int status_code,
downstream->get_request_minor()); downstream->get_request_minor());
fflush(stderr); fflush(stderr);
if(get_config()->use_syslog) { if(get_config()->use_syslog) {
syslog(LOG_INFO, "%s %d %d \"%s %s HTTP/%u.%u\"\n", syslog(LOG_INFO, "%s %u %d \"%s %s HTTP/%u.%u\"\n",
client_ip.c_str(), client_ip.c_str(),
status_code, status_code,
downstream->get_stream_id(), downstream->get_stream_id(),
@ -110,13 +110,13 @@ void upstream_response(const std::string& client_ip, int status_code,
downstream->get_request_minor()); downstream->get_request_minor());
} }
} else { } else {
fprintf(stderr, "%s%s [%s] %d%s 0 \"-\"\n", fprintf(stderr, "%s%s [%s] %u%s 0 \"-\"\n",
get_config()->tty ? status_code_color(status_code) : "", get_config()->tty ? status_code_color(status_code) : "",
client_ip.c_str(), datestr, client_ip.c_str(), datestr,
status_code, status_code,
get_config()->tty ? "\033[0m" : ""); get_config()->tty ? "\033[0m" : "");
if(get_config()->use_syslog) { if(get_config()->use_syslog) {
syslog(LOG_INFO, "%s %d 0 \"-\"\n", client_ip.c_str(), status_code); syslog(LOG_INFO, "%s %u 0 \"-\"\n", client_ip.c_str(), status_code);
} }
fflush(stderr); fflush(stderr);
} }

View File

@ -34,7 +34,7 @@ namespace shrpx {
class Downstream; class Downstream;
void upstream_connect(const std::string& client_ip); void upstream_connect(const std::string& client_ip);
void upstream_response(const std::string& client_ip, int status_code, void upstream_response(const std::string& client_ip, unsigned int status_code,
Downstream *downstream); Downstream *downstream);
} // namespace shrpx } // namespace shrpx

View File

@ -35,11 +35,11 @@ namespace shrpx {
namespace http { namespace http {
std::string create_error_html(int status_code) std::string create_error_html(unsigned int status_code)
{ {
std::string res; std::string res;
res.reserve(512); res.reserve(512);
const char *status = http2::get_status_string(status_code); auto status = http2::get_status_string(status_code);
res += "<html><head><title>"; res += "<html><head><title>";
res += status; res += status;
res += "</title></head><body><h1>"; res += "</title></head><body><h1>";

View File

@ -33,7 +33,7 @@ namespace shrpx {
namespace http { namespace http {
std::string create_error_html(int status_code); std::string create_error_html(unsigned int status_code);
std::string create_via_header_value(int major, int minor); std::string create_via_header_value(int major, int minor);

View File

@ -544,7 +544,7 @@ void https_downstream_eventcb(bufferevent *bev, short events, void *ptr)
} }
} }
if(downstream->get_response_state() == Downstream::INITIAL) { if(downstream->get_response_state() == Downstream::INITIAL) {
int status; unsigned int status;
if(events & BEV_EVENT_TIMEOUT) { if(events & BEV_EVENT_TIMEOUT) {
status = 504; status = 504;
} else { } else {
@ -565,7 +565,7 @@ void https_downstream_eventcb(bufferevent *bev, short events, void *ptr)
} }
} // namespace } // namespace
int HttpsUpstream::error_reply(int status_code) int HttpsUpstream::error_reply(unsigned int status_code)
{ {
auto html = http::create_error_html(status_code); auto html = http::create_error_html(status_code);
std::string header; std::string header;

View File

@ -53,7 +53,7 @@ public:
void delete_downstream(); void delete_downstream();
Downstream* get_downstream() const; Downstream* get_downstream() const;
Downstream* pop_downstream(); Downstream* pop_downstream();
int error_reply(int status_code); int error_reply(unsigned int status_code);
virtual void pause_read(IOCtrlReason reason); virtual void pause_read(IOCtrlReason reason);
virtual int resume_read(IOCtrlReason reason, Downstream *downstream); virtual int resume_read(IOCtrlReason reason, Downstream *downstream);

View File

@ -636,7 +636,7 @@ void spdy_downstream_eventcb(bufferevent *bev, short events, void *ptr)
if(downstream->get_response_state() == Downstream::HEADER_COMPLETE) { if(downstream->get_response_state() == Downstream::HEADER_COMPLETE) {
upstream->rst_stream(downstream, SPDYLAY_INTERNAL_ERROR); upstream->rst_stream(downstream, SPDYLAY_INTERNAL_ERROR);
} else { } else {
int status; unsigned int status;
if(events & BEV_EVENT_TIMEOUT) { if(events & BEV_EVENT_TIMEOUT) {
status = 504; status = 504;
} else { } else {
@ -725,7 +725,7 @@ ssize_t spdy_data_read_callback(spdylay_session *session,
} }
} // namespace } // namespace
int SpdyUpstream::error_reply(Downstream *downstream, int status_code) int SpdyUpstream::error_reply(Downstream *downstream, unsigned int status_code)
{ {
int rv; int rv;
std::string html = http::create_error_html(status_code); std::string html = http::create_error_html(status_code);
@ -743,9 +743,9 @@ int SpdyUpstream::error_reply(Downstream *downstream, int status_code)
data_prd.read_callback = spdy_data_read_callback; data_prd.read_callback = spdy_data_read_callback;
std::string content_length = util::utos(html.size()); std::string content_length = util::utos(html.size());
std::string status_string = http2::get_status_string(status_code);
const char *nv[] = { const char *nv[] = {
":status", http2::get_status_string(status_code), ":status", status_string.c_str(),
":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,
@ -814,9 +814,10 @@ int SpdyUpstream::on_downstream_header_complete(Downstream *downstream)
auto nv = util::make_unique<const char*[]>(nheader * 2 + 6 + 1); auto nv = util::make_unique<const char*[]>(nheader * 2 + 6 + 1);
size_t hdidx = 0; size_t hdidx = 0;
std::string via_value; std::string via_value;
nv[hdidx++] = ":status"; std::string status_string = http2::get_status_string
nv[hdidx++] = http2::get_status_string
(downstream->get_response_http_status()); (downstream->get_response_http_status());
nv[hdidx++] = ":status";
nv[hdidx++] = status_string.c_str();
nv[hdidx++] = ":version"; nv[hdidx++] = ":version";
nv[hdidx++] = "HTTP/1.1"; nv[hdidx++] = "HTTP/1.1";
for(Headers::const_iterator i = downstream->get_response_headers().begin(); for(Headers::const_iterator i = downstream->get_response_headers().begin();

View File

@ -56,7 +56,7 @@ public:
int rst_stream(Downstream *downstream, int status_code); int rst_stream(Downstream *downstream, int status_code);
int window_update(Downstream *downstream); int window_update(Downstream *downstream);
int error_reply(Downstream *downstream, int status_code); int error_reply(Downstream *downstream, unsigned int status_code);
virtual void pause_read(IOCtrlReason reason); virtual void pause_read(IOCtrlReason reason);
virtual int resume_read(IOCtrlReason reason, Downstream *downstream); virtual int resume_read(IOCtrlReason reason, Downstream *downstream);