nghttpx: Rewrite Downstream::assemble_request_cookie using StringRef

This commit is contained in:
Tatsuhiro Tsujikawa 2016-03-18 23:50:04 +09:00
parent 71cc7a96c2
commit dcae6efaa2
2 changed files with 21 additions and 16 deletions

View File

@ -257,15 +257,22 @@ search_header_linear_backwards(const HeaderRefs &headers,
}
} // namespace
std::string Downstream::assemble_request_cookie() const {
std::string cookie;
cookie = "";
StringRef Downstream::assemble_request_cookie() {
size_t len = 0;
for (auto &kv : req_.fs.headers()) {
if (kv.token != http2::HD_COOKIE) {
if (kv.token != http2::HD_COOKIE || kv.value.empty()) {
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;
}
@ -280,18 +287,16 @@ std::string Downstream::assemble_request_cookie() const {
break;
}
if (end == std::end(kv.value)) {
cookie += kv.value;
} else {
cookie.append(std::begin(kv.value), end);
}
cookie += "; ";
}
if (cookie.size() >= 2) {
cookie.erase(cookie.size() - 2);
p = std::copy(std::begin(kv.value), end, p);
p = util::copy_lit(p, "; ");
}
return cookie;
// cut trailing "; "
if (p - iov.base >= 2) {
p -= 2;
}
return StringRef{iov.base, p};
}
size_t Downstream::count_crumble_request_cookie() {

View File

@ -257,7 +257,7 @@ public:
void crumble_request_cookie(std::vector<nghttp2_nv> &nva);
// Assembles request cookies. The opposite operation against
// crumble_request_cookie().
std::string assemble_request_cookie() const;
StringRef assemble_request_cookie();
void
set_request_start_time(std::chrono::high_resolution_clock::time_point time);