refactoring
This commit is contained in:
+35
-7
@@ -88,12 +88,12 @@ ngx_int_t ngx_http_pagespeed_header_filter(ngx_http_request_t* r)
|
|||||||
// Add a buffer to the end of the buffer chain indicating that we were processed
|
// Add a buffer to the end of the buffer chain indicating that we were processed
|
||||||
// through ngx_pagespeed.
|
// through ngx_pagespeed.
|
||||||
static
|
static
|
||||||
ngx_int_t ngx_http_pagespeed_body_filter(ngx_http_request_t* r, ngx_chain_t* in)
|
ngx_int_t ngx_http_pagespeed_note_processed(ngx_http_request_t* r,
|
||||||
{
|
ngx_chain_t* in) {
|
||||||
// Find the end of the buffer chain.
|
// Find the end of the buffer chain.
|
||||||
ngx_chain_t* chain_link;
|
ngx_chain_t* chain_link;
|
||||||
int chain_contains_last_buffer = 0;
|
int chain_contains_last_buffer = 0;
|
||||||
for ( chain_link = in; chain_link != NULL; chain_link = chain_link->next ) {
|
for (chain_link = in; chain_link != NULL; chain_link = chain_link->next) {
|
||||||
if (chain_link->buf->last_buf) {
|
if (chain_link->buf->last_buf) {
|
||||||
chain_contains_last_buffer = 1;
|
chain_contains_last_buffer = 1;
|
||||||
if (chain_link->next != NULL) {
|
if (chain_link->next != NULL) {
|
||||||
@@ -107,10 +107,9 @@ ngx_int_t ngx_http_pagespeed_body_filter(ngx_http_request_t* r, ngx_chain_t* in)
|
|||||||
|
|
||||||
if (!chain_contains_last_buffer) {
|
if (!chain_contains_last_buffer) {
|
||||||
// None of the buffers had last_buf set, meaning we have an incomplete chain
|
// None of the buffers had last_buf set, meaning we have an incomplete chain
|
||||||
// and are still waiting to get the final buffer. Let other body filters
|
// and are still waiting to get the final buffer. Wait until we're called
|
||||||
// act on the buffers we have so far and wait until we're called again with
|
// again with the last buffer.
|
||||||
// the last buffer.
|
return NGX_OK;
|
||||||
return ngx_http_next_body_filter(r, in);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare a new buffer to put the note into.
|
// Prepare a new buffer to put the note into.
|
||||||
@@ -147,6 +146,35 @@ ngx_int_t ngx_http_pagespeed_body_filter(ngx_http_request_t* r, ngx_chain_t* in)
|
|||||||
chain_link->buf->last_in_chain = 0;
|
chain_link->buf->last_in_chain = 0;
|
||||||
added_link->buf->last_in_chain = 1;
|
added_link->buf->last_in_chain = 1;
|
||||||
|
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace each buffer with a new one that's been through HtmlParse.
|
||||||
|
static
|
||||||
|
ngx_int_t ngx_http_pagespeed_parse_and_replace_buffer(ngx_http_request_t* r,
|
||||||
|
ngx_chain_t* in) {
|
||||||
|
ngx_chain_t* chain_link;
|
||||||
|
for (chain_link = in; chain_link != NULL; chain_link = chain_link->next) {
|
||||||
|
// working here
|
||||||
|
}
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
ngx_int_t ngx_http_pagespeed_body_filter(ngx_http_request_t* r, ngx_chain_t* in)
|
||||||
|
{
|
||||||
|
ngx_int_t rc;
|
||||||
|
|
||||||
|
rc = ngx_http_pagespeed_parse_and_replace_buffer(r, in);
|
||||||
|
if (rc != NGX_OK) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = ngx_http_pagespeed_note_processed(r, in);
|
||||||
|
if (rc != NGX_OK) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
return ngx_http_next_body_filter(r, in);
|
return ngx_http_next_body_filter(r, in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user