nghttpx: Return assemble cookie on the fly

This commit is contained in:
Tatsuhiro Tsujikawa 2016-01-14 00:44:10 +09:00
parent 3b8889a2a1
commit 6d6a00f1f5
4 changed files with 11 additions and 15 deletions

View File

@ -238,8 +238,8 @@ const Headers::value_type *get_header_linear(const Headers &headers,
} }
} // namespace } // namespace
void Downstream::assemble_request_cookie() { std::string Downstream::assemble_request_cookie() const {
std::string &cookie = assembled_request_cookie_; std::string cookie;
cookie = ""; cookie = "";
for (auto &kv : req_.fs.headers()) { for (auto &kv : req_.fs.headers()) {
if (kv.name.size() != 6 || kv.name[5] != 'e' || if (kv.name.size() != 6 || kv.name[5] != 'e' ||
@ -258,6 +258,8 @@ void Downstream::assemble_request_cookie() {
if (cookie.size() >= 2) { if (cookie.size() >= 2) {
cookie.erase(cookie.size() - 2); cookie.erase(cookie.size() - 2);
} }
return cookie;
} }
size_t Downstream::count_crumble_request_cookie() { size_t Downstream::count_crumble_request_cookie() {
@ -315,10 +317,6 @@ void Downstream::crumble_request_cookie(std::vector<nghttp2_nv> &nva) {
} }
} }
const std::string &Downstream::get_assembled_request_cookie() const {
return assembled_request_cookie_;
}
namespace { namespace {
void add_header(bool &key_prev, size_t &sum, Headers &headers, std::string name, void add_header(bool &key_prev, size_t &sum, Headers &headers, std::string name,
std::string value) { std::string value) {

View File

@ -221,8 +221,9 @@ public:
// Crumbles (split cookie by ";") in request_headers_ and adds them // Crumbles (split cookie by ";") in request_headers_ and adds them
// in |nva|. Headers::no_index is inherited. // in |nva|. Headers::no_index is inherited.
void crumble_request_cookie(std::vector<nghttp2_nv> &nva); void crumble_request_cookie(std::vector<nghttp2_nv> &nva);
void assemble_request_cookie(); // Assembles request cookies. The opposite operation against
const std::string &get_assembled_request_cookie() const; // crumble_request_cookie().
std::string assemble_request_cookie() const;
void void
set_request_start_time(std::chrono::high_resolution_clock::time_point time); set_request_start_time(std::chrono::high_resolution_clock::time_point time);
@ -379,7 +380,6 @@ private:
// location header field to decide the location should be rewritten // location header field to decide the location should be rewritten
// or not. // or not.
std::string request_downstream_host_; std::string request_downstream_host_;
std::string assembled_request_cookie_;
DefaultMemchunks request_buf_; DefaultMemchunks request_buf_;
DefaultMemchunks response_buf_; DefaultMemchunks response_buf_;

View File

@ -120,8 +120,7 @@ void test_downstream_assemble_request_cookie(void) {
req.fs.add_header("cookie", "bravo;"); req.fs.add_header("cookie", "bravo;");
req.fs.add_header("cookie", "charlie; "); req.fs.add_header("cookie", "charlie; ");
req.fs.add_header("cookie", "delta;;"); req.fs.add_header("cookie", "delta;;");
d.assemble_request_cookie(); CU_ASSERT("alpha; bravo; charlie; delta" == d.assemble_request_cookie());
CU_ASSERT("alpha; bravo; charlie; delta" == d.get_assembled_request_cookie());
} }
void test_downstream_rewrite_location_response_header(void) { void test_downstream_rewrite_location_response_header(void) {

View File

@ -233,8 +233,6 @@ int HttpDownstreamConnection::push_request_headers() {
downstream_->set_request_downstream_host(authority); downstream_->set_request_downstream_host(authority);
downstream_->assemble_request_cookie();
auto buf = downstream_->get_request_buf(); auto buf = downstream_->get_request_buf();
// Assume that method and request path do not contain \r\n. // Assume that method and request path do not contain \r\n.
@ -264,9 +262,10 @@ int HttpDownstreamConnection::push_request_headers() {
http2::build_http1_headers_from_headers(buf, req.fs.headers()); http2::build_http1_headers_from_headers(buf, req.fs.headers());
if (!downstream_->get_assembled_request_cookie().empty()) { auto cookie = downstream_->assemble_request_cookie();
if (!cookie.empty()) {
buf->append("Cookie: "); buf->append("Cookie: ");
buf->append(downstream_->get_assembled_request_cookie()); buf->append(cookie);
buf->append("\r\n"); buf->append("\r\n");
} }