src/ngx_pagespeed.cc
// Called exactly once per server block to merge the main configuration with the
// configuration for this server.
Called exactly once per server block to merge the main configuration with the
configuration for this server.
Called exactly once per server block to merge the main configuration with the configuration for this server .
char* ps_merge_srv_conf(ngx_conf_t* cf, void* parent, void* child) {
  times_ps_merge_srv_conf_called += 1;
  ps_srv_conf_t* parent_cfg_s = static_cast<ps_srv_conf_t*>(parent);
  ps_srv_conf_t* cfg_s = static_cast<ps_srv_conf_t*>(child);
  ps_merge_options(parent_cfg_s->options, &cfg_s->options);
  if (cfg_s->options == NULL) {
    return NGX_CONF_OK;  
  }
  int dummy_port = -times_ps_merge_srv_conf_called;
  ps_main_conf_t* cfg_m = static_cast<ps_main_conf_t*>(
      ngx_http_conf_get_module_main_conf(cf, ngx_pagespeed));
  cfg_m->driver_factory->SetMainConf(parent_cfg_s->options);
  cfg_s->server_context = cfg_m->driver_factory->MakeNgxServerContext(
      "dummy_hostname", dummy_port);
#if (NGX_HTTP_V2)
  ngx_str_t name = ngx_string("http2");
  cfg_s->server_context->set_ngx_http2_variable_index(
      ngx_http_get_variable_index(cf, &name));
#endif
  cfg_s->server_context->global_options()->Merge(*cfg_s->options);
  NgxRewriteOptions* ngx_options = dynamic_cast<NgxRewriteOptions*>(
      cfg_s->server_context->global_options());
  cfg_s->options->CopyScriptLinesTo(ngx_options);
  delete cfg_s->options;
  cfg_s->options = NULL;
  if (!cfg_s->server_context->global_options()->unplugged()) {
    GoogleMessageHandler handler;
    const char* file_cache_path =
        cfg_s->server_context->config()->file_cache_path().c_str();
    if (file_cache_path[0] == '\0') {
      if (!cfg_s->server_context->global_options()->standby()) {
        return const_cast<char*>("FileCachePath must be set, even for standby");
      } else {
        return const_cast<char*>("FileCachePath must be set");
      }
    } else if (!cfg_m->driver_factory->file_system()->IsDir(
        file_cache_path, &handler).is_true()) {
      return const_cast<char*>(
          "FileCachePath must be an nginx-writeable directory");
    }
  }
  return NGX_CONF_OK;
}
char * ps_merge_srv_conf ( ngx_conf_t * cf , void * parent , void * child ) { times_ps_merge_srv_conf_called += 1 ; ps_srv_conf_t * parent_cfg_s = static_cast < ps_srv_conf_t * > ( parent ) ; ps_srv_conf_t * cfg_s = static_cast < ps_srv_conf_t * > ( child ) ; ps_merge_options ( parent_cfg_s -> options , & cfg_s -> options ) ; if ( cfg_s -> options == NULL ) { return NGX_CONF_OK ; } int dummy_port = - times_ps_merge_srv_conf_called ; ps_main_conf_t * cfg_m = static_cast < ps_main_conf_t * > ( ngx_http_conf_get_module_main_conf ( cf , ngx_pagespeed ) ) ; cfg_m -> driver_factory -> SetMainConf ( parent_cfg_s -> options ) ; cfg_s -> server_context = cfg_m -> driver_factory -> MakeNgxServerContext ( " " , dummy_port ) ; #if ( NGX_HTTP_V2 ) ngx_str_t name = ngx_string ( " " ) ; cfg_s -> server_context -> set_ngx_http2_variable_index ( ngx_http_get_variable_index ( cf , & name ) ) ; #endif cfg_s -> server_context -> global_options ( ) -> Merge ( * cfg_s -> options ) ; NgxRewriteOptions * ngx_options = dynamic_cast < NgxRewriteOptions * > ( cfg_s -> server_context -> global_options ( ) ) ; cfg_s -> options -> CopyScriptLinesTo ( ngx_options ) ; delete cfg_s -> options ; cfg_s -> options = NULL ; if ( ! cfg_s -> server_context -> global_options ( ) -> unplugged ( ) ) { GoogleMessageHandler handler ; const char * file_cache_path = cfg_s -> server_context -> config ( ) -> file_cache_path ( ) . c_str ( ) ; if ( file_cache_path [ 0 ] == ' \0 ' ) { if ( ! cfg_s -> server_context -> global_options ( ) -> standby ( ) ) { return const_cast < char * > ( " " ) ; } else { return const_cast < char * > ( " " ) ; } } else if ( ! cfg_m -> driver_factory -> file_system ( ) -> IsDir ( file_cache_path , & handler ) . is_true ( ) ) { return const_cast < char * > ( " " ) ; } } return NGX_CONF_OK ; }
Called exactly once per server block to merge the main configuration with the
configuration for this server.
Called exactly once per server block to merge the main configuration with the configuration for this server .
// No pagespeed options; don't do anything. // ServerContext needs a hostname and port, but I don't see how to get this // and it ignores that a server can have multiple names and ports.  Because // the server context only needs them to make a unique identifier and to make // debugging easier, substitute our own unique identifier. // TODO(jefftk): either figure out how to get a hostname and port for this // server block or change ServerContext not to ask for them. // 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. // 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. // Once we do that we're done with cfg_s->options. // Validate FileCachePath