mirror of
https://github.com/nghttp2/nghttp2.git
synced 2025-12-07 10:38:53 +08:00
http2::get_header: Take std::string_view
This commit is contained in:
@@ -317,7 +317,8 @@ void add_header(Headers &nva, const StringRef &name, const StringRef &value,
|
||||
nva.push_back(to_header(name, value, no_index, token));
|
||||
}
|
||||
|
||||
const Headers::value_type *get_header(const Headers &nva, const char *name) {
|
||||
const Headers::value_type *get_header(const Headers &nva,
|
||||
const std::string_view &name) {
|
||||
const Headers::value_type *res = nullptr;
|
||||
for (auto &nv : nva) {
|
||||
if (nv.name == name) {
|
||||
|
||||
@@ -116,7 +116,8 @@ void add_header(Headers &nva, const StringRef &name, const StringRef &value,
|
||||
// Returns pointer to the entry in |nva| which has name |name|. If
|
||||
// more than one entries which have the name |name|, last occurrence
|
||||
// in |nva| is returned. If no such entry exist, returns nullptr.
|
||||
const Headers::value_type *get_header(const Headers &nva, const char *name);
|
||||
const Headers::value_type *get_header(const Headers &nva,
|
||||
const std::string_view &name);
|
||||
|
||||
// Returns true if the value of |nv| is not empty.
|
||||
bool non_empty_value(const HeaderRefs::value_type *nv);
|
||||
|
||||
@@ -111,15 +111,15 @@ void test_http2_get_header(void) {
|
||||
{"charlie", "4"}, {"delta", "5"}, {"echo", "6"},
|
||||
{"content-length", "7"}};
|
||||
const Headers::value_type *rv;
|
||||
rv = http2::get_header(nva, "delta");
|
||||
rv = http2::get_header(nva, "delta"sv);
|
||||
assert_not_null(rv);
|
||||
assert_stdstring_equal("delta", rv->name);
|
||||
|
||||
rv = http2::get_header(nva, "bravo");
|
||||
rv = http2::get_header(nva, "bravo"sv);
|
||||
assert_not_null(rv);
|
||||
assert_stdstring_equal("bravo", rv->name);
|
||||
|
||||
rv = http2::get_header(nva, "foxtrot");
|
||||
rv = http2::get_header(nva, "foxtrot"sv);
|
||||
assert_null(rv);
|
||||
}
|
||||
|
||||
|
||||
@@ -446,7 +446,7 @@ int submit_request(HttpClient *client, const Headers &headers, Request *req) {
|
||||
http2::make_field_nv(kv.name, kv.value, http2::no_index(kv.no_index)));
|
||||
}
|
||||
|
||||
auto method = http2::get_header(build_headers, ":method");
|
||||
auto method = http2::get_header(build_headers, ":method"sv);
|
||||
assert(method);
|
||||
|
||||
req->method = method->value;
|
||||
@@ -1529,7 +1529,7 @@ void HttpClient::output_har(FILE *outfile) {
|
||||
|
||||
json_object_set_new(content, "size", json_integer(req->response_len));
|
||||
|
||||
auto content_type_ptr = http2::get_header(req->res_nva, "content-type");
|
||||
auto content_type_ptr = http2::get_header(req->res_nva, "content-type"sv);
|
||||
|
||||
const char *content_type = "";
|
||||
if (content_type_ptr) {
|
||||
|
||||
Reference in New Issue
Block a user