From 1e041deb550b8c114dc4ff0e954977e035cf1f1e Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 8 Mar 2018 11:42:43 -0800 Subject: [PATCH] ircd: Add head-only resource::response; cleanup comments / cruft. --- include/ircd/resource.h | 1 + ircd/resource.cc | 42 +++++++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/include/ircd/resource.h b/include/ircd/resource.h index 51af6daed..77ae00b78 100644 --- a/include/ircd/resource.h +++ b/include/ircd/resource.h @@ -131,6 +131,7 @@ struct ircd::resource::request::object struct ircd::resource::response { + response(client &, const size_t &content_length, const string_view &content_type, const http::code & = http::OK, const string_view &headers = {}); response(client &, const string_view &str, const string_view &content_type, const http::code &, const vector_view &); response(client &, const string_view &str, const string_view &content_type, const http::code & = http::OK, const string_view &headers = {}); response(client &, const json::object &str, const http::code & = http::OK); diff --git a/ircd/resource.cc b/ircd/resource.cc index 94d1089b0..948be4cc7 100644 --- a/ircd/resource.cc +++ b/ircd/resource.cc @@ -618,6 +618,27 @@ ircd::resource::response::response(client &client, const string_view &content_type, const http::code &code, const string_view &headers) +{ + // Head gets sent + response + { + client, content.size(), content_type, code, headers + }; + + // All content gets sent + const ilist vector + { + content + }; + + write_closure(client)(vector); +} + +ircd::resource::response::response(client &client, + const size_t &content_length, + const string_view &content_type, + const http::code &code, + const string_view &headers) { const auto request_time { @@ -629,14 +650,6 @@ ircd::resource::response::response(client &client, "%zd$us", request_time }; - const string_view cache_control - { - (code >= 200 && code < 300) || - (code >= 403 && code < 405) || - (code >= 300 && code < 400)? "no-cache": - "" - }; - // This buffer will be passed to the socket and sent out; // cannot be static/tls. char head_buf[4_KiB]; @@ -645,17 +658,16 @@ ircd::resource::response::response(client &client, { head, code, - content.size(), + content_length, content_type, headers, { { "Access-Control-Allow-Origin", "*" }, //TODO: XXX - { "Cache-Control", cache_control }, { "X-IRCd-Request-Timer", rtime, }, }, }; - // Maximum size is 2_KiB which is realistically ok but ideally a small + // Maximum size is is realistically ok but ideally a small // maximum; this exception should hit the developer in testing. if(unlikely(!head.remaining())) throw assertive @@ -665,23 +677,21 @@ ircd::resource::response::response(client &client, const ilist vector { - head.completed(), - content + head.completed() }; write_closure(client)(vector); log::debug { - "socket(%p) local[%s] remote[%s] HTTP %d %s in %ld$us; response in %ld$us (%s) content-length:%zu", + "socket(%p) local[%s] remote[%s] HTTP %d %s in %ld$us; %s %zu content", client.sock.get(), string(local(client)), string(remote(client)), int(code), http::status(code), request_time, - (client.timer.at().count() - request_time), content_type, - content.size() + content_length, }; }