aboutsummaryrefslogtreecommitdiff
path: root/src/http
diff options
context:
space:
mode:
Diffstat (limited to 'src/http')
-rw-r--r--src/http/modules/ngx_http_gzip_filter.c69
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.c1
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.h1
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_header.c33
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_upstream.c9
-rw-r--r--src/http/ngx_http_headers.c4
-rw-r--r--src/http/ngx_http_request.h4
7 files changed, 104 insertions, 17 deletions
diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c
index c62a9ea4f..2034595d0 100644
--- a/src/http/modules/ngx_http_gzip_filter.c
+++ b/src/http/modules/ngx_http_gzip_filter.c
@@ -96,10 +96,8 @@ static ngx_conf_enum_t ngx_http_gzip_http_version[] = {
static ngx_conf_enum_t ngx_http_gzip_proxied[] = {
{ ngx_string("off"), NGX_HTTP_GZIP_PROXIED_OFF },
-#if 0
{ ngx_string("nocachable"), NGX_HTTP_GZIP_PROXIED_NOCACHABLE },
{ ngx_string("poor_cachable"), NGX_HTTP_GZIP_PROXIED_POOR_CACHABLE },
-#endif
{ ngx_string("on"), NGX_HTTP_GZIP_PROXIED_ON },
{ ngx_null_string, 0 }
};
@@ -223,6 +221,7 @@ static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
static int ngx_http_gzip_header_filter(ngx_http_request_t *r)
{
+ time_t date, expires;
ngx_http_gzip_ctx_t *ctx;
ngx_http_gzip_conf_t *conf;
@@ -250,9 +249,67 @@ static int ngx_http_gzip_header_filter(ngx_http_request_t *r)
}
- /* TODO: proxied */
- if (r->headers_in.via && conf->proxied == NGX_HTTP_GZIP_PROXIED_OFF) {
- return ngx_http_next_header_filter(r);
+ if (r->headers_in.via && conf->proxied != NGX_HTTP_GZIP_PROXIED_ON) {
+
+ if (conf->proxied == NGX_HTTP_GZIP_PROXIED_OFF) {
+ return ngx_http_next_header_filter(r);
+ }
+
+ if (r->headers_out.expires) {
+ expires = ngx_http_parse_time(r->headers_out.expires->value.data,
+ r->headers_out.expires->value.len);
+ if (expires == NGX_ERROR) {
+ return ngx_http_next_header_filter(r);
+ }
+
+ if (r->headers_out.date) {
+ date = ngx_http_parse_time(r->headers_out.date->value.data,
+ r->headers_out.date->value.len);
+ if (date == NGX_ERROR) {
+ return ngx_http_next_header_filter(r);
+ }
+
+ } else {
+ date = ngx_cached_time;
+ }
+
+ if (expires >= date) {
+ return ngx_http_next_header_filter(r);
+ }
+
+ } else if (r->headers_out.cache_control) {
+
+ if (conf->proxied == NGX_HTTP_GZIP_PROXIED_NOCACHABLE) {
+ if (ngx_strstr(r->headers_out.cache_control->value.data,
+ "no-cache") == NULL)
+ {
+ return ngx_http_next_header_filter(r);
+ }
+
+ } else { /* NGX_HTTP_GZIP_PROXIED_POOR_CACHABLE */
+
+ /* STUB: should be one cycle for all values */
+
+ if (ngx_strstr(r->headers_out.cache_control->value.data,
+ "no-cache") == NULL
+ && ngx_strstr(r->headers_out.cache_control->value.data,
+ "private") == NULL
+ && ngx_strstr(r->headers_out.cache_control->value.data,
+ "no-store") == NULL)
+ {
+ return ngx_http_next_header_filter(r);
+ }
+ }
+
+ } else if (conf->proxied == NGX_HTTP_GZIP_PROXIED_NOCACHABLE) {
+ return ngx_http_next_header_filter(r);
+
+ } else { /* NGX_HTTP_GZIP_PROXIED_POOR_CACHABLE */
+
+ if (r->headers_out.last_modified || r->headers_out.etag) {
+ return ngx_http_next_header_filter(r);
+ }
+ }
}
@@ -533,7 +590,7 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
trailer->crc32 = ctx->crc32;
trailer->zlen = ctx->zin;
#else
- /* STUB */
+ /* STUB */ Oops !
#endif
ctx->zstream.avail_in = 0;
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index 0fd89c139..d7cbf9608 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -262,6 +262,7 @@ ngx_http_header_t ngx_http_proxy_headers_in[] = {
{ ngx_string("Expires"), offsetof(ngx_http_proxy_headers_in_t, expires) },
{ ngx_string("Cache-Control"),
offsetof(ngx_http_proxy_headers_in_t, cache_control) },
+ { ngx_string("ETag"), offsetof(ngx_http_proxy_headers_in_t, etag) },
{ ngx_string("X-Accel-Expires"),
offsetof(ngx_http_proxy_headers_in_t, x_accel_expires) },
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h
index 853aa7617..55eee74e9 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.h
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.h
@@ -114,6 +114,7 @@ typedef struct {
ngx_table_elt_t *expires;
ngx_table_elt_t *cache_control;
+ ngx_table_elt_t *etag;
ngx_table_elt_t *x_accel_expires;
ngx_table_elt_t *connection;
diff --git a/src/http/modules/proxy/ngx_http_proxy_header.c b/src/http/modules/proxy/ngx_http_proxy_header.c
index 8c24a065e..cb13034f7 100644
--- a/src/http/modules/proxy/ngx_http_proxy_header.c
+++ b/src/http/modules/proxy/ngx_http_proxy_header.c
@@ -20,6 +20,8 @@ int ngx_http_proxy_copy_header(ngx_http_proxy_ctx_t *p,
h = headers_in->headers.elts;
for (i = 0; i < headers_in->headers.nelts; i++) {
+ /* ignore some headers */
+
if (&h[i] == headers_in->connection) {
continue;
}
@@ -51,12 +53,18 @@ int ngx_http_proxy_copy_header(ngx_http_proxy_ctx_t *p,
}
}
+
+ /* "Content-Type" is handled specially */
+
if (&h[i] == headers_in->content_type) {
r->headers_out.content_type = &h[i];
r->headers_out.content_type->key.len = 0;
continue;
}
+
+ /* copy some header pointers and set up r->headers_out */
+
if (!(ho = ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
{
return NGX_ERROR;
@@ -64,9 +72,30 @@ int ngx_http_proxy_copy_header(ngx_http_proxy_ctx_t *p,
*ho = h[i];
+ if (&h[i] == headers_in->expires) {
+ r->headers_out.expires = ho;
+ continue;
+ }
+
+ if (&h[i] == headers_in->cache_control) {
+ r->headers_out.cache_control = ho;
+ continue;
+ }
+
+ if (&h[i] == headers_in->etag) {
+ r->headers_out.etag = ho;
+ continue;
+ }
+
+ if (&h[i] == headers_in->last_modified) {
+ r->headers_out.last_modified = ho;
+ /* TODO: update r->headers_out.last_modified_time */
+ continue;
+ }
+
/*
- * ngx_http_header_filter() does not handle specially
- * the following headers if they are set:
+ * ngx_http_header_filter() passes the following headers as is
+ * and does not handle them specially if they are set:
* r->headers_out.server,
* r->headers_out.date,
* r->headers_out.content_length
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index 41946bfc6..60c9e8fca 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -338,9 +338,7 @@ static void ngx_http_proxy_init_upstream(void *data)
r->connection->read->event_handler = ngx_http_proxy_check_broken_connection;
- if (ngx_event_flags & (NGX_USE_CLEAR_EVENT|NGX_HAVE_KQUEUE_EVENT)) {
-
- /* kqueue allows to detect when client closes prematurely connection */
+ if (ngx_event_flags & NGX_USE_CLEAR_EVENT) {
r->connection->write->event_handler =
ngx_http_proxy_check_broken_connection;
@@ -627,11 +625,6 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
if (rc == NGX_AGAIN) {
ngx_add_timer(c->write, p->lcf->connect_timeout);
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http proxy connect handler: " PTR_FMT,
- c->write->event_handler);
-
return;
}
diff --git a/src/http/ngx_http_headers.c b/src/http/ngx_http_headers.c
index 8c925be21..fd617b161 100644
--- a/src/http/ngx_http_headers.c
+++ b/src/http/ngx_http_headers.c
@@ -53,6 +53,10 @@ ngx_http_header_t ngx_http_headers_out[] = {
offsetof(ngx_http_headers_out_t, last_modified) },
{ ngx_string("Accept-Ranges"),
offsetof(ngx_http_headers_out_t, accept_ranges) },
+ { ngx_string("Expires"), offsetof(ngx_http_headers_out_t, expires) },
+ { ngx_string("Cache-Control"),
+ offsetof(ngx_http_headers_out_t, cache_control) },
+ { ngx_string("ETag"), offsetof(ngx_http_headers_out_t, etag) },
{ ngx_null_string, 0 }
};
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index e5ae3e1be..716818fa4 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -140,12 +140,14 @@ typedef struct {
ngx_table_elt_t *last_modified;
ngx_table_elt_t *content_range;
ngx_table_elt_t *accept_ranges;
+ ngx_table_elt_t *expires;
+ ngx_table_elt_t *cache_control;
+ ngx_table_elt_t *etag;
ngx_str_t charset;
ngx_array_t ranges;
off_t content_length_n;
- u_char *etag;
time_t date_time;
time_t last_modified_time;
} ngx_http_headers_out_t;