nghttpx: Rewrite Downstream::assemble_request_cookie using StringRef
This commit is contained in:
parent
71cc7a96c2
commit
dcae6efaa2
|
@ -257,15 +257,22 @@ search_header_linear_backwards(const HeaderRefs &headers,
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
std::string Downstream::assemble_request_cookie() const {
|
StringRef Downstream::assemble_request_cookie() {
|
||||||
std::string cookie;
|
size_t len = 0;
|
||||||
cookie = "";
|
|
||||||
for (auto &kv : req_.fs.headers()) {
|
for (auto &kv : req_.fs.headers()) {
|
||||||
if (kv.token != http2::HD_COOKIE) {
|
if (kv.token != http2::HD_COOKIE || kv.value.empty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kv.value.empty()) {
|
len += kv.value.size() + str_size("; ");
|
||||||
|
}
|
||||||
|
|
||||||
|
auto iov = make_byte_ref(balloc_, len + 1);
|
||||||
|
auto p = iov.base;
|
||||||
|
|
||||||
|
for (auto &kv : req_.fs.headers()) {
|
||||||
|
if (kv.token != http2::HD_COOKIE || kv.value.empty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,18 +287,16 @@ std::string Downstream::assemble_request_cookie() const {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (end == std::end(kv.value)) {
|
p = std::copy(std::begin(kv.value), end, p);
|
||||||
cookie += kv.value;
|
p = util::copy_lit(p, "; ");
|
||||||
} else {
|
|
||||||
cookie.append(std::begin(kv.value), end);
|
|
||||||
}
|
|
||||||
cookie += "; ";
|
|
||||||
}
|
|
||||||
if (cookie.size() >= 2) {
|
|
||||||
cookie.erase(cookie.size() - 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cookie;
|
// cut trailing "; "
|
||||||
|
if (p - iov.base >= 2) {
|
||||||
|
p -= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return StringRef{iov.base, p};
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Downstream::count_crumble_request_cookie() {
|
size_t Downstream::count_crumble_request_cookie() {
|
||||||
|
|
|
@ -257,7 +257,7 @@ public:
|
||||||
void crumble_request_cookie(std::vector<nghttp2_nv> &nva);
|
void crumble_request_cookie(std::vector<nghttp2_nv> &nva);
|
||||||
// Assembles request cookies. The opposite operation against
|
// Assembles request cookies. The opposite operation against
|
||||||
// crumble_request_cookie().
|
// crumble_request_cookie().
|
||||||
std::string assemble_request_cookie() const;
|
StringRef assemble_request_cookie();
|
||||||
|
|
||||||
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);
|
||||||
|
|
Loading…
Reference in New Issue