nghttpx: Use StringRef for add_hedeader

This commit is contained in:
Tatsuhiro Tsujikawa 2016-02-20 20:53:19 +09:00
parent 6f1347fc8b
commit 3ff148811b
4 changed files with 20 additions and 26 deletions

View File

@ -338,14 +338,10 @@ void add_header(bool &key_prev, size_t &sum, Headers &headers, std::string name,
} // namespace
namespace {
void add_header(size_t &sum, Headers &headers, const uint8_t *name,
size_t namelen, const uint8_t *value, size_t valuelen,
bool no_index, int16_t token) {
sum += namelen + valuelen;
headers.emplace_back(
std::string(reinterpret_cast<const char *>(name), namelen),
std::string(reinterpret_cast<const char *>(value), valuelen), no_index,
token);
void add_header(size_t &sum, Headers &headers, const StringRef &name,
const StringRef &value, bool no_index, int16_t token) {
sum += name.size() + value.size();
headers.emplace_back(name.str(), value.str(), no_index, token);
}
} // 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);
}
void FieldStore::add_header(const uint8_t *name, size_t namelen,
const uint8_t *value, size_t valuelen,
void FieldStore::add_header(const StringRef &name, const StringRef &value,
bool no_index, int16_t token) {
shrpx::add_header(buffer_size_, headers_, name, namelen, value, valuelen,
no_index, token);
shrpx::add_header(buffer_size_, headers_, name, value, no_index, token);
}
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::add_trailer(const uint8_t *name, size_t namelen,
const uint8_t *value, size_t valuelen,
void FieldStore::add_trailer(const StringRef &name, const StringRef &value,
bool no_index, int16_t token) {
// Header size limit should be applied to all header and trailer
// fields combined.
shrpx::add_header(buffer_size_, trailers_, name, namelen, value, valuelen,
no_index, token);
shrpx::add_header(buffer_size_, trailers_, name, value, no_index, token);
}
void FieldStore::add_trailer_lower(const StringRef &name,

View File

@ -81,8 +81,8 @@ public:
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(const uint8_t *name, size_t namelen, const uint8_t *value,
size_t valuelen, bool no_index, int16_t token);
void add_header(const StringRef &name, const StringRef &value, bool no_index,
int16_t token);
void append_last_header_key(const char *data, size_t len);
void append_last_header_value(const char *data, size_t len);
@ -97,8 +97,8 @@ public:
// Empties headers.
void clear_headers();
void add_trailer(const uint8_t *name, size_t namelen, const uint8_t *value,
size_t valuelen, bool no_index, int16_t token);
void add_trailer(const StringRef &name, const StringRef &value, bool no_index,
int16_t token);
void add_trailer_lower(const StringRef &name, const StringRef &value);
void append_last_trailer_key(const char *data, size_t len);

View File

@ -739,12 +739,12 @@ int on_header_callback(nghttp2_session *session, const nghttp2_frame *frame,
if (trailer) {
// 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);
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);
return 0;
}
@ -778,7 +778,8 @@ int on_header_callback(nghttp2_session *session, const nghttp2_frame *frame,
}
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);
return 0;
}

View File

@ -205,12 +205,12 @@ int on_header_callback(nghttp2_session *session, const nghttp2_frame *frame,
if (frame->headers.cat == NGHTTP2_HCAT_HEADERS) {
// 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);
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);
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);
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);
}