nghttpx: Return assemble cookie on the fly
This commit is contained in:
parent
3b8889a2a1
commit
6d6a00f1f5
|
@ -238,8 +238,8 @@ const Headers::value_type *get_header_linear(const Headers &headers,
|
|||
}
|
||||
} // namespace
|
||||
|
||||
void Downstream::assemble_request_cookie() {
|
||||
std::string &cookie = assembled_request_cookie_;
|
||||
std::string Downstream::assemble_request_cookie() const {
|
||||
std::string cookie;
|
||||
cookie = "";
|
||||
for (auto &kv : req_.fs.headers()) {
|
||||
if (kv.name.size() != 6 || kv.name[5] != 'e' ||
|
||||
|
@ -258,6 +258,8 @@ void Downstream::assemble_request_cookie() {
|
|||
if (cookie.size() >= 2) {
|
||||
cookie.erase(cookie.size() - 2);
|
||||
}
|
||||
|
||||
return 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 {
|
||||
void add_header(bool &key_prev, size_t &sum, Headers &headers, std::string name,
|
||||
std::string value) {
|
||||
|
|
|
@ -221,8 +221,9 @@ public:
|
|||
// Crumbles (split cookie by ";") in request_headers_ and adds them
|
||||
// in |nva|. Headers::no_index is inherited.
|
||||
void crumble_request_cookie(std::vector<nghttp2_nv> &nva);
|
||||
void assemble_request_cookie();
|
||||
const std::string &get_assembled_request_cookie() const;
|
||||
// Assembles request cookies. The opposite operation against
|
||||
// crumble_request_cookie().
|
||||
std::string assemble_request_cookie() const;
|
||||
|
||||
void
|
||||
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
|
||||
// or not.
|
||||
std::string request_downstream_host_;
|
||||
std::string assembled_request_cookie_;
|
||||
|
||||
DefaultMemchunks request_buf_;
|
||||
DefaultMemchunks response_buf_;
|
||||
|
|
|
@ -120,8 +120,7 @@ void test_downstream_assemble_request_cookie(void) {
|
|||
req.fs.add_header("cookie", "bravo;");
|
||||
req.fs.add_header("cookie", "charlie; ");
|
||||
req.fs.add_header("cookie", "delta;;");
|
||||
d.assemble_request_cookie();
|
||||
CU_ASSERT("alpha; bravo; charlie; delta" == d.get_assembled_request_cookie());
|
||||
CU_ASSERT("alpha; bravo; charlie; delta" == d.assemble_request_cookie());
|
||||
}
|
||||
|
||||
void test_downstream_rewrite_location_response_header(void) {
|
||||
|
|
|
@ -233,8 +233,6 @@ int HttpDownstreamConnection::push_request_headers() {
|
|||
|
||||
downstream_->set_request_downstream_host(authority);
|
||||
|
||||
downstream_->assemble_request_cookie();
|
||||
|
||||
auto buf = downstream_->get_request_buf();
|
||||
|
||||
// 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());
|
||||
|
||||
if (!downstream_->get_assembled_request_cookie().empty()) {
|
||||
auto cookie = downstream_->assemble_request_cookie();
|
||||
if (!cookie.empty()) {
|
||||
buf->append("Cookie: ");
|
||||
buf->append(downstream_->get_assembled_request_cookie());
|
||||
buf->append(cookie);
|
||||
buf->append("\r\n");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue