Skip to content

Commit 25e9fba

Browse files
committed
console: support /pagespeed_console
sligocki is adding a feature to pagespeed where it will parse your statistics for you and determine if there are any problems. This CL wires up the ConsoleHandler and also includes a few required files in the build process. It doesn't work yet, because as of svn r3193 the console has a hardcoded json request to '/mod_pagespeed_statistics' and in nginx we use '/ngx_...' . I've tested this by changing all uses here to use the "mod_..." version and that worked, but I've undone those changes.
1 parent 0fc61ad commit 25e9fba

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ location ~ "^/ngx_pagespeed_static/" { }
8787
location ~ "^/ngx_pagespeed_beacon$" { }
8888
location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; }
8989
location /ngx_pagespeed_message { allow 127.0.0.1; deny all; }
90+
location /pagespeed_console { allow 127.0.0.1; deny all; }
9091
```
9192

9293
To confirm that the module is loaded, fetch a page and check that you see the

config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ if [ $ngx_found = yes ]; then
170170
$ps_src/ngx_thread_system.cc \
171171
$ps_src/ngx_url_async_fetcher.cc \
172172
$ps_src/pthread_shared_mem.cc \
173+
$mod_pagespeed_dir/out/$buildtype/obj/gen/data2c_out/instaweb/net/instaweb/system/console_out.cc \
174+
$mod_pagespeed_dir/out/$buildtype/obj/gen/data2c_out/instaweb/net/instaweb/system/console_css_out.cc \
173175
$mod_pagespeed_dir/net/instaweb/system/add_headers_fetcher.cc \
174176
$mod_pagespeed_dir/net/instaweb/system/loopback_route_fetcher.cc \
175177
$mod_pagespeed_dir/net/instaweb/system/serf_url_async_fetcher.cc"

scripts/prepare_psol.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ rsync -arvz "$MOD_PAGESPEED_SRC/" "psol/include/" --prune-empty-dirs \
6363
--include="apr_memcache2.c" \
6464
--include="loopback_route_fetcher.cc" \
6565
--include="add_headers_fetcher.cc" \
66+
--include="console_css_out.cc" \
67+
--include="console_out.cc" \
6668
--include="dense_hash_map" \
6769
--include="dense_hash_set" \
6870
--include="sparse_hash_map" \

src/ngx_pagespeed.cc

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "net/instaweb/rewriter/public/resource_fetch.h"
4949
#include "net/instaweb/rewriter/public/rewrite_driver.h"
5050
#include "net/instaweb/rewriter/public/static_asset_manager.h"
51+
#include "net/instaweb/system/public/handlers.h"
5152
#include "net/instaweb/public/global_constants.h"
5253
#include "net/instaweb/public/version.h"
5354
#include "net/instaweb/util/public/google_message_handler.h"
@@ -348,6 +349,7 @@ enum Response {
348349
kPagespeedDisabled,
349350
kBeacon,
350351
kStatistics,
352+
kConsole,
351353
kMessages,
352354
kPagespeedSubrequest,
353355
kNotHeadOrGet,
@@ -1472,6 +1474,9 @@ CreateRequestContext::Response ps_create_request_context(
14721474
|| url.PathSansQuery() == "/ngx_pagespeed_global_statistics" ) {
14731475
return CreateRequestContext::kStatistics;
14741476
}
1477+
if (url.PathSansQuery() == "/pagespeed_console") {
1478+
return CreateRequestContext::kConsole;
1479+
}
14751480
if (url.PathSansQuery() == "/ngx_pagespeed_message") {
14761481
return CreateRequestContext::kMessages;
14771482
}
@@ -1925,6 +1930,7 @@ ngx_int_t ps_header_filter(ngx_http_request_t* r) {
19251930
case CreateRequestContext::kBeacon:
19261931
case CreateRequestContext::kStaticContent:
19271932
case CreateRequestContext::kStatistics:
1933+
case CreateRequestContext::kConsole:
19281934
case CreateRequestContext::kMessages:
19291935
case CreateRequestContext::kPagespeedSubrequest:
19301936
case CreateRequestContext::kPagespeedDisabled:
@@ -2151,6 +2157,20 @@ void ps_write_handler_response(const StringPiece& output, ngx_http_request_t* r,
21512157
ps_write_handler_response(output, r, net_instaweb::kContentTypeHtml, timer);
21522158
}
21532159

2160+
ngx_int_t ps_console_handler(
2161+
ngx_http_request_t* r,
2162+
net_instaweb::NgxServerContext* server_context) {
2163+
net_instaweb::NgxRewriteDriverFactory* factory =
2164+
static_cast<net_instaweb::NgxRewriteDriverFactory*>(
2165+
server_context->factory());
2166+
net_instaweb::MessageHandler* message_handler = factory->message_handler();
2167+
GoogleString output;
2168+
net_instaweb::StringWriter writer(&output);
2169+
ConsoleHandler(server_context, &writer, message_handler);
2170+
ps_write_handler_response(output, r, factory->timer());
2171+
return NGX_OK;
2172+
}
2173+
21542174
// TODO(oschaaf): port SPDY specific functionality, shmcache stats
21552175
// TODO(oschaaf): refactor this with the apache code to share this code
21562176
ngx_int_t ps_statistics_handler(
@@ -2445,7 +2465,7 @@ void ps_beacon_body_handler(ngx_http_request_t* r) {
24452465
StringPiece request_body;
24462466
bool ok = ps_request_body_to_string_piece(r, &request_body);
24472467
GoogleString beacon_data = net_instaweb::StrCat(
2448-
query_param_beacon_data, "&", request_body);
2468+
query_param_beacon_data, "&", request_body);
24492469
if (ok) {
24502470
ps_beacon_handler_helper(r, beacon_data.c_str());
24512471
ngx_http_finalize_request(r, NGX_HTTP_NO_CONTENT);
@@ -2508,6 +2528,8 @@ ngx_int_t ps_content_handler(ngx_http_request_t* r) {
25082528
return ps_static_handler(r);
25092529
case CreateRequestContext::kStatistics:
25102530
return ps_statistics_handler(r, cfg_s->server_context);
2531+
case CreateRequestContext::kConsole:
2532+
return ps_console_handler(r, cfg_s->server_context);
25112533
case CreateRequestContext::kMessages:
25122534
return ps_messages_handler(r, cfg_s->server_context);
25132535
case CreateRequestContext::kOk:

test/pagespeed_test.conf.template

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ http {
3939
# critical images to be inlined, so we just disable the option here.
4040
pagespeed CriticalImagesBeaconEnabled false;
4141

42+
pagespeed Statistics on;
43+
pagespeed StatisticsLogging on;
44+
pagespeed LogDir "@@TEST_TMP@@/logdir";
45+
4246
server {
4347
# Sets up a logical home-page server on
4448
# max-cacheable-content-length.example.com. This server is only used to
@@ -104,7 +108,7 @@ http {
104108
set $ua_dependent_ps_capability_list "";
105109
set $bypass_cache 1;
106110
}
107-
111+
108112
location ~ /purge(/.*) {
109113
allow all;
110114
proxy_cache_purge htmlcache $ua_dependent_ps_capability_list$1$is_args$args;

0 commit comments

Comments
 (0)