diff --git a/genheaderfunc.py b/genheaderfunc.py index 079896ea..d8111d4c 100755 --- a/genheaderfunc.py +++ b/genheaderfunc.py @@ -21,9 +21,11 @@ HEADERS = [ "content-length", "location", "trailer", - "referer", "link", - "accept", + "accept-encoding", + "accept-language", + "cache-control", + "user-agent", # disallowed h1 headers 'connection', 'keep-alive', diff --git a/src/http2.cc b/src/http2.cc index 2e77e1ec..8bbc7d33 100644 --- a/src/http2.cc +++ b/src/http2.cc @@ -478,9 +478,6 @@ int lookup_token(const uint8_t *name, size_t namelen) { } break; case 't': - if (util::streq("accep", name, 5)) { - return HD_ACCEPT; - } if (util::streq("expec", name, 5)) { return HD_EXPECT; } @@ -508,9 +505,6 @@ int lookup_token(const uint8_t *name, size_t namelen) { } break; case 'r': - if (util::streq("refere", name, 6)) { - return HD_REFERER; - } if (util::streq("traile", name, 6)) { return HD_TRAILER; } @@ -543,6 +537,11 @@ int lookup_token(const uint8_t *name, size_t namelen) { return HD_CONNECTION; } break; + case 't': + if (util::streq("user-agen", name, 9)) { + return HD_USER_AGENT; + } + break; case 'y': if (util::streq(":authorit", name, 9)) { return HD__AUTHORITY; @@ -550,6 +549,15 @@ int lookup_token(const uint8_t *name, size_t namelen) { break; } break; + case 13: + switch (name[namelen - 1]) { + case 'l': + if (util::streq("cache-contro", name, 12)) { + return HD_CACHE_CONTROL; + } + break; + } + break; case 14: switch (name[namelen - 1]) { case 'h': @@ -566,6 +574,16 @@ int lookup_token(const uint8_t *name, size_t namelen) { break; case 15: switch (name[namelen - 1]) { + case 'e': + if (util::streq("accept-languag", name, 14)) { + return HD_ACCEPT_LANGUAGE; + } + break; + case 'g': + if (util::streq("accept-encodin", name, 14)) { + return HD_ACCEPT_ENCODING; + } + break; case 'r': if (util::streq("x-forwarded-fo", name, 14)) { return HD_X_FORWARDED_FOR; diff --git a/src/http2.h b/src/http2.h index f9d9d68e..26f0a154 100644 --- a/src/http2.h +++ b/src/http2.h @@ -195,8 +195,10 @@ enum { HD__PATH, HD__SCHEME, HD__STATUS, - HD_ACCEPT, + HD_ACCEPT_ENCODING, + HD_ACCEPT_LANGUAGE, HD_ALT_SVC, + HD_CACHE_CONTROL, HD_CONNECTION, HD_CONTENT_LENGTH, HD_COOKIE, @@ -208,12 +210,12 @@ enum { HD_LINK, HD_LOCATION, HD_PROXY_CONNECTION, - HD_REFERER, HD_SERVER, HD_TE, HD_TRAILER, HD_TRANSFER_ENCODING, HD_UPGRADE, + HD_USER_AGENT, HD_VIA, HD_X_FORWARDED_FOR, HD_X_FORWARDED_PROTO, diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index c100266e..76f9972c 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -568,6 +568,9 @@ int on_frame_send_callback(nghttp2_session *session, const nghttp2_frame *frame, downstream->set_request_path({nv.value, nv.value + nv.valuelen}); break; } + downstream->add_request_header(nv.name, nv.namelen, nv.value, nv.valuelen, + nv.flags & NGHTTP2_NV_FLAG_NO_INDEX, + token); } downstream->inspect_http2_request(); @@ -1588,6 +1591,16 @@ int Http2Upstream::submit_push_promise(const std::string &path, nva.reserve(downstream->get_request_headers().size()); for (auto &kv : downstream->get_request_headers()) { switch (kv.token) { + // TODO generate referer + case http2::HD__AUTHORITY: + case http2::HD__SCHEME: + case http2::HD_ACCEPT_ENCODING: + case http2::HD_ACCEPT_LANGUAGE: + case http2::HD_CACHE_CONTROL: + case http2::HD_HOST: + case http2::HD_USER_AGENT: + nva.push_back(http2::make_nv(kv.name, kv.value, kv.no_index)); + break; case http2::HD__METHOD: // juse use "GET" for now nva.push_back(http2::make_nv_lc(":method", "GET")); @@ -1595,15 +1608,7 @@ int Http2Upstream::submit_push_promise(const std::string &path, case http2::HD__PATH: nva.push_back(http2::make_nv_ls(":path", path)); continue; - case http2::HD_ACCEPT: - // browser tends to change accept header field value depending - // on requesting resource. So just omit it for now. - continue; - case http2::HD_REFERER: - // TODO construct referer - continue; } - nva.push_back(http2::make_nv(kv.name, kv.value, kv.no_index)); } rv = nghttp2_submit_push_promise(session_, NGHTTP2_FLAG_NONE,