Commit f3551871 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttpx: Fix missing extension HTTP status code in response

parent c7ce6d81
......@@ -30,7 +30,7 @@ namespace nghttp2 {
namespace http2 {
const char* get_status_string(int status_code)
std::string get_status_string(unsigned int status_code)
{
switch(status_code) {
case 100: return "100 Continue";
......@@ -74,7 +74,7 @@ const char* get_status_string(int status_code)
case 503: return "503 Service Unavailable";
case 504: return "504 Gateway Timeout";
case 505: return "505 HTTP Version Not Supported";
default: return "";
default: return util::utos(status_code);
}
}
......
......@@ -38,7 +38,7 @@ namespace nghttp2 {
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);
......
......@@ -64,7 +64,7 @@ void upstream_connect(const std::string& client_ip)
}
namespace {
const char* status_code_color(int status_code)
const char* status_code_color(unsigned int status_code)
{
if(status_code <= 199) {
return "\033[1;36m";
......@@ -82,13 +82,13 @@ const char* status_code_color(int status_code)
}
} // 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)
{
char datestr[64];
get_datestr(datestr);
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) : "",
client_ip.c_str(), datestr,
status_code,
......@@ -100,7 +100,7 @@ void upstream_response(const std::string& client_ip, int status_code,
downstream->get_request_minor());
fflush(stderr);
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(),
status_code,
downstream->get_stream_id(),
......@@ -110,13 +110,13 @@ void upstream_response(const std::string& client_ip, int status_code,
downstream->get_request_minor());
}
} 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) : "",
client_ip.c_str(), datestr,
status_code,
get_config()->tty ? "\033[0m" : "");
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);
}
......
......@@ -34,7 +34,7 @@ namespace shrpx {
class Downstream;
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);
} // namespace shrpx
......
......@@ -35,11 +35,11 @@ namespace shrpx {
namespace http {
std::string create_error_html(int status_code)
std::string create_error_html(unsigned int status_code)
{
std::string res;
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 += status;
res += "</title></head><body><h1>";
......
......@@ -33,7 +33,7 @@ namespace shrpx {
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);
......
......@@ -544,7 +544,7 @@ void https_downstream_eventcb(bufferevent *bev, short events, void *ptr)
}
}
if(downstream->get_response_state() == Downstream::INITIAL) {
int status;
unsigned int status;
if(events & BEV_EVENT_TIMEOUT) {
status = 504;
} else {
......@@ -565,7 +565,7 @@ void https_downstream_eventcb(bufferevent *bev, short events, void *ptr)
}
} // namespace
int HttpsUpstream::error_reply(int status_code)
int HttpsUpstream::error_reply(unsigned int status_code)
{
auto html = http::create_error_html(status_code);
std::string header;
......
......@@ -53,7 +53,7 @@ public:
void delete_downstream();
Downstream* get_downstream() const;
Downstream* pop_downstream();
int error_reply(int status_code);
int error_reply(unsigned int status_code);
virtual void pause_read(IOCtrlReason reason);
virtual int resume_read(IOCtrlReason reason, Downstream *downstream);
......
......@@ -636,7 +636,7 @@ void spdy_downstream_eventcb(bufferevent *bev, short events, void *ptr)
if(downstream->get_response_state() == Downstream::HEADER_COMPLETE) {
upstream->rst_stream(downstream, SPDYLAY_INTERNAL_ERROR);
} else {
int status;
unsigned int status;
if(events & BEV_EVENT_TIMEOUT) {
status = 504;
} else {
......@@ -725,7 +725,7 @@ ssize_t spdy_data_read_callback(spdylay_session *session,
}
} // namespace
int SpdyUpstream::error_reply(Downstream *downstream, int status_code)
int SpdyUpstream::error_reply(Downstream *downstream, unsigned int status_code)
{
int rv;
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;
std::string content_length = util::utos(html.size());
std::string status_string = http2::get_status_string(status_code);
const char *nv[] = {
":status", http2::get_status_string(status_code),
":status", status_string.c_str(),
":version", "http/1.1",
"content-type", "text/html; charset=UTF-8",
"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);
size_t hdidx = 0;
std::string via_value;
nv[hdidx++] = ":status";
nv[hdidx++] = http2::get_status_string
std::string status_string = http2::get_status_string
(downstream->get_response_http_status());
nv[hdidx++] = ":status";
nv[hdidx++] = status_string.c_str();
nv[hdidx++] = ":version";
nv[hdidx++] = "HTTP/1.1";
for(Headers::const_iterator i = downstream->get_response_headers().begin();
......
......@@ -56,7 +56,7 @@ public:
int rst_stream(Downstream *downstream, int status_code);
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 int resume_read(IOCtrlReason reason, Downstream *downstream);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment