Compare commits

..

4 Commits

Author SHA1 Message Date
Otto van der Schaaf dea38db4cb [DRAFT] Fixes for NGINX nginx 1.23.0
As of nginx 1.23 the cache control headers are re-implemented as al linked list.
This reworks our code that manipulates this header to work with that.

Still a draft: this change probably needs to be conditioned against nginx version
with ifdefs, so older version can still be built as well. Hence, still a draft.

Attempts to fix https://github.com/apache/incubator-pagespeed-ngx/issues/1749
2022-06-27 09:57:37 +02:00
Werner Beroux 9e70f6dacb Avoids relying on Bash (#1700)
This script runs fine with just Dash (SH) instead of Bash. Alpine Linux and others don't have Bash.
2020-07-30 00:37:59 +02:00
Ivan Ridao Freitas d647f4be4f Update README.md (#1677)
Fixes #1676 by using the image uploaded to GitHub.
2020-01-25 09:29:48 -05:00
Otto van der Schaaf c69649ab0a Fix error handling in ps_create_XXX_conf (#1625)
Return NULL instead of NGX_CONF_ERROR when config creation fails.

Fixes https://github.com/apache/incubator-pagespeed-ngx/issues/1623
2019-02-10 23:42:44 +01:00
11 changed files with 68 additions and 51 deletions
+18
View File
@@ -0,0 +1,18 @@
[submodule "testing-dependencies/mod_pagespeed"]
path = testing-dependencies/mod_pagespeed
url = https://github.com/apache/incubator-pagespeed-mod.git
[submodule "testing-dependencies/ngx_cache_purge"]
path = testing-dependencies/ngx_cache_purge
url = https://github.com/FRiCKLE/ngx_cache_purge.git
[submodule "testing-dependencies/nginx"]
path = testing-dependencies/nginx
url = https://github.com/nginx/nginx.git
[submodule "testing-dependencies/set-misc-nginx-module"]
path = testing-dependencies/set-misc-nginx-module
url = https://github.com/openresty/set-misc-nginx-module
[submodule "testing-dependencies/ngx_devel_kit"]
path = testing-dependencies/ngx_devel_kit
url = https://github.com/simpl/ngx_devel_kit
[submodule "testing-dependencies/headers-more-nginx-module"]
path = testing-dependencies/headers-more-nginx-module
url = https://github.com/openresty/headers-more-nginx-module
+4 -1
View File
@@ -1 +1,4 @@
https://dist.apache.org/repos/dist/release/incubator/pagespeed/1.14.36.1/x64/psol-1.14.36.1-apache-incubating-$BIT_SIZE_NAME.tar.gz
In a release this file would contain the URL to download the pre-compiled PSOL
binary, but on development branches (like this one) you have to build PSOL from
source yourself. See:
https://github.com/apache/incubator-pagespeed-ngx/wiki/Building-PSOL-From-Source
+1 -1
View File
@@ -1,4 +1,4 @@
![ngx_pagespeed](https://lh6.googleusercontent.com/-qufedJIJq7Y/UXEvVYxyYvI/AAAAAAAADo8/JHDFQhs91_c/s401/04_ngx_pagespeed.png)
![ngx_pagespeed](https://user-images.githubusercontent.com/6751650/73116078-338a9180-3f0f-11ea-8fdf-8c99cb4bec7f.png)
[![Build Status](https://travis-ci.org/apache/incubator-pagespeed-ngx.svg?branch=master)](https://travis-ci.org/apache/incubator-pagespeed-ngx)
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
+38 -48
View File
@@ -396,40 +396,32 @@ namespace {
//
// Based on ngx_http_add_cache_control.
ngx_int_t ps_set_cache_control(ngx_http_request_t* r, char* cache_control) {
// First strip existing cache-control headers.
ngx_table_elt_t* header;
NgxListIterator it(&(r->headers_out.headers.part));
while ((header = it.Next()) != NULL) {
if (STR_CASE_EQ_LITERAL(header->key, "Cache-Control")) {
// Response headers with hash of 0 are excluded from the response.
header->hash = 0;
}
}
ngx_table_elt_t* cc = r->headers_out.cache_control;
// Now add our new cache control header.
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*));
if (rc != NGX_OK) {
return NGX_ERROR;
}
if (cc == NULL) {
cc = reinterpret_cast<ngx_table_elt_t*>(ngx_list_push(&r->headers_out.headers));
if (cc == NULL) {
return NGX_ERROR;
}
r->headers_out.cache_control = cc;
cc->next = NULL;
cc->hash = 1;
ngx_str_set(&cc->key, "Cache-Control");
} else {
for (cc = cc->next; cc; cc = cc->next) {
cc->hash = 0;
}
cc = r->headers_out.cache_control;
cc->next = NULL;
}
ngx_table_elt_t** cache_control_headers = static_cast<ngx_table_elt_t**>(
ngx_array_push(&r->headers_out.cache_control));
if (cache_control_headers == NULL) {
return NGX_ERROR;
}
cache_control_headers[0] = static_cast<ngx_table_elt_t*>(
ngx_list_push(&r->headers_out.headers));
if (cache_control_headers[0] == NULL) {
return NGX_ERROR;
}
cache_control_headers[0]->hash = 1;
ngx_str_set(&cache_control_headers[0]->key, "Cache-Control");
cache_control_headers[0]->value.len = strlen(cache_control);
cache_control_headers[0]->value.data =
cc->value.len = strlen(cache_control);
cc->value.data =
reinterpret_cast<u_char*>(cache_control);
return NGX_OK;
}
@@ -439,22 +431,20 @@ bool ps_get_cache_control(ngx_http_request_t* r, GoogleString* cache_control) {
// Use headers_out.cache_control instead of looking for Cache-Control in
// headers_out.headers, because if an upstream sent multiple Cache-Control
// headers they're already combined in headers_out.cache_control.
auto ccp = static_cast<ngx_table_elt_t**>(r->headers_out.cache_control.elts);
if (ccp == nullptr) {
return false; // Header not present.
}
ngx_table_elt_t* cc = r->headers_out.cache_control;
bool first_segment = true;
for (ngx_uint_t i = 0; i < r->headers_out.cache_control.nelts; i++) {
if (ccp[i]->hash == 0) {
continue; // Elements with a hash of 0 are marked as excluded.
while (cc != NULL) {
if (cc->hash) {
if (first_segment) {
first_segment = false;
} else {
cache_control->append(", ");
}
cache_control->append(reinterpret_cast<char*>(cc->value.data),
cc->value.len);
}
if (first_segment) {
first_segment = false;
} else {
cache_control->append(", ");
}
cache_control->append(reinterpret_cast<char*>(ccp[i]->value.data),
ccp[i]->value.len);
cc = cc->next;
}
return true;
}
@@ -1028,7 +1018,7 @@ 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;
return NULL;
}
CHECK(!factory_deleted);
NgxRewriteOptions::Initialize();
@@ -1049,7 +1039,7 @@ void* ps_create_main_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;
return NULL;
}
ps_set_conf_cleanup_handler(cf, ps_cleanup_srv_conf, cfg_s);
return cfg_s;
@@ -1058,7 +1048,7 @@ void* ps_create_srv_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;
return NULL;
}
ps_set_conf_cleanup_handler(cf, ps_cleanup_loc_conf, cfg_l);
return cfg_l;