diff --git a/src/http2.cc b/src/http2.cc index eba7aa54..6f347cc2 100644 --- a/src/http2.cc +++ b/src/http2.cc @@ -271,7 +271,7 @@ void copy_url_component(std::string &dest, const http_parser_url *u, int field, Headers::value_type to_header(const uint8_t *name, size_t namelen, const uint8_t *value, size_t valuelen, - bool no_index, int16_t token) { + bool no_index, int32_t token) { return Header(std::string(reinterpret_cast(name), namelen), std::string(reinterpret_cast(value), valuelen), no_index, token); @@ -279,7 +279,7 @@ Headers::value_type to_header(const uint8_t *name, size_t namelen, void add_header(Headers &nva, const uint8_t *name, size_t namelen, const uint8_t *value, size_t valuelen, bool no_index, - int16_t token) { + int32_t token) { if (valuelen > 0) { size_t i, j; for (i = 0; i < valuelen && (value[i] == ' ' || value[i] == '\t'); ++i) @@ -760,7 +760,7 @@ void init_hdidx(HeaderIndex &hdidx) { std::fill(std::begin(hdidx), std::end(hdidx), -1); } -void index_header(HeaderIndex &hdidx, int16_t token, size_t idx) { +void index_header(HeaderIndex &hdidx, int32_t token, size_t idx) { if (token == -1) { return; } @@ -769,7 +769,7 @@ void index_header(HeaderIndex &hdidx, int16_t token, size_t idx) { } bool check_http2_request_pseudo_header(const HeaderIndex &hdidx, - int16_t token) { + int32_t token) { switch (token) { case HD__AUTHORITY: case HD__METHOD: @@ -782,7 +782,7 @@ bool check_http2_request_pseudo_header(const HeaderIndex &hdidx, } bool check_http2_response_pseudo_header(const HeaderIndex &hdidx, - int16_t token) { + int32_t token) { switch (token) { case HD__STATUS: return hdidx[token] == -1; @@ -791,7 +791,7 @@ bool check_http2_response_pseudo_header(const HeaderIndex &hdidx, } } -bool http2_header_allowed(int16_t token) { +bool http2_header_allowed(int32_t token) { switch (token) { case HD_CONNECTION: case HD_KEEP_ALIVE: @@ -813,7 +813,7 @@ bool http2_mandatory_request_headers_presence(const HeaderIndex &hdidx) { return true; } -const Headers::value_type *get_header(const HeaderIndex &hdidx, int16_t token, +const Headers::value_type *get_header(const HeaderIndex &hdidx, int32_t token, const Headers &nva) { auto i = hdidx[token]; if (i == -1) { @@ -822,7 +822,7 @@ const Headers::value_type *get_header(const HeaderIndex &hdidx, int16_t token, return &nva[i]; } -Headers::value_type *get_header(const HeaderIndex &hdidx, int16_t token, +Headers::value_type *get_header(const HeaderIndex &hdidx, int32_t token, Headers &nva) { auto i = hdidx[token]; if (i == -1) { diff --git a/src/http2.h b/src/http2.h index 8eaeff56..58a4cc00 100644 --- a/src/http2.h +++ b/src/http2.h @@ -44,7 +44,7 @@ namespace nghttp2 { struct Header { Header(std::string name, std::string value, bool no_index = false, - int16_t token = -1) + int32_t token = -1) : name(std::move(name)), value(std::move(value)), token(token), @@ -62,7 +62,7 @@ struct Header { std::string name; std::string value; - int16_t token; + int32_t token; bool no_index; }; @@ -89,14 +89,14 @@ void copy_url_component(std::string &dest, const http_parser_url *u, int field, Headers::value_type to_header(const uint8_t *name, size_t namelen, const uint8_t *value, size_t valuelen, - bool no_index, int16_t token); + bool no_index, int32_t token); // Add name/value pairs to |nva|. If |no_index| is true, this // name/value pair won't be indexed when it is forwarded to the next // hop. This function strips white spaces around |value|. void add_header(Headers &nva, const uint8_t *name, size_t namelen, const uint8_t *value, size_t valuelen, bool no_index, - int16_t token); + int32_t token); // Returns pointer to the entry in |nva| which has name |name|. If // more than one entries which have the name |name|, last occurrence @@ -277,30 +277,30 @@ int lookup_token(const std::string &name); // array containing at least HD_MAXIDX elements. void init_hdidx(HeaderIndex &hdidx); // Indexes header |token| using index |idx|. -void index_header(HeaderIndex &hdidx, int16_t token, size_t idx); +void index_header(HeaderIndex &hdidx, int32_t token, size_t idx); // Returns true if HTTP/2 request pseudo header |token| is not indexed // yet and not -1. -bool check_http2_request_pseudo_header(const HeaderIndex &hdidx, int16_t token); +bool check_http2_request_pseudo_header(const HeaderIndex &hdidx, int32_t token); // Returns true if HTTP/2 response pseudo header |token| is not // indexed yet and not -1. bool check_http2_response_pseudo_header(const HeaderIndex &hdidx, - int16_t token); + int32_t token); // Returns true if header field denoted by |token| is allowed for // HTTP/2. -bool http2_header_allowed(int16_t token); +bool http2_header_allowed(int32_t token); // Returns true that |hdidx| contains mandatory HTTP/2 request // headers. bool http2_mandatory_request_headers_presence(const HeaderIndex &hdidx); // Returns header denoted by |token| using index |hdidx|. -const Headers::value_type *get_header(const HeaderIndex &hdidx, int16_t token, +const Headers::value_type *get_header(const HeaderIndex &hdidx, int32_t token, const Headers &nva); -Headers::value_type *get_header(const HeaderIndex &hdidx, int16_t token, +Headers::value_type *get_header(const HeaderIndex &hdidx, int32_t token, Headers &nva); struct LinkHeader { diff --git a/src/nghttp.cc b/src/nghttp.cc index e3d4e110..a1705124 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -273,34 +273,7 @@ bool Request::is_ipv6_literal_addr() const { } } -bool Request::response_pseudo_header_allowed(int16_t token) const { - if (!res_nva.empty() && res_nva.back().name.c_str()[0] != ':') { - return false; - } - switch (token) { - case http2::HD__STATUS: - return res_hdidx[token] == -1; - default: - return false; - } -} - -bool Request::push_request_pseudo_header_allowed(int16_t token) const { - if (!req_nva.empty() && req_nva.back().name.c_str()[0] != ':') { - return false; - } - switch (token) { - case http2::HD__AUTHORITY: - case http2::HD__METHOD: - case http2::HD__PATH: - case http2::HD__SCHEME: - return req_hdidx[token] == -1; - default: - return false; - } -} - -Headers::value_type *Request::get_res_header(int16_t token) { +Headers::value_type *Request::get_res_header(int32_t token) { auto idx = res_hdidx[token]; if (idx == -1) { return nullptr; @@ -308,7 +281,7 @@ Headers::value_type *Request::get_res_header(int16_t token) { return &res_nva[idx]; } -Headers::value_type *Request::get_req_header(int16_t token) { +Headers::value_type *Request::get_req_header(int32_t token) { auto idx = req_hdidx[token]; if (idx == -1) { return nullptr; diff --git a/src/nghttp.h b/src/nghttp.h index 715a110e..df4ca685 100644 --- a/src/nghttp.h +++ b/src/nghttp.h @@ -125,11 +125,8 @@ struct Request { bool is_ipv6_literal_addr() const; - bool response_pseudo_header_allowed(int16_t token) const; - bool push_request_pseudo_header_allowed(int16_t token) const; - - Headers::value_type *get_res_header(int16_t token); - Headers::value_type *get_req_header(int16_t token); + Headers::value_type *get_res_header(int32_t token); + Headers::value_type *get_req_header(int32_t token); void record_request_start_time(); void record_response_start_time(); diff --git a/src/shrpx_downstream.cc b/src/shrpx_downstream.cc index 32b7c1f2..0a8da837 100644 --- a/src/shrpx_downstream.cc +++ b/src/shrpx_downstream.cc @@ -331,7 +331,7 @@ void Downstream::crumble_request_cookie(std::vector &nva) { namespace { void add_header(bool &key_prev, size_t &sum, Headers &headers, const StringRef &name, const StringRef &value, bool no_index, - int16_t token) { + int32_t token) { key_prev = true; sum += name.size() + value.size(); headers.emplace_back(name.str(), value.str(), no_index, token); @@ -340,7 +340,7 @@ void add_header(bool &key_prev, size_t &sum, Headers &headers, namespace { void add_header(size_t &sum, Headers &headers, const StringRef &name, - const StringRef &value, bool no_index, int16_t token) { + const StringRef &value, bool no_index, int32_t token) { sum += name.size() + value.size(); headers.emplace_back(name.str(), value.str(), no_index, token); } @@ -388,7 +388,7 @@ int FieldStore::parse_content_length() { return 0; } -const Headers::value_type *FieldStore::header(int16_t token) const { +const Headers::value_type *FieldStore::header(int32_t token) const { for (auto it = headers_.rbegin(); it != headers_.rend(); ++it) { auto &kv = *it; if (kv.token == token) { @@ -398,7 +398,7 @@ const Headers::value_type *FieldStore::header(int16_t token) const { return nullptr; } -Headers::value_type *FieldStore::header(int16_t token) { +Headers::value_type *FieldStore::header(int32_t token) { for (auto it = headers_.rbegin(); it != headers_.rend(); ++it) { auto &kv = *it; if (kv.token == token) { @@ -422,7 +422,7 @@ void FieldStore::add_header_lower(const StringRef &name, const StringRef &value, } void FieldStore::add_header_token(const StringRef &name, const StringRef &value, - bool no_index, int16_t token) { + bool no_index, int32_t token) { shrpx::add_header(buffer_size_, headers_, name, value, no_index, token); } @@ -449,7 +449,7 @@ void FieldStore::add_trailer_lower(const StringRef &name, void FieldStore::add_trailer_token(const StringRef &name, const StringRef &value, bool no_index, - int16_t token) { + int32_t token) { // Header size limit should be applied to all header and trailer // fields combined. shrpx::add_header(buffer_size_, trailers_, name, value, no_index, token); diff --git a/src/shrpx_downstream.h b/src/shrpx_downstream.h index 4306940d..3864674f 100644 --- a/src/shrpx_downstream.h +++ b/src/shrpx_downstream.h @@ -73,8 +73,8 @@ public: // multiple header have |name| as name, return last occurrence from // the beginning. If no such header is found, returns nullptr. // This function must be called after headers are indexed - const Headers::value_type *header(int16_t token) const; - Headers::value_type *header(int16_t token); + const Headers::value_type *header(int32_t token) const; + Headers::value_type *header(int32_t token); // Returns pointer to the header field with the name |name|. If no // such header is found, returns nullptr. const Headers::value_type *header(const StringRef &name) const; @@ -82,7 +82,7 @@ public: void add_header_lower(const StringRef &name, const StringRef &value, bool no_index); void add_header_token(const StringRef &name, const StringRef &value, - bool no_index, int16_t token); + bool no_index, int32_t token); void append_last_header_key(const char *data, size_t len); void append_last_header_value(const char *data, size_t len); @@ -99,7 +99,7 @@ public: void add_trailer_lower(const StringRef &name, const StringRef &value, bool no_index); void add_trailer_token(const StringRef &name, const StringRef &value, - bool no_index, int16_t token); + bool no_index, int32_t token); void append_last_trailer_key(const char *data, size_t len); void append_last_trailer_value(const char *data, size_t len);