Created
August 20, 2015 02:41
-
-
Save flano-yuki/ad8e059208493db7436a to your computer and use it in GitHub Desktop.
$ diff -u -r ./nginx-1.9.3/src/http/v2/ ./nginx-1.9.4/src/htt p/v2/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -u -r ./nginx-1.9.3/src/http/v2/ngx_http_v2.c ./nginx-1.9.4/src/http/v2/ngx_http_v2.c | |
--- ./nginx-1.9.3/src/http/v2/ngx_http_v2.c 2015-08-16 14:32:49.654689058 +0900 | |
+++ ./nginx-1.9.4/src/http/v2/ngx_http_v2.c 2015-08-20 11:38:03.424522814 +0900 | |
@@ -169,9 +169,10 @@ | |
static ngx_int_t ngx_http_v2_parse_method(ngx_http_request_t *r); | |
static ngx_int_t ngx_http_v2_parse_scheme(ngx_http_request_t *r); | |
static ngx_int_t ngx_http_v2_parse_authority(ngx_http_request_t *r); | |
-static void ngx_http_v2_run_request(ngx_http_request_t *r); | |
static ngx_int_t ngx_http_v2_construct_request_line(ngx_http_request_t *r); | |
-static ngx_int_t ngx_http_v2_concatenate_cookie_header(ngx_http_request_t *r); | |
+static ngx_int_t ngx_http_v2_cookie(ngx_http_request_t *r); | |
+static ngx_int_t ngx_http_v2_construct_cookie_header(ngx_http_request_t *r); | |
+static void ngx_http_v2_run_request(ngx_http_request_t *r); | |
static ngx_int_t ngx_http_v2_init_request_body(ngx_http_request_t *r); | |
static ngx_int_t ngx_http_v2_terminate_stream(ngx_http_v2_connection_t *h2c, | |
@@ -1386,6 +1387,8 @@ | |
ngx_http_core_srv_conf_t *cscf; | |
ngx_http_core_main_conf_t *cmcf; | |
+ static ngx_str_t cookie = ngx_string("cookie"); | |
+ | |
r = h2c->state.stream->request; | |
if (h2c->state.parse_name) { | |
@@ -1433,6 +1436,16 @@ | |
return ngx_http_v2_state_header_complete(h2c, pos, end); | |
} | |
+ if ((size_t) (r->header_name_end - r->header_name_start) == cookie.len | |
+ && ngx_memcmp(r->header_name_start, cookie.data, cookie.len) == 0) | |
+ { | |
+ if (ngx_http_v2_cookie(r) != NGX_OK) { | |
+ // TODO | |
+ } | |
+ | |
+ return ngx_http_v2_state_header_complete(h2c, pos, end); | |
+ } | |
+ | |
h = ngx_list_push(&r->headers_in.headers); | |
if (h == NULL) { | |
return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR); | |
@@ -2338,6 +2351,7 @@ | |
return NULL; | |
} | |
+ r->http_version = NGX_HTTP_VERSION_20; | |
r->valid_location = 1; | |
fc->data = r; | |
@@ -2660,37 +2674,6 @@ | |
} | |
-static void | |
-ngx_http_v2_run_request(ngx_http_request_t *r) | |
-{ | |
- if (ngx_http_v2_construct_request_line(r) != NGX_OK) { | |
- return; | |
- } | |
- | |
- if (ngx_http_v2_concatenate_cookie_header(r) != NGX_OK) { | |
- return; | |
- } | |
- | |
- r->http_state = NGX_HTTP_PROCESS_REQUEST_STATE; | |
- | |
- if (ngx_http_process_request_header(r) != NGX_OK) { | |
- return; | |
- } | |
- | |
- if (r->headers_in.content_length_n > 0 && r->stream->in_closed) { | |
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, | |
- "client prematurely closed stream"); | |
- | |
- r->stream->skip_data = NGX_HTTP_V2_DATA_ERROR; | |
- | |
- ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST); | |
- return; | |
- } | |
- | |
- ngx_http_process_request(r); | |
-} | |
- | |
- | |
static ngx_int_t | |
ngx_http_v2_construct_request_line(ngx_http_request_t *r) | |
{ | |
@@ -2736,28 +2719,62 @@ | |
static ngx_int_t | |
-ngx_http_v2_concatenate_cookie_header(ngx_http_request_t *r) | |
+ngx_http_v2_cookie(ngx_http_request_t *r) | |
+{ | |
+ ngx_str_t *val; | |
+ ngx_array_t *cookies; | |
+ | |
+ cookies = r->stream->cookies; | |
+ | |
+ if (cookies == NULL) { | |
+ cookies = ngx_array_create(r->pool, 2, sizeof(ngx_str_t)); | |
+ if (cookies == NULL) { | |
+ return NGX_ERROR; | |
+ } | |
+ | |
+ r->stream->cookies = cookies; | |
+ } | |
+ | |
+ val = ngx_array_push(cookies); | |
+ if (val == NULL) { | |
+ return NGX_ERROR; | |
+ } | |
+ | |
+ val->len = r->header_end - r->header_start; | |
+ val->data = r->header_start; | |
+ | |
+ return NGX_OK; | |
+} | |
+ | |
+ | |
+static ngx_int_t | |
+ngx_http_v2_construct_cookie_header(ngx_http_request_t *r) | |
{ | |
- size_t len; | |
- u_char *p, *end, *buf; | |
- ngx_uint_t i; | |
- ngx_array_t *a; | |
- ngx_table_elt_t **h; | |
+ u_char *buf, *p, *end; | |
+ size_t len; | |
+ ngx_str_t *vals; | |
+ ngx_uint_t i; | |
+ ngx_array_t *cookies; | |
+ ngx_table_elt_t *h; | |
+ ngx_http_header_t *hh; | |
+ ngx_http_core_main_conf_t *cmcf; | |
+ | |
+ static ngx_str_t cookie = ngx_string("cookie"); | |
- a = &r->headers_in.cookies; | |
+ cookies = r->stream->cookies; | |
- if (a->nelts <= 1) { | |
+ if (cookies == NULL) { | |
return NGX_OK; | |
} | |
- h = a->elts; | |
+ vals = cookies->elts; | |
i = 0; | |
len = 0; | |
do { | |
- len += h[i]->value.len + 2; | |
- } while (++i != a->nelts); | |
+ len += vals[i].len + 2; | |
+ } while (++i != cookies->nelts); | |
len -= 2; | |
@@ -2772,7 +2789,7 @@ | |
for (i = 0; /* void */ ; i++) { | |
- p = ngx_cpymem(p, h[i]->value.data, h[i]->value.len); | |
+ p = ngx_cpymem(p, vals[i].data, vals[i].len); | |
if (p == end) { | |
*p = '\0'; | |
@@ -2782,15 +2799,73 @@ | |
*p++ = ';'; *p++ = ' '; | |
} | |
- h[0]->value.len = len; | |
- h[0]->value.data = buf; | |
+ h = ngx_list_push(&r->headers_in.headers); | |
+ if (h == NULL) { | |
+ return NGX_ERROR; | |
+ } | |
- a->nelts = 1; | |
+ h->hash = ngx_hash_key(cookie.data, cookie.len); | |
+ | |
+ h->key.len = cookie.len; | |
+ h->key.data = cookie.data; | |
+ | |
+ h->value.len = len; | |
+ h->value.data = buf; | |
+ | |
+ h->lowcase_key = cookie.data; | |
+ | |
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
+ | |
+ hh = ngx_hash_find(&cmcf->headers_in_hash, h->hash, | |
+ h->lowcase_key, h->key.len); | |
+ | |
+ if (hh == NULL) { | |
+ return NGX_ERROR; | |
+ } | |
+ | |
+ if (hh->handler(r, h, hh->offset) != NGX_OK) { | |
+ /* | |
+ * request has been finalized already | |
+ * in ngx_http_process_multi_header_lines() | |
+ */ | |
+ return NGX_ABORT; | |
+ } | |
return NGX_OK; | |
} | |
+static void | |
+ngx_http_v2_run_request(ngx_http_request_t *r) | |
+{ | |
+ if (ngx_http_v2_construct_request_line(r) != NGX_OK) { | |
+ return; | |
+ } | |
+ | |
+ if (ngx_http_v2_construct_cookie_header(r) != NGX_OK) { | |
+ return; | |
+ } | |
+ | |
+ r->http_state = NGX_HTTP_PROCESS_REQUEST_STATE; | |
+ | |
+ if (ngx_http_process_request_header(r) != NGX_OK) { | |
+ return; | |
+ } | |
+ | |
+ if (r->headers_in.content_length_n > 0 && r->stream->in_closed) { | |
+ ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, | |
+ "client prematurely closed stream"); | |
+ | |
+ r->stream->skip_data = NGX_HTTP_V2_DATA_ERROR; | |
+ | |
+ ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST); | |
+ return; | |
+ } | |
+ | |
+ ngx_http_process_request(r); | |
+} | |
+ | |
+ | |
static ngx_int_t | |
ngx_http_v2_init_request_body(ngx_http_request_t *r) | |
{ | |
diff -u -r ./nginx-1.9.3/src/http/v2/ngx_http_v2_filter_module.c ./nginx-1.9.4/src/http/v2/ngx_http_v2_filter_module.c | |
--- ./nginx-1.9.3/src/http/v2/ngx_http_v2_filter_module.c 2015-08-16 14:32:49.654689058 +0900 | |
+++ ./nginx-1.9.4/src/http/v2/ngx_http_v2_filter_module.c 2015-08-20 11:38:03.424522814 +0900 | |
@@ -309,7 +309,7 @@ | |
#if (NGX_HTTP_SSL) | |
if (fc->ssl) { | |
- *p++ ='s'; | |
+ *p++ = 's'; | |
} | |
#endif | |
diff -u -r ./nginx-1.9.3/src/http/v2/ngx_http_v2.h ./nginx-1.9.4/src/http/v2/ngx_http_v2.h | |
--- ./nginx-1.9.3/src/http/v2/ngx_http_v2.h 2015-08-16 14:32:49.654689058 +0900 | |
+++ ./nginx-1.9.4/src/http/v2/ngx_http_v2.h 2015-08-20 11:38:03.424522814 +0900 | |
@@ -158,6 +158,8 @@ | |
ngx_queue_t queue; | |
+ ngx_array_t *cookies; | |
+ | |
unsigned handled:1; | |
unsigned blocked:1; | |
unsigned exhausted:1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment