nghttpx: Reworkd inherited request headers in PUSH_PROMISE

This commit is contained in:
Tatsuhiro Tsujikawa 2015-02-08 14:23:22 +09:00
parent b14cfaf308
commit 88f0bc70c4
4 changed files with 45 additions and 18 deletions

View File

@ -21,9 +21,11 @@ HEADERS = [
"content-length", "content-length",
"location", "location",
"trailer", "trailer",
"referer",
"link", "link",
"accept", "accept-encoding",
"accept-language",
"cache-control",
"user-agent",
# disallowed h1 headers # disallowed h1 headers
'connection', 'connection',
'keep-alive', 'keep-alive',

View File

@ -478,9 +478,6 @@ int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 't': case 't':
if (util::streq("accep", name, 5)) {
return HD_ACCEPT;
}
if (util::streq("expec", name, 5)) { if (util::streq("expec", name, 5)) {
return HD_EXPECT; return HD_EXPECT;
} }
@ -508,9 +505,6 @@ int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 'r': case 'r':
if (util::streq("refere", name, 6)) {
return HD_REFERER;
}
if (util::streq("traile", name, 6)) { if (util::streq("traile", name, 6)) {
return HD_TRAILER; return HD_TRAILER;
} }
@ -543,6 +537,11 @@ int lookup_token(const uint8_t *name, size_t namelen) {
return HD_CONNECTION; return HD_CONNECTION;
} }
break; break;
case 't':
if (util::streq("user-agen", name, 9)) {
return HD_USER_AGENT;
}
break;
case 'y': case 'y':
if (util::streq(":authorit", name, 9)) { if (util::streq(":authorit", name, 9)) {
return HD__AUTHORITY; return HD__AUTHORITY;
@ -550,6 +549,15 @@ int lookup_token(const uint8_t *name, size_t namelen) {
break; break;
} }
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: case 14:
switch (name[namelen - 1]) { switch (name[namelen - 1]) {
case 'h': case 'h':
@ -566,6 +574,16 @@ int lookup_token(const uint8_t *name, size_t namelen) {
break; break;
case 15: case 15:
switch (name[namelen - 1]) { 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': case 'r':
if (util::streq("x-forwarded-fo", name, 14)) { if (util::streq("x-forwarded-fo", name, 14)) {
return HD_X_FORWARDED_FOR; return HD_X_FORWARDED_FOR;

View File

@ -195,8 +195,10 @@ enum {
HD__PATH, HD__PATH,
HD__SCHEME, HD__SCHEME,
HD__STATUS, HD__STATUS,
HD_ACCEPT, HD_ACCEPT_ENCODING,
HD_ACCEPT_LANGUAGE,
HD_ALT_SVC, HD_ALT_SVC,
HD_CACHE_CONTROL,
HD_CONNECTION, HD_CONNECTION,
HD_CONTENT_LENGTH, HD_CONTENT_LENGTH,
HD_COOKIE, HD_COOKIE,
@ -208,12 +210,12 @@ enum {
HD_LINK, HD_LINK,
HD_LOCATION, HD_LOCATION,
HD_PROXY_CONNECTION, HD_PROXY_CONNECTION,
HD_REFERER,
HD_SERVER, HD_SERVER,
HD_TE, HD_TE,
HD_TRAILER, HD_TRAILER,
HD_TRANSFER_ENCODING, HD_TRANSFER_ENCODING,
HD_UPGRADE, HD_UPGRADE,
HD_USER_AGENT,
HD_VIA, HD_VIA,
HD_X_FORWARDED_FOR, HD_X_FORWARDED_FOR,
HD_X_FORWARDED_PROTO, HD_X_FORWARDED_PROTO,

View File

@ -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}); downstream->set_request_path({nv.value, nv.value + nv.valuelen});
break; 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(); downstream->inspect_http2_request();
@ -1588,6 +1591,16 @@ int Http2Upstream::submit_push_promise(const std::string &path,
nva.reserve(downstream->get_request_headers().size()); nva.reserve(downstream->get_request_headers().size());
for (auto &kv : downstream->get_request_headers()) { for (auto &kv : downstream->get_request_headers()) {
switch (kv.token) { 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: case http2::HD__METHOD:
// juse use "GET" for now // juse use "GET" for now
nva.push_back(http2::make_nv_lc(":method", "GET")); 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: case http2::HD__PATH:
nva.push_back(http2::make_nv_ls(":path", path)); nva.push_back(http2::make_nv_ls(":path", path));
continue; 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, rv = nghttp2_submit_push_promise(session_, NGHTTP2_FLAG_NONE,