Merge pull request #1076 from pagespeed/morlovich-h2-bit

Store whether h2 is in use in RequestContext.
This commit is contained in:
Maks Orlovich
2016-01-05 12:35:51 -05:00
3 changed files with 40 additions and 6 deletions
+11
View File
@@ -1086,6 +1086,17 @@ char* ps_merge_srv_conf(ngx_conf_t* cf, void* parent, void* child) {
cfg_m->driver_factory->set_main_conf(parent_cfg_s->options); cfg_m->driver_factory->set_main_conf(parent_cfg_s->options);
cfg_s->server_context = cfg_m->driver_factory->MakeNgxServerContext( cfg_s->server_context = cfg_m->driver_factory->MakeNgxServerContext(
"dummy_hostname", dummy_port); "dummy_hostname", dummy_port);
#if (NGX_HTTP_V2)
// Save the variable index of the "http2" variable, so we can use it
// at request time to lookup whether that's on. We do this conditionally
// since NGINX will complain to the user (at [emerg] level!) if it doesn't
// know about it.
ngx_str_t name = ngx_string("http2");
cfg_s->server_context->set_ngx_http2_variable_index(
ngx_http_get_variable_index(cf, &name));
#endif
// The server context sets some options when we call global_options(). So // The server context sets some options when we call global_options(). So
// let it do that, then merge in options we got from the config file. // let it do that, then merge in options we got from the config file.
// Once we do that we're done with cfg_s->options. // Once we do that we're done with cfg_s->options.
+19 -6
View File
@@ -35,7 +35,8 @@ namespace net_instaweb {
NgxServerContext::NgxServerContext( NgxServerContext::NgxServerContext(
NgxRewriteDriverFactory* factory, StringPiece hostname, int port) NgxRewriteDriverFactory* factory, StringPiece hostname, int port)
: SystemServerContext(factory, hostname, port) { : SystemServerContext(factory, hostname, port),
ngx_http2_variable_index_(NGX_ERROR) {
} }
NgxServerContext::~NgxServerContext() { } NgxServerContext::~NgxServerContext() { }
@@ -70,11 +71,23 @@ SystemRequestContext* NgxServerContext::NewRequestContext(
local_ip.len = 0; local_ip.len = 0;
} }
return new SystemRequestContext(thread_system()->NewMutex(), SystemRequestContext* ctx = new SystemRequestContext(
timer(), thread_system()->NewMutex(), timer(),
ps_determine_host(r), ps_determine_host(r), local_port, str_to_string_piece(local_ip));
local_port,
str_to_string_piece(local_ip)); // See if http2 is in use.
if (ngx_http2_variable_index_ >= 0) {
ngx_http_variable_value_t* val =
ngx_http_get_indexed_variable(r, ngx_http2_variable_index_);
if (val != NULL && val->valid) {
StringPiece str_val(reinterpret_cast<char*>(val->data), val->len);
if (str_val == "h2" || str_val == "h2c") {
ctx->set_using_http2(true);
}
}
}
return ctx;
} }
GoogleString NgxServerContext::FormatOption(StringPiece option_name, GoogleString NgxServerContext::FormatOption(StringPiece option_name,
+10
View File
@@ -58,8 +58,18 @@ class NgxServerContext : public SystemServerContext {
virtual GoogleString FormatOption(StringPiece option_name, StringPiece args); virtual GoogleString FormatOption(StringPiece option_name, StringPiece args);
void set_ngx_http2_variable_index(ngx_int_t idx) {
ngx_http2_variable_index_ = idx;
}
ngx_int_t ngx_http2_variable_index() const {
return ngx_http2_variable_index_;
}
private: private:
NgxRewriteDriverFactory* ngx_factory_; NgxRewriteDriverFactory* ngx_factory_;
// what index the "http2" var is, or NGX_ERROR.
ngx_int_t ngx_http2_variable_index_;
DISALLOW_COPY_AND_ASSIGN(NgxServerContext); DISALLOW_COPY_AND_ASSIGN(NgxServerContext);
}; };