Welcome! Log In Create A New Profile

Advanced

[nginx] Basic support of the Link response header.

February 08, 2018 02:00AM
details: http://hg.nginx.org/nginx/rev/6ba68ad8b24c
branches:
changeset: 7199:6ba68ad8b24c
user: Ruslan Ermilov <ru@nginx.com>
date: Thu Feb 08 09:54:18 2018 +0300
description:
Basic support of the Link response header.

diffstat:

src/http/modules/ngx_http_headers_filter_module.c | 42 ++++++++++++----------
src/http/ngx_http_request.h | 1 +
src/http/ngx_http_upstream.c | 5 ++
src/http/ngx_http_variables.c | 3 +
4 files changed, 32 insertions(+), 19 deletions(-)

diffs (124 lines):

diff -r 573f20116163 -r 6ba68ad8b24c src/http/modules/ngx_http_headers_filter_module.c
--- a/src/http/modules/ngx_http_headers_filter_module.c Wed Feb 07 16:44:29 2018 +0300
+++ b/src/http/modules/ngx_http_headers_filter_module.c Thu Feb 08 09:54:18 2018 +0300
@@ -56,7 +56,7 @@ static ngx_int_t ngx_http_set_expires(ng
ngx_http_headers_conf_t *conf);
static ngx_int_t ngx_http_parse_expires(ngx_str_t *value,
ngx_http_expires_t *expires, time_t *expires_time, char **err);
-static ngx_int_t ngx_http_add_cache_control(ngx_http_request_t *r,
+static ngx_int_t ngx_http_add_multi_header_lines(ngx_http_request_t *r,
ngx_http_header_val_t *hv, ngx_str_t *value);
static ngx_int_t ngx_http_add_header(ngx_http_request_t *r,
ngx_http_header_val_t *hv, ngx_str_t *value);
@@ -77,7 +77,13 @@ static char *ngx_http_headers_add(ngx_co

static ngx_http_set_header_t ngx_http_set_headers[] = {

- { ngx_string("Cache-Control"), 0, ngx_http_add_cache_control },
+ { ngx_string("Cache-Control"),
+ offsetof(ngx_http_headers_out_t, cache_control),
+ ngx_http_add_multi_header_lines },
+
+ { ngx_string("Link"),
+ offsetof(ngx_http_headers_out_t, link),
+ ngx_http_add_multi_header_lines },

{ ngx_string("Last-Modified"),
offsetof(ngx_http_headers_out_t, last_modified),
@@ -555,42 +561,40 @@ ngx_http_add_header(ngx_http_request_t *


static ngx_int_t
-ngx_http_add_cache_control(ngx_http_request_t *r, ngx_http_header_val_t *hv,
- ngx_str_t *value)
+ngx_http_add_multi_header_lines(ngx_http_request_t *r,
+ ngx_http_header_val_t *hv, ngx_str_t *value)
{
- ngx_table_elt_t *cc, **ccp;
+ ngx_array_t *pa;
+ ngx_table_elt_t *h, **ph;

if (value->len == 0) {
return NGX_OK;
}

- ccp = r->headers_out.cache_control.elts;
-
- if (ccp == NULL) {
+ pa = (ngx_array_t *) ((char *) &r->headers_out + hv->offset);

- if (ngx_array_init(&r->headers_out.cache_control, r->pool,
- 1, sizeof(ngx_table_elt_t *))
- != NGX_OK)
+ if (pa->elts == NULL) {
+ if (ngx_array_init(pa, r->pool, 1, sizeof(ngx_table_elt_t *)) != NGX_OK)
{
return NGX_ERROR;
}
}

- cc = ngx_list_push(&r->headers_out.headers);
- if (cc == NULL) {
+ h = ngx_list_push(&r->headers_out.headers);
+ if (h == NULL) {
return NGX_ERROR;
}

- cc->hash = 1;
- ngx_str_set(&cc->key, "Cache-Control");
- cc->value = *value;
+ h->hash = 1;
+ h->key = hv->key;
+ h->value = *value;

- ccp = ngx_array_push(&r->headers_out.cache_control);
- if (ccp == NULL) {
+ ph = ngx_array_push(pa);
+ if (ph == NULL) {
return NGX_ERROR;
}

- *ccp = cc;
+ *ph = h;

return NGX_OK;
}
diff -r 573f20116163 -r 6ba68ad8b24c src/http/ngx_http_request.h
--- a/src/http/ngx_http_request.h Wed Feb 07 16:44:29 2018 +0300
+++ b/src/http/ngx_http_request.h Thu Feb 08 09:54:18 2018 +0300
@@ -279,6 +279,7 @@ typedef struct {
ngx_uint_t content_type_hash;

ngx_array_t cache_control;
+ ngx_array_t link;

off_t content_length_n;
off_t content_offset;
diff -r 573f20116163 -r 6ba68ad8b24c src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c Wed Feb 07 16:44:29 2018 +0300
+++ b/src/http/ngx_http_upstream.c Thu Feb 08 09:54:18 2018 +0300
@@ -284,6 +284,11 @@ static ngx_http_upstream_header_t ngx_h
ngx_http_upstream_process_vary, 0,
ngx_http_upstream_copy_header_line, 0, 0 },

+ { ngx_string("Link"),
+ ngx_http_upstream_ignore_header_line, 0,
+ ngx_http_upstream_copy_multi_header_lines,
+ offsetof(ngx_http_headers_out_t, link), 0 },
+
{ ngx_string("X-Accel-Expires"),
ngx_http_upstream_process_accel_expires, 0,
ngx_http_upstream_copy_header_line, 0, 0 },
diff -r 573f20116163 -r 6ba68ad8b24c src/http/ngx_http_variables.c
--- a/src/http/ngx_http_variables.c Wed Feb 07 16:44:29 2018 +0300
+++ b/src/http/ngx_http_variables.c Thu Feb 08 09:54:18 2018 +0300
@@ -318,6 +318,9 @@ static ngx_http_variable_t ngx_http_cor
{ ngx_string("sent_http_cache_control"), NULL, ngx_http_variable_headers,
offsetof(ngx_http_request_t, headers_out.cache_control), 0, 0 },

+ { ngx_string("sent_http_link"), NULL, ngx_http_variable_headers,
+ offsetof(ngx_http_request_t, headers_out.link), 0, 0 },
+
{ ngx_string("limit_rate"), ngx_http_variable_request_set_size,
ngx_http_variable_request_get_size,
offsetof(ngx_http_request_t, limit_rate),
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Basic support of the Link response header.

ru@nginx.com 736 February 08, 2018 02:00AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 307
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready