From bbc1844c61ad1bf7f4b48601e4e1a7f1b647446b Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 11 Mar 2018 10:23:06 -0700 Subject: [PATCH] ircd::http: Status code signage consistency. --- include/ircd/http.h | 4 ++-- ircd/client.cc | 4 ++-- ircd/http.cc | 9 +++++---- ircd/resource.cc | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/ircd/http.h b/include/ircd/http.h index 4525fff24..dcb271f04 100644 --- a/include/ircd/http.h +++ b/include/ircd/http.h @@ -14,7 +14,7 @@ /// HyperText TransPort: formal grammars & tools namespace ircd::http { - enum code :int; + enum code :ushort; struct error; struct line; struct query; @@ -40,7 +40,7 @@ namespace ircd::http // Add more as you go... // enum ircd::http::code -:int +:ushort { CONTINUE = 100, SWITCHING_PROTOCOLS = 101, diff --git a/ircd/client.cc b/ircd/client.cc index 662fcd184..64cc4a6bc 100644 --- a/ircd/client.cc +++ b/ircd/client.cc @@ -687,11 +687,11 @@ catch(const http::error &e) { if(ircd::debugmode) log::error { - "socket(%p) local[%s] remote[%s] HTTP %d %s `%s' :%s", + "socket(%p) local[%s] remote[%s] HTTP %u %s `%s' :%s", sock.get(), string(local(*this)), string(remote(*this)), - int(e.code), + uint(e.code), http::status(e.code), head.uri, e.content diff --git a/ircd/http.cc b/ircd/http.cc index eeb51825c..4bbdc1e10 100644 --- a/ircd/http.cc +++ b/ircd/http.cc @@ -72,7 +72,8 @@ BOOST_FUSION_ADAPT_STRUCT ( decltype(ircd::http::line::request::version), version ) ) -const decltype(ircd::http::reason) ircd::http::reason +decltype(ircd::http::reason) +ircd::http::reason { { code::CONTINUE, "Continue" }, { code::SWITCHING_PROTOCOLS, "Switching Protocols" }, @@ -765,7 +766,7 @@ ircd::http::error::error(const http::code &code, ,headers{std::move(headers)} ,code{code} { - snprintf(buf, sizeof(buf), "%d %s", int(code), status(code).c_str()); + snprintf(buf, sizeof(buf), "%u %s", uint(code), status(code).c_str()); } ircd::http::code @@ -786,7 +787,7 @@ ircd::http::status(const string_view &str) } ircd::string_view -ircd::http::status(const enum code &code) +ircd::http::status(const http::code &code) try { return reason.at(code); @@ -795,7 +796,7 @@ catch(const std::out_of_range &e) { log::warning { - "No reason string for HTTP status code %d", int(code) + "No reason string for HTTP status code %u", uint(code) }; return ""_sv; diff --git a/ircd/resource.cc b/ircd/resource.cc index 46d981894..a898b61ce 100644 --- a/ircd/resource.cc +++ b/ircd/resource.cc @@ -709,7 +709,7 @@ ircd::resource::response::response(client &client, client.sock.get(), string(local(client)), string(remote(client)), - int(code), + uint(code), http::status(code), request_time, content_type,