nghttpx: Use StringRef for add_hedeader
This commit is contained in:
parent
6f1347fc8b
commit
3ff148811b
|
@ -338,14 +338,10 @@ void add_header(bool &key_prev, size_t &sum, Headers &headers, std::string name,
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void add_header(size_t &sum, Headers &headers, const uint8_t *name,
|
void add_header(size_t &sum, Headers &headers, const StringRef &name,
|
||||||
size_t namelen, const uint8_t *value, size_t valuelen,
|
const StringRef &value, bool no_index, int16_t token) {
|
||||||
bool no_index, int16_t token) {
|
sum += name.size() + value.size();
|
||||||
sum += namelen + valuelen;
|
headers.emplace_back(name.str(), value.str(), no_index, token);
|
||||||
headers.emplace_back(
|
|
||||||
std::string(reinterpret_cast<const char *>(name), namelen),
|
|
||||||
std::string(reinterpret_cast<const char *>(value), valuelen), no_index,
|
|
||||||
token);
|
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -430,11 +426,9 @@ void FieldStore::add_header(std::string name, std::string value,
|
||||||
headers_.emplace_back(std::move(name), std::move(value), false, token);
|
headers_.emplace_back(std::move(name), std::move(value), false, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FieldStore::add_header(const uint8_t *name, size_t namelen,
|
void FieldStore::add_header(const StringRef &name, const StringRef &value,
|
||||||
const uint8_t *value, size_t valuelen,
|
|
||||||
bool no_index, int16_t token) {
|
bool no_index, int16_t token) {
|
||||||
shrpx::add_header(buffer_size_, headers_, name, namelen, value, valuelen,
|
shrpx::add_header(buffer_size_, headers_, name, value, no_index, token);
|
||||||
no_index, token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FieldStore::append_last_header_key(const char *data, size_t len) {
|
void FieldStore::append_last_header_key(const char *data, size_t len) {
|
||||||
|
@ -449,13 +443,11 @@ void FieldStore::append_last_header_value(const char *data, size_t len) {
|
||||||
|
|
||||||
void FieldStore::clear_headers() { headers_.clear(); }
|
void FieldStore::clear_headers() { headers_.clear(); }
|
||||||
|
|
||||||
void FieldStore::add_trailer(const uint8_t *name, size_t namelen,
|
void FieldStore::add_trailer(const StringRef &name, const StringRef &value,
|
||||||
const uint8_t *value, size_t valuelen,
|
|
||||||
bool no_index, int16_t token) {
|
bool no_index, int16_t token) {
|
||||||
// Header size limit should be applied to all header and trailer
|
// Header size limit should be applied to all header and trailer
|
||||||
// fields combined.
|
// fields combined.
|
||||||
shrpx::add_header(buffer_size_, trailers_, name, namelen, value, valuelen,
|
shrpx::add_header(buffer_size_, trailers_, name, value, no_index, token);
|
||||||
no_index, token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FieldStore::add_trailer_lower(const StringRef &name,
|
void FieldStore::add_trailer_lower(const StringRef &name,
|
||||||
|
|
|
@ -81,8 +81,8 @@ public:
|
||||||
|
|
||||||
void add_header_lower(const StringRef &name, const StringRef &value);
|
void add_header_lower(const StringRef &name, const StringRef &value);
|
||||||
void add_header(std::string name, std::string value, int16_t token);
|
void add_header(std::string name, std::string value, int16_t token);
|
||||||
void add_header(const uint8_t *name, size_t namelen, const uint8_t *value,
|
void add_header(const StringRef &name, const StringRef &value, bool no_index,
|
||||||
size_t valuelen, bool no_index, int16_t token);
|
int16_t token);
|
||||||
|
|
||||||
void append_last_header_key(const char *data, size_t len);
|
void append_last_header_key(const char *data, size_t len);
|
||||||
void append_last_header_value(const char *data, size_t len);
|
void append_last_header_value(const char *data, size_t len);
|
||||||
|
@ -97,8 +97,8 @@ public:
|
||||||
// Empties headers.
|
// Empties headers.
|
||||||
void clear_headers();
|
void clear_headers();
|
||||||
|
|
||||||
void add_trailer(const uint8_t *name, size_t namelen, const uint8_t *value,
|
void add_trailer(const StringRef &name, const StringRef &value, bool no_index,
|
||||||
size_t valuelen, bool no_index, int16_t token);
|
int16_t token);
|
||||||
void add_trailer_lower(const StringRef &name, const StringRef &value);
|
void add_trailer_lower(const StringRef &name, const StringRef &value);
|
||||||
|
|
||||||
void append_last_trailer_key(const char *data, size_t len);
|
void append_last_trailer_key(const char *data, size_t len);
|
||||||
|
|
|
@ -739,12 +739,12 @@ int on_header_callback(nghttp2_session *session, const nghttp2_frame *frame,
|
||||||
|
|
||||||
if (trailer) {
|
if (trailer) {
|
||||||
// just store header fields for trailer part
|
// just store header fields for trailer part
|
||||||
resp.fs.add_trailer(name, namelen, value, valuelen,
|
resp.fs.add_trailer(StringRef{name, namelen}, StringRef{value, valuelen},
|
||||||
flags & NGHTTP2_NV_FLAG_NO_INDEX, token);
|
flags & NGHTTP2_NV_FLAG_NO_INDEX, token);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.fs.add_header(name, namelen, value, valuelen,
|
resp.fs.add_header(StringRef{name, namelen}, StringRef{value, valuelen},
|
||||||
flags & NGHTTP2_NV_FLAG_NO_INDEX, token);
|
flags & NGHTTP2_NV_FLAG_NO_INDEX, token);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -778,7 +778,8 @@ int on_header_callback(nghttp2_session *session, const nghttp2_frame *frame,
|
||||||
}
|
}
|
||||||
|
|
||||||
auto token = http2::lookup_token(name, namelen);
|
auto token = http2::lookup_token(name, namelen);
|
||||||
promised_req.fs.add_header(name, namelen, value, valuelen,
|
promised_req.fs.add_header(StringRef{name, namelen},
|
||||||
|
StringRef{value, valuelen},
|
||||||
flags & NGHTTP2_NV_FLAG_NO_INDEX, token);
|
flags & NGHTTP2_NV_FLAG_NO_INDEX, token);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,12 +205,12 @@ int on_header_callback(nghttp2_session *session, const nghttp2_frame *frame,
|
||||||
|
|
||||||
if (frame->headers.cat == NGHTTP2_HCAT_HEADERS) {
|
if (frame->headers.cat == NGHTTP2_HCAT_HEADERS) {
|
||||||
// just store header fields for trailer part
|
// just store header fields for trailer part
|
||||||
req.fs.add_trailer(name, namelen, value, valuelen,
|
req.fs.add_trailer(StringRef{name, namelen}, StringRef{value, valuelen},
|
||||||
flags & NGHTTP2_NV_FLAG_NO_INDEX, token);
|
flags & NGHTTP2_NV_FLAG_NO_INDEX, token);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
req.fs.add_header(name, namelen, value, valuelen,
|
req.fs.add_header(StringRef{name, namelen}, StringRef{value, valuelen},
|
||||||
flags & NGHTTP2_NV_FLAG_NO_INDEX, token);
|
flags & NGHTTP2_NV_FLAG_NO_INDEX, token);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -593,7 +593,8 @@ int on_frame_send_callback(nghttp2_session *session, const nghttp2_frame *frame,
|
||||||
req.path = http2::rewrite_clean_path(nv.value, nv.value + nv.valuelen);
|
req.path = http2::rewrite_clean_path(nv.value, nv.value + nv.valuelen);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
req.fs.add_header(nv.name, nv.namelen, nv.value, nv.valuelen,
|
req.fs.add_header(StringRef{nv.name, nv.namelen},
|
||||||
|
StringRef{nv.value, nv.valuelen},
|
||||||
nv.flags & NGHTTP2_NV_FLAG_NO_INDEX, token);
|
nv.flags & NGHTTP2_NV_FLAG_NO_INDEX, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue