src/ngx_pagespeed.cc
// Set us up for processing a request.  Creates a request context and determines
// which handler should deal with the request.
Set us up for processing a request.  Creates a request context and determines
which handler should deal with the request.
Set us up for processing a request . Creates a request context and determines which handler should deal with the request .
RequestRouting::Response ps_route_request(ngx_http_request_t* r) {
  ps_srv_conf_t* cfg_s = ps_get_srv_config(r);
  if (ps_disabled(cfg_s)) {
    return RequestRouting::kPagespeedDisabled;
  }
  if (ngx_terminate || ngx_exiting) {
    return RequestRouting::kError;
  }
  if (r->err_status != 0) {
    return RequestRouting::kErrorResponse;
  }
  GoogleString url_string = ps_determine_url(r);
  GoogleUrl url(url_string);
  if (!url.IsWebValid()) {
    ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "invalid url");
    return RequestRouting::kInvalidUrl;
  }
  if (is_pagespeed_subrequest(r)) {
    return RequestRouting::kPagespeedSubrequest;
  } else if (
      url.PathSansLeaf() == dynamic_cast<NgxRewriteDriverFactory*>(
          cfg_s->server_context->factory())->static_asset_prefix()) {
    return RequestRouting::kStaticContent;
  }
  const NgxRewriteOptions* global_options = cfg_s->server_context->config();
  StringPiece path = url.PathSansQuery();
  if (StringCaseEqual(path, global_options->statistics_path()) &&
      global_options->StatisticsAccessAllowed(url)) {
    return RequestRouting::kStatistics;
  } else if (StringCaseEqual(path, global_options->global_statistics_path()) &&
             global_options->GlobalStatisticsAccessAllowed(url)) {
    return RequestRouting::kGlobalStatistics;
  } else if (StringCaseEqual(path, global_options->console_path()) &&
             global_options->ConsoleAccessAllowed(url)) {
    return RequestRouting::kConsole;
  } else if (StringCaseEqual(path, global_options->messages_path()) &&
             global_options->MessagesAccessAllowed(url)) {
    return RequestRouting::kMessages;
  } else if (
      !global_options->admin_path().empty() &&
      StringCaseStartsWith(path, global_options->admin_path()) &&
      global_options->AdminAccessAllowed(url)) {
    return RequestRouting::kAdmin;
  } else if (!global_options->global_admin_path().empty() &&
             StringCaseStartsWith(path, global_options->global_admin_path()) &&
             global_options->GlobalAdminAccessAllowed(url)) {
    return RequestRouting::kGlobalAdmin;
  } else if (global_options->enable_cache_purge() &&
             !global_options->purge_method().empty() &&
             (global_options->purge_method() ==
              str_to_string_piece(r->method_name))) {
    return RequestRouting::kCachePurge;
  }
  const GoogleString* beacon_url;
  if (ps_is_https(r)) {
    beacon_url = &(global_options->beacon_url().https);
  } else {
    beacon_url = &(global_options->beacon_url().http);
  }
  if (url.PathSansQuery() == StringPiece(*beacon_url)) {
    return RequestRouting::kBeacon;
  }
  return RequestRouting::kResource;
}
RequestRouting :: Response ps_route_request ( ngx_http_request_t * r ) { ps_srv_conf_t * cfg_s = ps_get_srv_config ( r ) ; if ( ps_disabled ( cfg_s ) ) { return RequestRouting :: kPagespeedDisabled ; } if ( ngx_terminate || ngx_exiting ) { return RequestRouting :: kError ; } if ( r -> err_status != 0 ) { return RequestRouting :: kErrorResponse ; } GoogleString url_string = ps_determine_url ( r ) ; GoogleUrl url ( url_string ) ; if ( ! url . IsWebValid ( ) ) { ngx_log_error ( NGX_LOG_ERR , r -> connection -> log , 0 , " " ) ; return RequestRouting :: kInvalidUrl ; } if ( is_pagespeed_subrequest ( r ) ) { return RequestRouting :: kPagespeedSubrequest ; } else if ( url . PathSansLeaf ( ) == dynamic_cast < NgxRewriteDriverFactory * > ( cfg_s -> server_context -> factory ( ) ) -> static_asset_prefix ( ) ) { return RequestRouting :: kStaticContent ; } const NgxRewriteOptions * global_options = cfg_s -> server_context -> config ( ) ; StringPiece path = url . PathSansQuery ( ) ; if ( StringCaseEqual ( path , global_options -> statistics_path ( ) ) && global_options -> StatisticsAccessAllowed ( url ) ) { return RequestRouting :: kStatistics ; } else if ( StringCaseEqual ( path , global_options -> global_statistics_path ( ) ) && global_options -> GlobalStatisticsAccessAllowed ( url ) ) { return RequestRouting :: kGlobalStatistics ; } else if ( StringCaseEqual ( path , global_options -> console_path ( ) ) && global_options -> ConsoleAccessAllowed ( url ) ) { return RequestRouting :: kConsole ; } else if ( StringCaseEqual ( path , global_options -> messages_path ( ) ) && global_options -> MessagesAccessAllowed ( url ) ) { return RequestRouting :: kMessages ; } else if ( ! global_options -> admin_path ( ) . empty ( ) && StringCaseStartsWith ( path , global_options -> admin_path ( ) ) && global_options -> AdminAccessAllowed ( url ) ) { return RequestRouting :: kAdmin ; } else if ( ! global_options -> global_admin_path ( ) . empty ( ) && StringCaseStartsWith ( path , global_options -> global_admin_path ( ) ) && global_options -> GlobalAdminAccessAllowed ( url ) ) { return RequestRouting :: kGlobalAdmin ; } else if ( global_options -> enable_cache_purge ( ) && ! global_options -> purge_method ( ) . empty ( ) && ( global_options -> purge_method ( ) == str_to_string_piece ( r -> method_name ) ) ) { return RequestRouting :: kCachePurge ; } const GoogleString * beacon_url ; if ( ps_is_https ( r ) ) { beacon_url = & ( global_options -> beacon_url ( ) . https ) ; } else { beacon_url = & ( global_options -> beacon_url ( ) . http ) ; } if ( url . PathSansQuery ( ) == StringPiece ( * beacon_url ) ) { return RequestRouting :: kBeacon ; } return RequestRouting :: kResource ; }
Set us up for processing a request.
Set us up for processing a request .
// Not enabled for this server block. // Let nginx deal with the error however it wants; we will see a NULL ctx in // the body filter or content handler and do nothing. // The admin handlers get everything under a path (/path/*) while all the // other handlers only get exact matches (/path).  So match all paths // starting with the handler path.