From 62108e2c26be4a81dc6ea40e5ac78136cfc86c2b Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 11 Mar 2020 15:44:17 -0700 Subject: [PATCH] ircd::http: Move closure from response::head; use string_view literal. --- ircd/http.cc | 62 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/ircd/http.cc b/ircd/http.cc index fab17a293..19b2af8e6 100644 --- a/ircd/http.cc +++ b/ircd/http.cc @@ -498,38 +498,58 @@ ircd::http::response::response(window_buffer &out, writeline(out); } +namespace ircd::http +{ + static void assign(response::head &, const header &); +} + ircd::http::response::head::head(parse::capstan &pc, const headers::closure &c) :line::response{pc} ,headers { - http::headers{pc, [this, &c](const auto &h) + http::headers { - if(iequals(h.first, "content-type"s)) - this->content_type = h.second; + pc, [this, &c](const auto &header) + { + assign(*this, header); - else if(iequals(h.first, "content-length"s)) - this->content_length = parser.content_length(h.second); - - else if(iequals(h.first, "content-range"s)) - this->content_range = h.second; - - else if(iequals(h.first, "accept-range"s)) - this->content_range = h.second; - - else if(iequals(h.first, "transfer-encoding"s)) - this->transfer_encoding = h.second; - - else if(iequals(h.first, "server"s)) - this->server = h.second; - - if(c) - c(h); - }} + if(c) + c(header); + } + } } { } +void +ircd::http::assign(response::head &head, + const header &header) +{ + const auto &[key, val] + { + header + }; + + if(iequals(key, "content-type"_sv)) + head.content_type = val; + + else if(iequals(key, "content-length"_sv)) + head.content_length = parser.content_length(val); + + else if(iequals(key, "content-range"_sv)) + head.content_range = val; + + else if(iequals(key, "accept-range"_sv)) + head.content_range = val; + + else if(iequals(key, "transfer-encoding"_sv)) + head.transfer_encoding = val; + + else if(iequals(key, "server"_sv)) + head.server = val; +} + ircd::http::response::chunk::chunk(parse::capstan &pc) try :line{pc}