src/ngx_pagespeed.cc
// There are many sources of options:
//  - the request (query parameters, headers, and cookies)
//  - location block
//  - global server options
//  - experiment framework
// Consider them all, returning appropriate options for this request, of which
// the caller takes ownership.  If the only applicable options are global,
// set options to NULL so we can use server_context->global_options().
There are many sources of options:
the request (query parameters, headers, and cookies)
location block
global server options
experiment framework
Consider them all, returning appropriate options for this request, of which
the caller takes ownership.  If the only applicable options are global,
set options to NULL so we can use server_context->global_options().
There are many sources of options : the request ( query parameters headers and cookies ) location block global server options experiment framework Consider them all returning appropriate options for this request of which the caller takes ownership . If the only applicable options are global set options to NULL so we can use server_context - > global_options () .
bool ps_determine_options(ngx_http_request_t* r,
                          RequestHeaders* request_headers,
                          ResponseHeaders* response_headers,
                          RewriteOptions** options,
                          RequestContextPtr request_context,
                          ps_srv_conf_t* cfg_s,
                          GoogleUrl* url,
                          GoogleString* pagespeed_query_params,
                          GoogleString* pagespeed_option_cookies,
                          bool html_rewrite) {
  ps_loc_conf_t* cfg_l = ps_get_loc_config(r);
  RewriteOptions* global_options = cfg_s->server_context->global_options();
  RewriteOptions* directory_options = cfg_l->options;
  RewriteOptions* request_options = ps_determine_request_options(
      r, directory_options, request_headers, response_headers, request_context,
      cfg_s, url, pagespeed_query_params, pagespeed_option_cookies);
  bool have_request_options = request_options != NULL;
  NgxRewriteOptions* ngx_global_options =
      dynamic_cast<NgxRewriteOptions*>(global_options);
  if (!have_request_options && directory_options == NULL &&
      !global_options->running_experiment() &&
      ngx_global_options->script_lines().size() == 0) {
    return true;
  }
  if (directory_options != NULL) {
    if (*options != NULL) {
      (*options)->Merge(*directory_options);
    } else {
      *options = directory_options->Clone();
    }
  } else {
    if (*options == NULL) {
      *options = global_options->Clone();
    }
  }
  NgxRewriteDriverFactory* ngx_factory =
      dynamic_cast<NgxRewriteDriverFactory*>(cfg_s->server_context->factory());
  NgxRewriteOptions* ngx_options = dynamic_cast<NgxRewriteOptions*>(*options);
  if (!ngx_options->ExecuteScriptVariables(r, cfg_s->handler, ngx_factory)) {
    return false;
  }
  if (have_request_options) {
    (*options)->Merge(*request_options);
    delete request_options;
    request_options = NULL;
  }
  if ((*options)->running_experiment() &&
      html_rewrite &&
      (!have_request_options ||
       (*options)->enroll_experiment())) {
    bool ok = ps_set_experiment_state_and_cookie(
        r, request_headers, *options, url->Host());
    if (!ok) {
      delete *options;
      *options = NULL;
      return false;
    }
  }
  return true;
}
bool ps_determine_options ( ngx_http_request_t * r , RequestHeaders * request_headers , ResponseHeaders * response_headers , RewriteOptions * * options , RequestContextPtr request_context , ps_srv_conf_t * cfg_s , GoogleUrl * url , GoogleString * pagespeed_query_params , GoogleString * pagespeed_option_cookies , bool html_rewrite ) { ps_loc_conf_t * cfg_l = ps_get_loc_config ( r ) ; RewriteOptions * global_options = cfg_s -> server_context -> global_options ( ) ; RewriteOptions * directory_options = cfg_l -> options ; RewriteOptions * request_options = ps_determine_request_options ( r , directory_options , request_headers , response_headers , request_context , cfg_s , url , pagespeed_query_params , pagespeed_option_cookies ) ; bool have_request_options = request_options != NULL ; NgxRewriteOptions * ngx_global_options = dynamic_cast < NgxRewriteOptions * > ( global_options ) ; if ( ! have_request_options && directory_options == NULL && ! global_options -> running_experiment ( ) && ngx_global_options -> script_lines ( ) . size ( ) == 0 ) { return true ; } if ( directory_options != NULL ) { if ( * options != NULL ) { ( * options ) -> Merge ( * directory_options ) ; } else { * options = directory_options -> Clone ( ) ; } } else { if ( * options == NULL ) { * options = global_options -> Clone ( ) ; } } NgxRewriteDriverFactory * ngx_factory = dynamic_cast < NgxRewriteDriverFactory * > ( cfg_s -> server_context -> factory ( ) ) ; NgxRewriteOptions * ngx_options = dynamic_cast < NgxRewriteOptions * > ( * options ) ; if ( ! ngx_options -> ExecuteScriptVariables ( r , cfg_s -> handler , ngx_factory ) ) { return false ; } if ( have_request_options ) { ( * options ) -> Merge ( * request_options ) ; delete request_options ; request_options = NULL ; } if ( ( * options ) -> running_experiment ( ) && html_rewrite && ( ! have_request_options || ( * options ) -> enroll_experiment ( ) ) ) { bool ok = ps_set_experiment_state_and_cookie ( r , request_headers , * options , url -> Host ( ) ) ; if ( ! ok ) { delete * options ; * options = NULL ; return false ; } } return true ; }
There are many sources of options:
 the request (query parameters, headers, and cookies)
 location block
 global server options
 experiment framework
Consider them all, returning appropriate options for this request, of which
the caller takes ownership.
There are many sources of options : the request ( query parameters headers and cookies ) location block global server options experiment framework Consider them all returning appropriate options for this request of which the caller takes ownership .
// Global options for this server.  Never null. // Directory-specific options, usually null.  They've already been rebased off // of the global options as part of the configuration process. // Request-specific options, nearly always null.  If set they need to be // rebased on the directory options or the global options. // Because the caller takes ownership of any options we return, the only // situation in which we can avoid allocating a new RewriteOptions is if the // global options are ok as they are and we don't have script variables we // need to evaluate at this point. // Start with directory options if we have them, otherwise request options. // ExecuteScriptVariables() sets 'pagespeed off' on ngx_options when execution // fails and then returns false. When that happens we return, as we don't want // to allow enabling pagespeed by request and execute without the intended // configuration. // Modify our options in response to request options if specified. // If we're running an experiment and processing html then modify our options // in response to the experiment.  Except we generally don't want experiments // to be contaminated with unexpected settings, so ignore experiments if we // have request-specific options.  Unless EnrollExperiment is on, probably set // by a query parameter, in which case we want to go ahead and apply the // experimental settings even if it means bad data, because we're just seeing // what it looks like.