cosmetic changes: alphabetization, spacing, indentation, type location

Merge of pull request #135
This commit is contained in:
Jeff Kaufman
2013-01-23 13:28:23 -05:00
parent 2056e919c4
commit 5363fe0c32
12 changed files with 145 additions and 210 deletions
+3 -1
View File
@@ -17,10 +17,12 @@
// Author: jefftk@google.com (Jeff Kaufman)
#include "ngx_base_fetch.h"
#include "ngx_pagespeed.h"
#include "net/instaweb/http/public/response_headers.h"
#include "net/instaweb/util/public/google_message_handler.h"
#include "net/instaweb/util/public/message_handler.h"
#include "net/instaweb/http/public/response_headers.h"
namespace net_instaweb {
+3 -2
View File
@@ -38,10 +38,11 @@
#define NGX_BASE_FETCH_H_
extern "C" {
#include <pthread.h>
#include <ngx_http.h>
}
#include <pthread.h>
#include "net/instaweb/http/public/async_fetch.h"
#include "net/instaweb/http/public/headers.h"
#include "net/instaweb/util/public/string.h"
@@ -121,6 +122,6 @@ class NgxBaseFetch : public AsyncFetch {
DISALLOW_COPY_AND_ASSIGN(NgxBaseFetch);
};
} // namespace net_instaweb
} // namespace net_instaweb
#endif // NGX_BASE_FETCH_H_
+1 -1
View File
@@ -51,7 +51,7 @@ NgxCache::NgxCache(const StringPiece& path,
} else {
FallBackToFileBasedLocking();
}
// TODO(jefftk): see the ngx_rewrite_options.h note on OriginRewriteOptions;
// this would move to OriginRewriteOptions.
FileCache::CachePolicy* policy = new FileCache::CachePolicy(
+4 -4
View File
@@ -23,13 +23,13 @@
namespace net_instaweb {
class NgxRewriteOptions;
class NgxRewriteDriverFactory;
class CacheInterface;
class FileCache;
class FileSystemLockManager;
class MessageHandler;
class NamedLockManager;
class NgxRewriteOptions;
class NgxRewriteDriverFactory;
class SharedMemLockManager;
// The NgxCache encapsulates a cache-sharing model where a user specifies
@@ -41,8 +41,8 @@ class NgxCache {
static const char kLruCache[];
NgxCache(const StringPiece& path,
const NgxRewriteOptions& config,
NgxRewriteDriverFactory* factory);
const NgxRewriteOptions& config,
NgxRewriteDriverFactory* factory);
~NgxCache();
CacheInterface* l1_cache() { return l1_cache_.get(); }
CacheInterface* l2_cache() { return l2_cache_.get(); }
+83 -151
View File
@@ -33,12 +33,13 @@ extern "C" {
#include <unistd.h>
#include "ngx_rewrite_driver_factory.h"
#include "ngx_server_context.h"
#include "ngx_rewrite_options.h"
#include "ngx_base_fetch.h"
#include "ngx_rewrite_driver_factory.h"
#include "ngx_rewrite_options.h"
#include "ngx_server_context.h"
#include "net/instaweb/automatic/public/proxy_fetch.h"
#include "net/instaweb/automatic/public/resource_fetch.h"
#include "net/instaweb/http/public/request_context.h"
#include "net/instaweb/rewriter/public/furious_matcher.h"
#include "net/instaweb/rewriter/public/process_context.h"
@@ -50,7 +51,6 @@ extern "C" {
#include "net/instaweb/util/public/google_message_handler.h"
#include "net/instaweb/util/public/google_url.h"
#include "net/instaweb/util/public/string.h"
#include "net/instaweb/automatic/public/resource_fetch.h"
extern ngx_module_t ngx_pagespeed;
@@ -64,13 +64,11 @@ extern ngx_module_t ngx_pagespeed;
namespace ngx_psol {
StringPiece
str_to_string_piece(ngx_str_t s) {
StringPiece str_to_string_piece(ngx_str_t s) {
return StringPiece(reinterpret_cast<char*>(s.data), s.len);
}
char*
string_piece_to_pool_string(ngx_pool_t* pool, StringPiece sp) {
char* string_piece_to_pool_string(ngx_pool_t* pool, StringPiece sp) {
// Need space for the final null.
ngx_uint_t buffer_size = sp.size() + 1;
char* s = static_cast<char*>(ngx_palloc(pool, buffer_size));
@@ -82,8 +80,7 @@ string_piece_to_pool_string(ngx_pool_t* pool, StringPiece sp) {
return s;
}
ngx_int_t
string_piece_to_buffer_chain(
ngx_int_t string_piece_to_buffer_chain(
ngx_pool_t* pool, StringPiece sp, ngx_chain_t** link_ptr,
bool send_last_buf) {
@@ -211,41 +208,29 @@ typedef struct {
bool write_pending;
} ps_request_ctx_t;
ngx_int_t
ps_body_filter(ngx_http_request_t* r, ngx_chain_t* in);
ngx_int_t ps_body_filter(ngx_http_request_t* r, ngx_chain_t* in);
void*
ps_create_srv_conf(ngx_conf_t* cf);
void* ps_create_srv_conf(ngx_conf_t* cf);
char*
ps_merge_srv_conf(ngx_conf_t* cf, void* parent, void* child);
char* ps_merge_srv_conf(ngx_conf_t* cf, void* parent, void* child);
char*
ps_merge_loc_conf(ngx_conf_t* cf, void* parent, void* child);
char* ps_merge_loc_conf(ngx_conf_t* cf, void* parent, void* child);
void
ps_release_request_context(void* data);
void ps_release_request_context(void* data);
void
ps_set_buffered(ngx_http_request_t* r, bool on);
void ps_set_buffered(ngx_http_request_t* r, bool on);
GoogleString
ps_determine_url(ngx_http_request_t* r);
GoogleString ps_determine_url(ngx_http_request_t* r);
ps_request_ctx_t*
ps_get_request_context(ngx_http_request_t* r);
ps_request_ctx_t* ps_get_request_context(ngx_http_request_t* r);
void
ps_initialize_server_context(ps_srv_conf_t* cfg);
void ps_initialize_server_context(ps_srv_conf_t* cfg);
ngx_int_t
ps_update(ps_request_ctx_t* ctx, ngx_event_t* ev);
ngx_int_t ps_update(ps_request_ctx_t* ctx, ngx_event_t* ev);
void
ps_connection_read_handler(ngx_event_t* ev);
void ps_connection_read_handler(ngx_event_t* ev);
ngx_int_t
ps_create_connection(ps_request_ctx_t* ctx);
ngx_int_t ps_create_connection(ps_request_ctx_t* ctx);
namespace CreateRequestContext {
enum Response {
@@ -256,34 +241,27 @@ enum Response {
kInvalidUrl,
kPagespeedDisabled,
};
} // namespace CreateRequestContext
} // namespace CreateRequestContext
CreateRequestContext::Response
ps_create_request_context(ngx_http_request_t* r, bool is_resource_fetch);
CreateRequestContext::Response ps_create_request_context(
ngx_http_request_t* r, bool is_resource_fetch);
void
ps_send_to_pagespeed(ngx_http_request_t* r,
ps_request_ctx_t* ctx,
ps_srv_conf_t* cfg_s,
ngx_chain_t* in);
void ps_send_to_pagespeed(ngx_http_request_t* r,
ps_request_ctx_t* ctx,
ps_srv_conf_t* cfg_s,
ngx_chain_t* in);
ngx_int_t
ps_body_filter(ngx_http_request_t* r, ngx_chain_t* in);
ngx_int_t ps_body_filter(ngx_http_request_t* r, ngx_chain_t* in);
ngx_int_t
ps_header_filter(ngx_http_request_t* r);
ngx_int_t ps_header_filter(ngx_http_request_t* r);
ngx_int_t
ps_init(ngx_conf_t* cf);
ngx_int_t ps_init(ngx_conf_t* cf);
char*
ps_srv_configure(ngx_conf_t* cf, ngx_command_t* cmd, void* conf);
char* ps_srv_configure(ngx_conf_t* cf, ngx_command_t* cmd, void* conf);
char*
ps_loc_configure(ngx_conf_t* cf, ngx_command_t* cmd, void* conf);
char* ps_loc_configure(ngx_conf_t* cf, ngx_command_t* cmd, void* conf);
void
ps_ignore_sigpipe();
void ps_ignore_sigpipe();
ngx_command_t ps_commands[] = {
{ ngx_string("pagespeed"),
@@ -305,21 +283,20 @@ ngx_command_t ps_commands[] = {
ngx_null_command
};
void
ps_ignore_sigpipe() {
void ps_ignore_sigpipe() {
struct sigaction act;
ngx_memzero(&act, sizeof(act));
act.sa_handler = SIG_IGN;
sigemptyset (&act.sa_mask);
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigaction (SIGPIPE, &act, NULL);
sigaction(SIGPIPE, &act, NULL);
}
#define NGX_PAGESPEED_MAX_ARGS 10
char*
ps_configure(ngx_conf_t* cf,
net_instaweb::NgxRewriteOptions** options,
net_instaweb::MessageHandler* handler) {
char* ps_configure(ngx_conf_t* cf,
net_instaweb::NgxRewriteOptions** options,
net_instaweb::MessageHandler* handler) {
if (*options == NULL) {
net_instaweb::NgxRewriteOptions::Initialize();
*options = new net_instaweb::NgxRewriteOptions();
@@ -346,15 +323,13 @@ ps_configure(ngx_conf_t* cf,
return const_cast<char*>(status);
}
char*
ps_srv_configure(ngx_conf_t* cf, ngx_command_t* cmd, void* conf) {
char* ps_srv_configure(ngx_conf_t* cf, ngx_command_t* cmd, void* conf) {
ps_srv_conf_t* cfg_s = static_cast<ps_srv_conf_t*>(
ngx_http_conf_get_module_srv_conf(cf, ngx_pagespeed));
return ps_configure(cf, &cfg_s->options, cfg_s->handler);
}
char*
ps_loc_configure(ngx_conf_t* cf, ngx_command_t* cmd, void* conf) {
char* ps_loc_configure(ngx_conf_t* cf, ngx_command_t* cmd, void* conf) {
ps_loc_conf_t* cfg_l = static_cast<ps_loc_conf_t*>(
ngx_http_conf_get_module_loc_conf(cf, ngx_pagespeed));
@@ -366,8 +341,7 @@ ps_loc_configure(ngx_conf_t* cf, ngx_command_t* cmd, void* conf) {
return ps_configure(cf, &cfg_l->options, cfg_l->handler);
}
void
ps_cleanup_loc_conf(void* data) {
void ps_cleanup_loc_conf(void* data) {
ps_loc_conf_t* cfg_l = static_cast<ps_loc_conf_t*>(data);
delete cfg_l->handler;
cfg_l->handler = NULL;
@@ -375,8 +349,7 @@ ps_cleanup_loc_conf(void* data) {
cfg_l->options = NULL;
}
void
ps_cleanup_srv_conf(void* data) {
void ps_cleanup_srv_conf(void* data) {
ps_srv_conf_t* cfg_s = static_cast<ps_srv_conf_t*>(data);
if (cfg_s->proxy_fetch_factory != NULL) {
delete cfg_s->proxy_fetch_factory;
@@ -388,8 +361,7 @@ ps_cleanup_srv_conf(void* data) {
cfg_s->options = NULL;
}
void
ps_cleanup_main_conf(void* data) {
void ps_cleanup_main_conf(void* data) {
ps_main_conf_t* cfg_m = static_cast<ps_main_conf_t*>(data);
if (cfg_m->driver_factory != NULL) {
delete cfg_m->driver_factory;
@@ -401,9 +373,7 @@ ps_cleanup_main_conf(void* data) {
net_instaweb::NgxRewriteOptions::Terminate();
}
template <typename ConfT>
ConfT*
ps_create_conf(ngx_conf_t* cf) {
template <typename ConfT> ConfT* ps_create_conf(ngx_conf_t* cf) {
ConfT* cfg = static_cast<ConfT*>(ngx_pcalloc(cf->pool, sizeof(ConfT)));
if (cfg == NULL) {
return NULL;
@@ -412,8 +382,8 @@ ps_create_conf(ngx_conf_t* cf) {
return cfg;
}
void
ps_set_conf_cleanup_handler(ngx_conf_t* cf, void (func)(void*), void* data) {
void ps_set_conf_cleanup_handler(
ngx_conf_t* cf, void (func)(void*), void* data) {
ngx_pool_cleanup_t* cleanup_m = ngx_pool_cleanup_add(cf->pool, 0);
if (cleanup_m == NULL) {
ngx_conf_log_error(
@@ -424,8 +394,7 @@ ps_set_conf_cleanup_handler(ngx_conf_t* cf, void (func)(void*), void* data) {
}
}
void*
ps_create_main_conf(ngx_conf_t* cf) {
void* ps_create_main_conf(ngx_conf_t* cf) {
ps_main_conf_t* cfg_m = ps_create_conf<ps_main_conf_t>(cf);
if (cfg_m == NULL) {
return NGX_CONF_ERROR;
@@ -434,8 +403,7 @@ ps_create_main_conf(ngx_conf_t* cf) {
return cfg_m;
}
void*
ps_create_srv_conf(ngx_conf_t* cf) {
void* ps_create_srv_conf(ngx_conf_t* cf) {
ps_srv_conf_t* cfg_s = ps_create_conf<ps_srv_conf_t>(cf);
if (cfg_s == NULL) {
return NGX_CONF_ERROR;
@@ -444,8 +412,7 @@ ps_create_srv_conf(ngx_conf_t* cf) {
return cfg_s;
}
void*
ps_create_loc_conf(ngx_conf_t* cf) {
void* ps_create_loc_conf(ngx_conf_t* cf) {
ps_loc_conf_t* cfg_l = ps_create_conf<ps_loc_conf_t>(cf);
if (cfg_l == NULL) {
return NGX_CONF_ERROR;
@@ -487,8 +454,7 @@ void ps_merge_options(net_instaweb::NgxRewriteOptions* parent_options,
// 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) {
char* ps_merge_srv_conf(ngx_conf_t* cf, void* parent, void* child) {
ps_srv_conf_t* parent_cfg_s =
static_cast<ps_srv_conf_t*>(parent);
ps_srv_conf_t* cfg_s =
@@ -548,8 +514,7 @@ ps_merge_srv_conf(ngx_conf_t* cf, void* parent, void* child) {
return NGX_CONF_OK;
}
char*
ps_merge_loc_conf(ngx_conf_t* cf, void* parent, void* child) {
char* ps_merge_loc_conf(ngx_conf_t* cf, void* parent, void* child) {
ps_loc_conf_t* parent_cfg_l = static_cast<ps_loc_conf_t*>(parent);
// The variant of the pagespeed directive that is acceptable in location
@@ -584,8 +549,7 @@ ps_merge_loc_conf(ngx_conf_t* cf, void* parent, void* child) {
ngx_http_output_header_filter_pt ngx_http_next_header_filter;
ngx_http_output_body_filter_pt ngx_http_next_body_filter;
void
ps_release_request_context(void* data) {
void ps_release_request_context(void* data) {
ps_request_ctx_t* ctx = static_cast<ps_request_ctx_t*>(data);
// proxy_fetch deleted itself if we called Done(), but if an error happened
@@ -622,8 +586,7 @@ ps_release_request_context(void* data) {
// Tell nginx whether we have network activity we're waiting for so that it sets
// a write handler. See src/http/ngx_http_request.c:2083.
void
ps_set_buffered(ngx_http_request_t* r, bool on) {
void ps_set_buffered(ngx_http_request_t* r, bool on) {
if (on) {
r->buffered |= NGX_HTTP_SSI_BUFFERED;
} else {
@@ -631,8 +594,7 @@ ps_set_buffered(ngx_http_request_t* r, bool on) {
}
}
GoogleString
ps_determine_url(ngx_http_request_t* r) {
GoogleString ps_determine_url(ngx_http_request_t* r) {
// Based on ngx_http_variable_scheme.
bool is_https = false;
#if (NGX_HTTP_SSL)
@@ -685,8 +647,7 @@ ps_determine_url(ngx_http_request_t* r) {
// Get the context for this request. ps_create_request_context
// should already have been called to create it.
ps_request_ctx_t*
ps_get_request_context(ngx_http_request_t* r) {
ps_request_ctx_t* ps_get_request_context(ngx_http_request_t* r) {
return static_cast<ps_request_ctx_t*>(
ngx_http_get_module_ctx(r, ngx_pagespeed));
}
@@ -695,8 +656,7 @@ ps_get_request_context(ngx_http_request_t* r) {
// NGX_OK: pagespeed is done, request complete
// NGX_AGAIN: pagespeed still working, needs to be called again later
// NGX_ERROR: error
ngx_int_t
ps_update(ps_request_ctx_t* ctx, ngx_event_t* ev) {
ngx_int_t ps_update(ps_request_ctx_t* ctx, ngx_event_t* ev) {
bool done;
int rc;
char chr;
@@ -762,9 +722,7 @@ ps_update(ps_request_ctx_t* ctx, ngx_event_t* ev) {
return done ? NGX_OK : NGX_AGAIN;
}
void
ps_writer(ngx_http_request_t* r)
{
void ps_writer(ngx_http_request_t* r) {
ngx_connection_t* c = r->connection;
ngx_event_t* wev = c->write;
@@ -782,33 +740,26 @@ ps_writer(ngx_http_request_t* r)
}
int rc = ngx_http_next_body_filter(r, NULL);
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http pagespeed writer output filter: %d, \"%V?%V\"",
rc, &r->uri, &r->args);
if (rc == NGX_AGAIN) {
return;
}
r->write_event_handler = ngx_http_request_empty_handler;
ngx_http_finalize_request(r, rc);
}
ngx_int_t
ngx_http_set_pagespeed_write_handler(ngx_http_request_t *r)
{
ngx_int_t ngx_http_set_pagespeed_write_handler(ngx_http_request_t *r) {
r->http_state = NGX_HTTP_WRITING_REQUEST_STATE;
r->read_event_handler = ngx_http_request_empty_handler;
r->write_event_handler = ps_writer;
ngx_event_t* wev = r->connection->write;
ngx_http_core_loc_conf_t* clcf = static_cast<ngx_http_core_loc_conf_t*>(
ngx_http_get_module_loc_conf(r, ngx_http_core_module));
ngx_add_timer(wev, clcf->send_timeout);
if (ngx_handle_write_event(wev, clcf->send_lowat) != NGX_OK) {
@@ -818,8 +769,7 @@ ngx_http_set_pagespeed_write_handler(ngx_http_request_t *r)
return NGX_OK;
}
void
ps_connection_read_handler(ngx_event_t* ev) {
void ps_connection_read_handler(ngx_event_t* ev) {
CHECK(ev != NULL);
ngx_connection_t* c = static_cast<ngx_connection_t*>(ev->data);
@@ -856,8 +806,7 @@ ps_connection_read_handler(ngx_event_t* ev) {
}
}
ngx_int_t
ps_create_connection(ps_request_ctx_t* ctx) {
ngx_int_t ps_create_connection(ps_request_ctx_t* ctx) {
ngx_connection_t* c = ngx_get_connection(
ctx->pipe_fd, ctx->r->connection->log);
if (c == NULL) {
@@ -886,25 +835,21 @@ ps_create_connection(ps_request_ctx_t* ctx) {
// Populate cfg_* with configuration information for this
// request. Thin wrappers around ngx_http_get_module_*_conf and cast.
ps_main_conf_t*
ps_get_main_config(ngx_http_request_t* r) {
ps_main_conf_t* ps_get_main_config(ngx_http_request_t* r) {
return static_cast<ps_main_conf_t*>(
ngx_http_get_module_main_conf(r, ngx_pagespeed));
}
ps_srv_conf_t*
ps_get_srv_config(ngx_http_request_t* r) {
ps_srv_conf_t* ps_get_srv_config(ngx_http_request_t* r) {
return static_cast<ps_srv_conf_t*>(
ngx_http_get_module_srv_conf(r, ngx_pagespeed));
}
ps_loc_conf_t*
ps_get_loc_config(ngx_http_request_t* r) {
ps_loc_conf_t* ps_get_loc_config(ngx_http_request_t* r) {
return static_cast<ps_loc_conf_t*>(
ngx_http_get_module_loc_conf(r, ngx_pagespeed));
}
// Wrapper around GetQueryOptions()
bool
ps_determine_request_options(
bool ps_determine_request_options(
ngx_http_request_t* r,
ps_request_ctx_t* ctx,
ps_srv_conf_t* cfg_s,
@@ -942,12 +887,10 @@ ps_determine_request_options(
// 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,
ps_request_ctx_t* ctx,
net_instaweb::RewriteOptions** options,
net_instaweb::GoogleUrl* url) {
bool ps_determine_options(ngx_http_request_t* r,
ps_request_ctx_t* ctx,
net_instaweb::RewriteOptions** options,
net_instaweb::GoogleUrl* url) {
ps_srv_conf_t* cfg_s = ps_get_srv_config(r);
ps_loc_conf_t* cfg_l = ps_get_loc_config(r);
@@ -1002,8 +945,8 @@ ps_determine_options(ngx_http_request_t* r,
// Set us up for processing a request.
CreateRequestContext::Response
ps_create_request_context(ngx_http_request_t* r, bool is_resource_fetch) {
CreateRequestContext::Response ps_create_request_context(
ngx_http_request_t* r, bool is_resource_fetch) {
ps_srv_conf_t* cfg_s = ps_get_srv_config(r);
GoogleString url_string = ps_determine_url(r);
@@ -1148,11 +1091,10 @@ ps_create_request_context(ngx_http_request_t* r, bool is_resource_fetch) {
// Send each buffer in the chain to the proxy_fetch for optimization.
// Eventually it will make it's way, optimized, to base_fetch.
void
ps_send_to_pagespeed(ngx_http_request_t* r,
ps_request_ctx_t* ctx,
ps_srv_conf_t* cfg_s,
ngx_chain_t* in) {
void ps_send_to_pagespeed(ngx_http_request_t* r,
ps_request_ctx_t* ctx,
ps_srv_conf_t* cfg_s,
ngx_chain_t* in) {
ngx_chain_t* cur;
int last_buf = 0;
for (cur = in; cur != NULL; cur = cur->next) {
@@ -1181,8 +1123,7 @@ ps_send_to_pagespeed(ngx_http_request_t* r,
}
}
ngx_int_t
ps_body_filter(ngx_http_request_t* r, ngx_chain_t* in) {
ngx_int_t ps_body_filter(ngx_http_request_t* r, ngx_chain_t* in) {
ps_srv_conf_t* cfg_s = ps_get_srv_config(r);
if (cfg_s->server_context == NULL) {
// Pagespeed is on for some server block but not this one.
@@ -1233,8 +1174,7 @@ ps_body_filter(ngx_http_request_t* r, ngx_chain_t* in) {
#endif
// Based on ngx_http_add_cache_control.
ngx_int_t
ps_set_cache_control(ngx_http_request_t* r, char* cache_control) {
ngx_int_t ps_set_cache_control(ngx_http_request_t* r, char* cache_control) {
if (r->headers_out.cache_control.elts == NULL) {
ngx_int_t rc = ngx_array_init(&r->headers_out.cache_control, r->pool,
1, sizeof(ngx_table_elt_t *));
@@ -1261,8 +1201,7 @@ ps_set_cache_control(ngx_http_request_t* r, char* cache_control) {
return NGX_OK;
}
void
ps_strip_html_headers(ngx_http_request_t* r) {
void ps_strip_html_headers(ngx_http_request_t* r) {
// We're modifying content, so switch to 'Transfer-Encoding: chunked' and
// calculate on the fly.
ngx_http_clear_content_length(r);
@@ -1305,10 +1244,7 @@ ps_strip_html_headers(ngx_http_request_t* r) {
}
}
ngx_int_t
ps_header_filter(ngx_http_request_t* r) {
ngx_int_t ps_header_filter(ngx_http_request_t* r) {
ps_srv_conf_t* cfg_s = ps_get_srv_config(r);
if (cfg_s->server_context == NULL) {
// Pagespeed is on for some server block but not this one.
@@ -1386,8 +1322,7 @@ ps_header_filter(ngx_http_request_t* r) {
return ngx_http_next_header_filter(r);
}
ngx_int_t
ps_static_handler(ngx_http_request_t* r) {
ngx_int_t ps_static_handler(ngx_http_request_t* r) {
ps_srv_conf_t* cfg_s = ps_get_srv_config(r);
StringPiece request_uri_path = str_to_string_piece(r->uri);
@@ -1438,8 +1373,7 @@ ps_static_handler(ngx_http_request_t* r) {
// Handle requests for resources like example.css.pagespeed.ce.LyfcM6Wulf.css
// and for static content like /ngx_pagespeed_static/js_defer.q1EBmcgYOC.js
ngx_int_t
ps_content_handler(ngx_http_request_t* r) {
ngx_int_t ps_content_handler(ngx_http_request_t* r) {
if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) {
return NGX_DECLINED;
}
@@ -1476,8 +1410,7 @@ ps_content_handler(ngx_http_request_t* r) {
return NGX_DONE;
}
ngx_int_t
ps_init(ngx_conf_t* cf) {
ngx_int_t ps_init(ngx_conf_t* cf) {
// Only put register pagespeed code to run if there was a "pagespeed"
// configuration option set in the config file. With "pagespeed off" we
// consider every request and choose not to do anything, while with no
@@ -1528,8 +1461,7 @@ ngx_http_module_t ps_module = {
// Called when nginx forks worker processes. No threads should be started
// before this.
ngx_int_t
ps_init_process(ngx_cycle_t* cycle) {
ngx_int_t ps_init_process(ngx_cycle_t* cycle) {
ps_main_conf_t* cfg_m = static_cast<ps_main_conf_t*>(
ngx_http_cycle_get_module_main_conf(cycle, ngx_pagespeed));
if (cfg_m->driver_factory != NULL) {
+5 -7
View File
@@ -30,12 +30,11 @@ namespace ngx_psol {
// Allocate chain links and buffers from the supplied pool, and copy over the
// data from the string piece. If the string piece is empty, return
// NGX_DECLINED immediately unless send_last_buf.
ngx_int_t
string_piece_to_buffer_chain(ngx_pool_t* pool, StringPiece sp,
ngx_chain_t** link_ptr, bool send_last_buf);
ngx_int_t string_piece_to_buffer_chain(
ngx_pool_t* pool, StringPiece sp,
ngx_chain_t** link_ptr, bool send_last_buf);
StringPiece
str_to_string_piece(ngx_str_t s);
StringPiece str_to_string_piece(ngx_str_t s);
// s1: ngx_str_t, s2: string literal
// true if they're equal, false otherwise
@@ -54,8 +53,7 @@ str_to_string_piece(ngx_str_t s);
// Allocate memory out of the pool for the string piece, and copy the contents
// over. Returns NULL if we can't get memory.
char*
string_piece_to_pool_string(ngx_pool_t* pool, StringPiece sp);
char* string_piece_to_pool_string(ngx_pool_t* pool, StringPiece sp);
} // namespace ngx_psol
+18 -18
View File
@@ -17,45 +17,45 @@
// Author: jefftk@google.com (Jeff Kaufman)
#include "ngx_rewrite_driver_factory.h"
#include "ngx_rewrite_options.h"
#include "ngx_thread_system.h"
#include <cstdio>
#include "ngx_cache.h"
#include "ngx_rewrite_options.h"
#include "ngx_thread_system.h"
#include "net/instaweb/apache/apr_mem_cache.h"
#include "net/instaweb/apache/apr_thread_compatible_pool.h"
#include "net/instaweb/apache/serf_url_async_fetcher.h"
#include "net/instaweb/http/public/content_type.h"
#include "net/instaweb/http/public/fake_url_async_fetcher.h"
#include "net/instaweb/http/public/http_cache.h"
#include "net/instaweb/http/public/wget_url_fetcher.h"
#include "net/instaweb/rewriter/public/server_context.h"
#include "net/instaweb/http/public/write_through_http_cache.h"
#include "net/instaweb/rewriter/public/rewrite_driver.h"
#include "net/instaweb/rewriter/public/rewrite_driver_factory.h"
#include "net/instaweb/rewriter/public/server_context.h"
#include "net/instaweb/rewriter/public/static_javascript_manager.h"
#include "net/instaweb/util/public/async_cache.h"
#include "net/instaweb/util/public/cache_batcher.h"
#include "net/instaweb/util/public/cache_copy.h"
#include "net/instaweb/util/public/cache_stats.h"
#include "net/instaweb/util/public/fallback_cache.h"
#include "net/instaweb/util/public/file_cache.h"
#include "net/instaweb/util/public/google_message_handler.h"
#include "net/instaweb/util/public/google_timer.h"
#include "net/instaweb/util/public/lru_cache.h"
#include "net/instaweb/util/public/md5_hasher.h"
#include "net/instaweb/util/public/null_shared_mem.h"
#include "net/instaweb/util/public/scheduler_thread.h"
#include "net/instaweb/util/public/stdio_file_system.h"
#include "net/instaweb/util/public/simple_stats.h"
#include "net/instaweb/util/public/slow_worker.h"
#include "net/instaweb/util/public/stdio_file_system.h"
#include "net/instaweb/util/public/string.h"
#include "net/instaweb/util/public/string_util.h"
#include "net/instaweb/util/public/thread_system.h"
#include "net/instaweb/util/public/threadsafe_cache.h"
#include "net/instaweb/util/public/slow_worker.h"
#include "net/instaweb/util/public/file_cache.h"
#include "net/instaweb/util/public/write_through_cache.h"
#include "net/instaweb/http/public/http_cache.h"
#include "net/instaweb/http/public/write_through_http_cache.h"
#include "net/instaweb/apache/apr_thread_compatible_pool.h"
#include "net/instaweb/apache/serf_url_async_fetcher.h"
#include "net/instaweb/apache/apr_mem_cache.h"
#include "net/instaweb/util/public/null_shared_mem.h"
#include "net/instaweb/util/public/cache_copy.h"
#include "net/instaweb/util/public/async_cache.h"
#include "net/instaweb/util/public/cache_stats.h"
#include "net/instaweb/util/public/cache_batcher.h"
#include "net/instaweb/util/public/fallback_cache.h"
#include "ngx_cache.h"
namespace net_instaweb {
+14 -14
View File
@@ -19,28 +19,27 @@
#ifndef NGX_REWRITE_DRIVER_FACTORY_H_
#define NGX_REWRITE_DRIVER_FACTORY_H_
#include "apr_pools.h"
#include "base/scoped_ptr.h"
#include "net/instaweb/rewriter/public/rewrite_driver_factory.h"
#include "net/instaweb/util/public/md5_hasher.h"
#include "net/instaweb/util/public/simple_stats.h"
#include "apr_pools.h"
// TODO (oschaaf):
// We should reparent ApacheRewriteDriverFactory and NgxRewriteDriverFactory
// to a new class OriginRewriteDriverFactory & factor out as much as possible.
// TODO(oschaaf): We should reparent ApacheRewriteDriverFactory and
// NgxRewriteDriverFactory to a new class OriginRewriteDriverFactory and factor
// out as much as possible.
namespace net_instaweb {
class AbstractSharedMem;
class SlowWorker;
class StaticJavaScriptManager;
class NgxServerContext;
class AprMemCache;
class AsyncCache;
class CacheInterface;
class NgxServerContext;
class NgxCache;
class NgxRewriteOptions;
class AprMemCache;
class CacheInterface;
class AsyncCache;
class SlowWorker;
class StaticJavaScriptManager;
class NgxRewriteDriverFactory : public RewriteDriverFactory {
public:
@@ -49,7 +48,7 @@ class NgxRewriteDriverFactory : public RewriteDriverFactory {
// main_conf will have only options set in the main block. It may be NULL,
// and we do not take ownership.
NgxRewriteDriverFactory(NgxRewriteOptions* main_conf);
explicit NgxRewriteDriverFactory(NgxRewriteOptions* main_conf);
virtual ~NgxRewriteDriverFactory();
virtual Hasher* NewHasher();
virtual UrlFetcher* DefaultUrlFetcher();
@@ -94,7 +93,8 @@ class NgxRewriteDriverFactory : public RewriteDriverFactory {
//
// If a non-null CacheInterface* is returned, its ownership is transferred
// to the caller and must be freed on destruction.
CacheInterface* GetMemcached(NgxRewriteOptions* options, CacheInterface* l2_cache);
CacheInterface* GetMemcached(NgxRewriteOptions* options,
CacheInterface* l2_cache);
// Returns the filesystem metadata cache for the given config's specification
// (if it has one). NULL is returned if no cache is specified.
@@ -104,7 +104,7 @@ class NgxRewriteDriverFactory : public RewriteDriverFactory {
// called after the caller has finished any forking it intends to do.
void StartThreads();
private:
private:
SimpleStats simple_stats_;
Timer* timer_;
scoped_ptr<SlowWorker> slow_worker_;
@@ -139,6 +139,6 @@ private:
DISALLOW_COPY_AND_ASSIGN(NgxRewriteDriverFactory);
};
} // namespace net_instaweb
} // namespace net_instaweb
#endif // NGX_REWRITE_DRIVER_FACTORY_H_
+7 -8
View File
@@ -22,13 +22,13 @@ extern "C" {
#include <ngx_http.h>
}
#include "ngx_rewrite_options.h"
#include "ngx_pagespeed.h"
#include "net/instaweb/public/version.h"
#include "net/instaweb/rewriter/public/file_load_policy.h"
#include "net/instaweb/rewriter/public/rewrite_options.h"
#include "net/instaweb/util/public/timer.h"
#include "net/instaweb/rewriter/public/file_load_policy.h"
namespace net_instaweb {
@@ -60,7 +60,7 @@ void NgxRewriteOptions::AddProperties() {
add_ngx_option(500000,
&NgxRewriteOptions::file_cache_clean_inode_limit_, "nfcl",
RewriteOptions::kFileCacheCleanInodeLimit);
add_ngx_option(16384, //16MB
add_ngx_option(16384, // 16MB
&NgxRewriteOptions::lru_cache_byte_limit_, "nlcb",
RewriteOptions::kLruCacheByteLimit);
add_ngx_option(1024, // 1MB
@@ -206,9 +206,9 @@ RewriteOptions::OptionSettingResult NgxRewriteOptions::ParseAndSetOptions2(
} else if (IsDirective(directive, "CustomFetchHeader")) {
AddCustomFetchHeader(arg1, arg2);
} else if (IsDirective(directive, "LoadFromFile")) {
file_load_policy()->Associate(arg1,arg2);
file_load_policy()->Associate(arg1, arg2);
} else if (IsDirective(directive, "LoadFromFileMatch")) {
if (!file_load_policy()->AssociateRegexp(arg1,arg2,msg)) {
if (!file_load_policy()->AssociateRegexp(arg1, arg2, msg)) {
return RewriteOptions::kOptionValueInvalid;
}
} else if (IsDirective(directive, "LoadFromFileRule")
@@ -256,7 +256,7 @@ RewriteOptions::OptionSettingResult NgxRewriteOptions::ParseAndSetOptions3(
if (!ok) {
*msg = "Format is size md5 url; bad md5 or URL";
return RewriteOptions::kOptionValueInvalid;
}
}
} else {
return RewriteOptions::kOptionNameUnknown;
}
@@ -268,7 +268,7 @@ RewriteOptions::OptionSettingResult NgxRewriteOptions::ParseAndSetOptions3(
const char*
NgxRewriteOptions::ParseAndSetOptions(
StringPiece* args, int n_args, ngx_pool_t* pool, MessageHandler* handler) {
CHECK(n_args >= 1);
CHECK_GE(n_args, 1);
int i;
fprintf(stderr, "Setting option from (");
@@ -350,5 +350,4 @@ const char* NgxRewriteOptions::class_name() const {
return NgxRewriteOptions::kClassName;
}
} // namespace net_instaweb
+3 -2
View File
@@ -131,6 +131,7 @@ class NgxRewriteOptions : public RewriteOptions {
void set_fetcher_proxy(GoogleString x) {
set_option(x, &fetcher_proxy_);
}
private:
// Used by class_name() and DynamicCast() to provide error checking.
static const char kClassName[];
@@ -158,7 +159,7 @@ class NgxRewriteOptions : public RewriteOptions {
StringPiece directive, StringPiece arg1, StringPiece arg2,
GoogleString* msg, MessageHandler* handler);
OptionSettingResult ParseAndSetOptions3(
StringPiece directive, StringPiece arg1, StringPiece arg2,
StringPiece directive, StringPiece arg1, StringPiece arg2,
StringPiece arg3, GoogleString* msg, MessageHandler* handler);
// Keeps the properties added by this subclass. These are merged into
@@ -202,6 +203,6 @@ class NgxRewriteOptions : public RewriteOptions {
DISALLOW_COPY_AND_ASSIGN(NgxRewriteOptions);
};
} // namespace net_instaweb
} // namespace net_instaweb
#endif // NGX_REWRITE_OPTIONS_H_
+1
View File
@@ -17,6 +17,7 @@
// Author: jefftk@google.com (Jeff Kaufman)
#include "ngx_server_context.h"
#include "ngx_rewrite_options.h"
#include "ngx_rewrite_driver_factory.h"
#include "net/instaweb/util/public/file_system_lock_manager.h"
+3 -2
View File
@@ -22,6 +22,7 @@
#define NGX_SERVER_CONTEXT_H_
#include "net/instaweb/rewriter/public/server_context.h"
namespace net_instaweb {
class NgxRewriteDriverFactory;
@@ -29,7 +30,7 @@ class NgxRewriteOptions;
class NgxServerContext : public ServerContext {
public:
NgxServerContext(NgxRewriteDriverFactory* factory);
explicit NgxServerContext(NgxRewriteDriverFactory* factory);
virtual ~NgxServerContext();
// Call only when you need an NgxRewriteOptions. If you don't need
@@ -42,6 +43,6 @@ class NgxServerContext : public ServerContext {
DISALLOW_COPY_AND_ASSIGN(NgxServerContext);
};
} // namespace net_instaweb
} // namespace net_instaweb
#endif // NGX_SERVER_CONTEXT_H_