Merge branch 'master' into nghttpx-mruby

This commit is contained in:
Tatsuhiro Tsujikawa 2015-09-05 19:04:04 +09:00
commit 77958eab46
3 changed files with 35 additions and 19 deletions

View File

@ -59,17 +59,12 @@ header field to initiate server push:
Link: </fonts/font.woff>; rel=preload
Link: </css/theme.css>; rel=preload
Currently, the following restrictions are applied for server push:
Currently, the following restriction is applied for server push:
1. URI-reference must not contain authority. If it exists, it is not
pushed. ``/fonts/font.woff`` and ``css/theme.css`` are eligible to
be pushed. ``https://example.org/fonts/font.woff`` and
``//example.org/css/theme.css`` are not.
2. The associated stream must have method "GET" or "POST". The
1. The associated stream must have method "GET" or "POST". The
associated stream's status code must be 200.
These limitations may be loosened in the future release.
This limitation may be loosened in the future release.
UNIX DOMAIN SOCKET
------------------

View File

@ -1395,6 +1395,8 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream) {
// don't want to push for HEAD request. Not sure other methods
// are also eligible for push.
if (!get_config()->no_server_push &&
nghttp2_session_get_remote_settings(session_,
NGHTTP2_SETTINGS_ENABLE_PUSH) == 1 &&
get_config()->downstream_proto == PROTO_HTTP &&
!get_config()->http2_proxy && (downstream->get_stream_id() % 2) &&
downstream->get_response_header(http2::HD_LINK) &&
@ -1610,6 +1612,7 @@ int Http2Upstream::prepare_push_promise(Downstream *downstream) {
const char *relq = nullptr;
size_t relqlen = 0;
std::string authority, scheme;
http_parser_url v{};
rv = http_parser_parse_url(link_url, link_urllen, 0, &v);
if (rv != 0) {
@ -1627,9 +1630,18 @@ int Http2Upstream::prepare_push_promise(Downstream *downstream) {
relqlen = end - relq;
}
} else {
if (v.field_set & (1 << UF_HOST)) {
continue;
if (v.field_set & (1 << UF_SCHEMA)) {
http2::copy_url_component(scheme, &v, UF_SCHEMA, link_url);
}
if (v.field_set & (1 << UF_HOST)) {
http2::copy_url_component(authority, &v, UF_HOST, link_url);
if (v.field_set & (1 << UF_PORT)) {
authority += ":";
authority += util::utos(v.port);
}
}
if (v.field_set & (1 << UF_PATH)) {
auto &f = v.field_data[UF_PATH];
rel = link_url + f.off;
@ -1645,9 +1657,18 @@ int Http2Upstream::prepare_push_promise(Downstream *downstream) {
relqlen = f.len;
}
}
if (scheme.empty()) {
scheme = downstream->get_request_http2_scheme();
}
if (authority.empty()) {
authority = downstream->get_request_http2_authority();
}
auto path = http2::path_join(base, baselen, nullptr, 0, rel, rellen, relq,
relqlen);
rv = submit_push_promise(path, downstream);
rv = submit_push_promise(scheme, authority, path, downstream);
if (rv != 0) {
return -1;
}
@ -1656,7 +1677,9 @@ int Http2Upstream::prepare_push_promise(Downstream *downstream) {
return 0;
}
int Http2Upstream::submit_push_promise(const std::string &path,
int Http2Upstream::submit_push_promise(const std::string &scheme,
const std::string &authority,
const std::string &path,
Downstream *downstream) {
int rv;
std::vector<nghttp2_nv> nva;
@ -1664,13 +1687,9 @@ int Http2Upstream::submit_push_promise(const std::string &path,
// juse use "GET" for now
nva.push_back(http2::make_nv_ll(":method", "GET"));
nva.push_back(
http2::make_nv_ls(":scheme", downstream->get_request_http2_scheme()));
nva.push_back(http2::make_nv_ls(":scheme", scheme));
nva.push_back(http2::make_nv_ls(":path", path));
auto &authority = downstream->get_request_http2_authority();
if (!authority.empty()) {
nva.push_back(http2::make_nv_ls(":authority", authority));
}
nva.push_back(http2::make_nv_ls(":authority", authority));
for (auto &kv : downstream->get_request_headers()) {
switch (kv.token) {

View File

@ -98,7 +98,9 @@ public:
void check_shutdown();
int prepare_push_promise(Downstream *downstream);
int submit_push_promise(const std::string &path, Downstream *downstream);
int submit_push_promise(const std::string &scheme,
const std::string &authority, const std::string &path,
Downstream *downstream);
int on_request_headers(Downstream *downstream, const nghttp2_frame *frame);