forked from Hakase/nginx-build
Latest update - 7208
This commit is contained in:
@@ -95,7 +95,8 @@ auto/configure \
|
||||
|
||||
|
||||
### OpenSSL Skip
|
||||
#touch lib/openssl-1.1.0g/.openssl/include/openssl/ssl.h
|
||||
### Do not use it for the FIRST BUILD.
|
||||
#touch lib/openssl/.openssl/include/openssl/ssl.h
|
||||
|
||||
### Install
|
||||
make $BUILD_MTS install
|
||||
|
||||
@@ -436,6 +436,7 @@ if [ $HTTP = YES ]; then
|
||||
|
||||
if [ $HTTP_V2 = YES ]; then
|
||||
have=NGX_HTTP_V2 . auto/have
|
||||
have=NGX_HTTP_HEADERS . auto/have
|
||||
|
||||
ngx_module_name=ngx_http_v2_module
|
||||
ngx_module_incs=src/http/v2
|
||||
|
||||
@@ -31,6 +31,7 @@ struct ngx_shm_zone_s {
|
||||
ngx_shm_t shm;
|
||||
ngx_shm_zone_init_pt init;
|
||||
void *tag;
|
||||
void *sync;
|
||||
ngx_uint_t noreuse; /* unsigned noreuse:1; */
|
||||
};
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ ngx_http_header_t ngx_http_headers_in[] = {
|
||||
offsetof(ngx_http_headers_in_t, upgrade),
|
||||
ngx_http_process_header_line },
|
||||
|
||||
#if (NGX_HTTP_GZIP)
|
||||
#if (NGX_HTTP_GZIP || NGX_HTTP_HEADERS)
|
||||
{ ngx_string("Accept-Encoding"),
|
||||
offsetof(ngx_http_headers_in_t, accept_encoding),
|
||||
ngx_http_process_header_line },
|
||||
|
||||
@@ -200,7 +200,7 @@ typedef struct {
|
||||
ngx_table_elt_t *expect;
|
||||
ngx_table_elt_t *upgrade;
|
||||
|
||||
#if (NGX_HTTP_GZIP)
|
||||
#if (NGX_HTTP_GZIP || NGX_HTTP_HEADERS)
|
||||
ngx_table_elt_t *accept_encoding;
|
||||
ngx_table_elt_t *via;
|
||||
#endif
|
||||
|
||||
+146
-68
@@ -11,6 +11,14 @@
|
||||
#include <ngx_http_v2_module.h>
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_str_t name;
|
||||
ngx_uint_t offset;
|
||||
ngx_uint_t hash;
|
||||
ngx_http_header_t *hh;
|
||||
} ngx_http_v2_parse_header_t;
|
||||
|
||||
|
||||
/* errors */
|
||||
#define NGX_HTTP_V2_NO_ERROR 0x0
|
||||
#define NGX_HTTP_V2_PROTOCOL_ERROR 0x1
|
||||
@@ -156,6 +164,8 @@ static ngx_int_t ngx_http_v2_parse_scheme(ngx_http_request_t *r,
|
||||
ngx_str_t *value);
|
||||
static ngx_int_t ngx_http_v2_parse_authority(ngx_http_request_t *r,
|
||||
ngx_str_t *value);
|
||||
static ngx_int_t ngx_http_v2_parse_header(ngx_http_request_t *r,
|
||||
ngx_http_v2_parse_header_t *header, ngx_str_t *value);
|
||||
static ngx_int_t ngx_http_v2_construct_request_line(ngx_http_request_t *r);
|
||||
static ngx_int_t ngx_http_v2_cookie(ngx_http_request_t *r,
|
||||
ngx_http_v2_header_t *header);
|
||||
@@ -201,6 +211,23 @@ static ngx_http_v2_handler_pt ngx_http_v2_frame_states[] = {
|
||||
(sizeof(ngx_http_v2_frame_states) / sizeof(ngx_http_v2_handler_pt))
|
||||
|
||||
|
||||
static ngx_http_v2_parse_header_t ngx_http_v2_parse_headers[] = {
|
||||
{ ngx_string("host"),
|
||||
offsetof(ngx_http_headers_in_t, host), 0, NULL },
|
||||
|
||||
{ ngx_string("accept-encoding"),
|
||||
offsetof(ngx_http_headers_in_t, accept_encoding), 0, NULL },
|
||||
|
||||
{ ngx_string("accept-language"),
|
||||
offsetof(ngx_http_headers_in_t, accept_language), 0, NULL },
|
||||
|
||||
{ ngx_string("user-agent"),
|
||||
offsetof(ngx_http_headers_in_t, user_agent), 0, NULL },
|
||||
|
||||
{ ngx_null_string, 0, 0, NULL }
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
ngx_http_v2_init(ngx_event_t *rev)
|
||||
{
|
||||
@@ -2527,21 +2554,52 @@ ngx_http_v2_parse_int(ngx_http_v2_connection_t *h2c, u_char **pos, u_char *end,
|
||||
}
|
||||
|
||||
|
||||
ngx_int_t
|
||||
ngx_http_v2_push_stream(ngx_http_v2_connection_t *h2c, ngx_uint_t depend,
|
||||
size_t request_length, ngx_str_t *path, ngx_str_t *authority)
|
||||
ngx_http_v2_stream_t *
|
||||
ngx_http_v2_push_stream(ngx_http_v2_stream_t *parent, ngx_str_t *path)
|
||||
{
|
||||
ngx_int_t rc;
|
||||
ngx_str_t value;
|
||||
ngx_connection_t *fc;
|
||||
ngx_http_request_t *r;
|
||||
ngx_http_v2_node_t *node;
|
||||
ngx_http_v2_stream_t *stream;
|
||||
ngx_int_t rc;
|
||||
ngx_str_t value;
|
||||
ngx_pool_t *pool;
|
||||
ngx_uint_t index;
|
||||
ngx_table_elt_t **h;
|
||||
ngx_connection_t *fc;
|
||||
ngx_http_request_t *r;
|
||||
ngx_http_v2_node_t *node;
|
||||
ngx_http_v2_stream_t *stream;
|
||||
ngx_http_v2_srv_conf_t *h2scf;
|
||||
ngx_http_v2_connection_t *h2c;
|
||||
ngx_http_v2_parse_header_t *header;
|
||||
|
||||
h2c = parent->connection;
|
||||
|
||||
pool = ngx_create_pool(1024, h2c->connection->log);
|
||||
if (pool == NULL) {
|
||||
goto rst_stream;
|
||||
}
|
||||
|
||||
node = ngx_http_v2_get_node_by_id(h2c, h2c->last_push, 1);
|
||||
|
||||
if (node == NULL) {
|
||||
return NGX_ERROR;
|
||||
ngx_destroy_pool(pool);
|
||||
goto rst_stream;
|
||||
}
|
||||
|
||||
stream = ngx_http_v2_create_stream(h2c, 1);
|
||||
if (stream == NULL) {
|
||||
|
||||
if (node->parent == NULL) {
|
||||
h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
|
||||
ngx_http_v2_module);
|
||||
|
||||
index = ngx_http_v2_index(h2scf, h2c->last_push);
|
||||
h2c->streams_index[index] = node->index;
|
||||
|
||||
ngx_queue_insert_tail(&h2c->closed, &node->reuse);
|
||||
h2c->closed_nodes++;
|
||||
}
|
||||
|
||||
ngx_destroy_pool(pool);
|
||||
goto rst_stream;
|
||||
}
|
||||
|
||||
if (node->parent) {
|
||||
@@ -2549,21 +2607,11 @@ ngx_http_v2_push_stream(ngx_http_v2_connection_t *h2c, ngx_uint_t depend,
|
||||
h2c->closed_nodes--;
|
||||
}
|
||||
|
||||
stream = ngx_http_v2_create_stream(h2c, 1);
|
||||
if (stream == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
stream->pool = ngx_create_pool(1024, h2c->connection->log);
|
||||
if (stream->pool == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
stream->pool = pool;
|
||||
|
||||
r = stream->request;
|
||||
fc = r->connection;
|
||||
|
||||
r->request_length = request_length;
|
||||
|
||||
stream->in_closed = 1;
|
||||
stream->node = node;
|
||||
|
||||
@@ -2572,10 +2620,10 @@ ngx_http_v2_push_stream(ngx_http_v2_connection_t *h2c, ngx_uint_t depend,
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
|
||||
"http2 push stream sid:%ui "
|
||||
"depends on %ui excl:0 weight:16",
|
||||
h2c->last_push, depend);
|
||||
h2c->last_push, parent->node->id);
|
||||
|
||||
node->weight = NGX_HTTP_V2_DEFAULT_WEIGHT;
|
||||
ngx_http_v2_set_dependency(h2c, node, depend, 0);
|
||||
ngx_http_v2_set_dependency(h2c, node, parent->node->id, 0);
|
||||
|
||||
r->method_name = ngx_http_core_get_method;
|
||||
r->method = NGX_HTTP_GET;
|
||||
@@ -2592,51 +2640,77 @@ ngx_http_v2_push_stream(ngx_http_v2_connection_t *h2c, ngx_uint_t depend,
|
||||
r->schema_end = r->schema_start + 4;
|
||||
}
|
||||
|
||||
value.len = authority->len;
|
||||
|
||||
value.data = ngx_pstrdup(stream->pool, authority);
|
||||
value.data = ngx_pstrdup(pool, path);
|
||||
if (value.data == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
rc = ngx_http_v2_parse_authority(r, &value);
|
||||
|
||||
if (rc != NGX_OK) {
|
||||
goto error;
|
||||
goto close;
|
||||
}
|
||||
|
||||
value.len = path->len;
|
||||
|
||||
value.data = ngx_pstrdup(stream->pool, path);
|
||||
if (value.data == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
rc = ngx_http_v2_parse_path(r, &value);
|
||||
|
||||
if (rc != NGX_OK) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
for (header = ngx_http_v2_parse_headers; header->name.len; header++) {
|
||||
h = (ngx_table_elt_t **)
|
||||
((char *) &parent->request->headers_in + header->offset);
|
||||
|
||||
if (*h == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
value.len = (*h)->value.len;
|
||||
|
||||
value.data = ngx_pnalloc(pool, value.len + 1);
|
||||
if (value.data == NULL) {
|
||||
goto close;
|
||||
}
|
||||
|
||||
ngx_memcpy(value.data, (*h)->value.data, value.len);
|
||||
value.data[value.len] = '\0';
|
||||
|
||||
rc = ngx_http_v2_parse_header(r, header, &value);
|
||||
|
||||
if (rc != NGX_OK) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
fc->write->handler = ngx_http_v2_run_request_handler;
|
||||
ngx_post_event(fc->write, &ngx_posted_events);
|
||||
|
||||
return NGX_OK;
|
||||
return stream;
|
||||
|
||||
error:
|
||||
|
||||
if (rc == NGX_ABORT) {
|
||||
return NGX_ERROR;
|
||||
/* header handler has already finalized request */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (rc == NGX_DECLINED) {
|
||||
ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
|
||||
return NGX_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
(void) ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
|
||||
close:
|
||||
|
||||
return NGX_ERROR;
|
||||
ngx_http_v2_close_stream(stream, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
||||
|
||||
return NULL;
|
||||
|
||||
rst_stream:
|
||||
|
||||
if (ngx_http_v2_send_rst_stream(h2c, h2c->last_push,
|
||||
NGX_HTTP_INTERNAL_SERVER_ERROR)
|
||||
!= NGX_OK)
|
||||
{
|
||||
h2c->connection->error = 1;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -3449,41 +3523,45 @@ ngx_http_v2_parse_scheme(ngx_http_request_t *r, ngx_str_t *value)
|
||||
static ngx_int_t
|
||||
ngx_http_v2_parse_authority(ngx_http_request_t *r, ngx_str_t *value)
|
||||
{
|
||||
ngx_table_elt_t *h;
|
||||
ngx_http_header_t *hh;
|
||||
ngx_http_core_main_conf_t *cmcf;
|
||||
return ngx_http_v2_parse_header(r, &ngx_http_v2_parse_headers[0], value);
|
||||
}
|
||||
|
||||
static ngx_str_t host = ngx_string("host");
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_v2_parse_header(ngx_http_request_t *r,
|
||||
ngx_http_v2_parse_header_t *header, ngx_str_t *value)
|
||||
{
|
||||
ngx_table_elt_t *h;
|
||||
ngx_http_core_main_conf_t *cmcf;
|
||||
|
||||
h = ngx_list_push(&r->headers_in.headers);
|
||||
if (h == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
h->hash = ngx_hash_key(host.data, host.len);
|
||||
h->key.len = header->name.len;
|
||||
h->key.data = header->name.data;
|
||||
h->lowcase_key = header->name.data;
|
||||
|
||||
h->key.len = host.len;
|
||||
h->key.data = host.data;
|
||||
if (header->hh == NULL) {
|
||||
header->hash = ngx_hash_key(header->name.data, header->name.len);
|
||||
|
||||
cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
|
||||
|
||||
header->hh = ngx_hash_find(&cmcf->headers_in_hash, header->hash,
|
||||
h->lowcase_key, h->key.len);
|
||||
if (header->hh == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
h->hash = header->hash;
|
||||
|
||||
h->value.len = value->len;
|
||||
h->value.data = value->data;
|
||||
|
||||
h->lowcase_key = host.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_host()
|
||||
*/
|
||||
if (header->hh->handler(r, h, header->hh->offset) != NGX_OK) {
|
||||
/* header handler has already finalized request */
|
||||
return NGX_ABORT;
|
||||
}
|
||||
|
||||
@@ -3875,8 +3953,8 @@ ngx_http_v2_process_request_body(ngx_http_request_t *r, u_char *pos,
|
||||
} else {
|
||||
if (size > (size_t) (buf->end - buf->last)) {
|
||||
ngx_log_error(NGX_LOG_INFO, fc->log, 0,
|
||||
"client intended to send body data "
|
||||
"larger than declared");
|
||||
"client intended to send body data "
|
||||
"larger than declared");
|
||||
|
||||
return NGX_HTTP_BAD_REQUEST;
|
||||
}
|
||||
|
||||
@@ -336,9 +336,8 @@ void ngx_http_v2_init(ngx_event_t *rev);
|
||||
ngx_int_t ngx_http_v2_read_request_body(ngx_http_request_t *r);
|
||||
ngx_int_t ngx_http_v2_read_unbuffered_request_body(ngx_http_request_t *r);
|
||||
|
||||
ngx_int_t ngx_http_v2_push_stream(ngx_http_v2_connection_t *h2c,
|
||||
ngx_uint_t depend, size_t request_length, ngx_str_t *path,
|
||||
ngx_str_t *authority);
|
||||
ngx_http_v2_stream_t *ngx_http_v2_push_stream(ngx_http_v2_stream_t *parent,
|
||||
ngx_str_t *path);
|
||||
|
||||
void ngx_http_v2_close_stream(ngx_http_v2_stream_t *stream, ngx_int_t rc);
|
||||
|
||||
|
||||
@@ -45,19 +45,48 @@
|
||||
#define NGX_HTTP_V2_STATUS_404_INDEX 13
|
||||
#define NGX_HTTP_V2_STATUS_500_INDEX 14
|
||||
|
||||
#define NGX_HTTP_V2_ACCEPT_ENCODING_INDEX 16
|
||||
#define NGX_HTTP_V2_ACCEPT_LANGUAGE_INDEX 17
|
||||
#define NGX_HTTP_V2_CONTENT_LENGTH_INDEX 28
|
||||
#define NGX_HTTP_V2_CONTENT_TYPE_INDEX 31
|
||||
#define NGX_HTTP_V2_DATE_INDEX 33
|
||||
#define NGX_HTTP_V2_LAST_MODIFIED_INDEX 44
|
||||
#define NGX_HTTP_V2_LOCATION_INDEX 46
|
||||
#define NGX_HTTP_V2_SERVER_INDEX 54
|
||||
#define NGX_HTTP_V2_USER_AGENT_INDEX 58
|
||||
#define NGX_HTTP_V2_VARY_INDEX 59
|
||||
|
||||
#define NGX_HTTP_V2_NO_TRAILERS (ngx_http_v2_out_frame_t *) -1
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_str_t name;
|
||||
u_char index;
|
||||
ngx_uint_t offset;
|
||||
} ngx_http_v2_push_header_t;
|
||||
|
||||
|
||||
static ngx_http_v2_push_header_t ngx_http_v2_push_headers[] = {
|
||||
{ ngx_string(":authority"), NGX_HTTP_V2_AUTHORITY_INDEX,
|
||||
offsetof(ngx_http_headers_in_t, host) },
|
||||
|
||||
{ ngx_string("accept-encoding"), NGX_HTTP_V2_ACCEPT_ENCODING_INDEX,
|
||||
offsetof(ngx_http_headers_in_t, accept_encoding) },
|
||||
|
||||
{ ngx_string("accept-language"), NGX_HTTP_V2_ACCEPT_LANGUAGE_INDEX,
|
||||
offsetof(ngx_http_headers_in_t, accept_language) },
|
||||
|
||||
{ ngx_string("user-agent"), NGX_HTTP_V2_USER_AGENT_INDEX,
|
||||
offsetof(ngx_http_headers_in_t, user_agent) },
|
||||
};
|
||||
|
||||
#define NGX_HTTP_V2_PUSH_HEADERS \
|
||||
(sizeof(ngx_http_v2_push_headers) / sizeof(ngx_http_v2_push_header_t))
|
||||
|
||||
|
||||
static ngx_int_t ngx_http_v2_push_resources(ngx_http_request_t *r);
|
||||
static ngx_int_t ngx_http_v2_push_resource(ngx_http_request_t *r,
|
||||
ngx_str_t *path, ngx_str_t *authority);
|
||||
ngx_str_t *path, ngx_str_t *binary);
|
||||
|
||||
u_char *ngx_http_v2_string_encode(u_char *dst, u_char *src, size_t len,
|
||||
u_char *tmp, ngx_uint_t lower);
|
||||
@@ -606,15 +635,17 @@ ngx_http_v2_push_resources(ngx_http_request_t *r)
|
||||
{
|
||||
u_char *start, *end, *last;
|
||||
ngx_int_t rc;
|
||||
ngx_str_t path, authority;
|
||||
ngx_str_t path;
|
||||
ngx_uint_t i, push;
|
||||
ngx_table_elt_t **h;
|
||||
ngx_http_v2_loc_conf_t *h2lcf;
|
||||
ngx_http_complex_value_t *pushes;
|
||||
ngx_str_t binary[NGX_HTTP_V2_PUSH_HEADERS];
|
||||
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||
"http2 push resources");
|
||||
ngx_str_null(&authority);
|
||||
|
||||
ngx_memzero(binary, NGX_HTTP_V2_PUSH_HEADERS * sizeof(ngx_str_t));
|
||||
|
||||
h2lcf = ngx_http_get_module_loc_conf(r, ngx_http_v2_module);
|
||||
|
||||
@@ -634,7 +665,7 @@ ngx_http_v2_push_resources(ngx_http_request_t *r)
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = ngx_http_v2_push_resource(r, &path, &authority);
|
||||
rc = ngx_http_v2_push_resource(r, &path, binary);
|
||||
|
||||
if (rc == NGX_ERROR) {
|
||||
return NGX_ERROR;
|
||||
@@ -799,7 +830,7 @@ ngx_http_v2_push_resources(ngx_http_request_t *r)
|
||||
if (push && path.len
|
||||
&& !(path.len > 1 && path.data[0] == '/' && path.data[1] == '/'))
|
||||
{
|
||||
rc = ngx_http_v2_push_resource(r, &path, &authority);
|
||||
rc = ngx_http_v2_push_resource(r, &path, binary);
|
||||
|
||||
if (rc == NGX_ERROR) {
|
||||
return NGX_ERROR;
|
||||
@@ -824,15 +855,18 @@ ngx_http_v2_push_resources(ngx_http_request_t *r)
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_v2_push_resource(ngx_http_request_t *r, ngx_str_t *path,
|
||||
ngx_str_t *authority)
|
||||
ngx_str_t *binary)
|
||||
{
|
||||
u_char *start, *pos, *tmp;
|
||||
size_t len;
|
||||
ngx_table_elt_t *host;
|
||||
ngx_connection_t *fc;
|
||||
ngx_http_v2_stream_t *stream;
|
||||
ngx_http_v2_out_frame_t *frame;
|
||||
ngx_http_v2_connection_t *h2c;
|
||||
u_char *start, *pos, *tmp;
|
||||
size_t len;
|
||||
ngx_str_t *value;
|
||||
ngx_uint_t i;
|
||||
ngx_table_elt_t **h;
|
||||
ngx_connection_t *fc;
|
||||
ngx_http_v2_stream_t *stream;
|
||||
ngx_http_v2_out_frame_t *frame;
|
||||
ngx_http_v2_connection_t *h2c;
|
||||
ngx_http_v2_push_header_t *ph;
|
||||
|
||||
fc = r->connection;
|
||||
|
||||
@@ -848,8 +882,8 @@ ngx_http_v2_push_resource(ngx_http_request_t *r, ngx_str_t *path,
|
||||
}
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
|
||||
"http2 pushing:%ui limit:%ui",
|
||||
h2c->pushing, h2c->concurrent_pushes);
|
||||
"http2 pushing:%ui limit:%ui",
|
||||
h2c->pushing, h2c->concurrent_pushes);
|
||||
|
||||
if (h2c->pushing >= h2c->concurrent_pushes) {
|
||||
return NGX_ABORT;
|
||||
@@ -863,42 +897,70 @@ ngx_http_v2_push_resource(ngx_http_request_t *r, ngx_str_t *path,
|
||||
return NGX_DECLINED;
|
||||
}
|
||||
|
||||
host = r->headers_in.host;
|
||||
|
||||
if (host == NULL) {
|
||||
if (r->headers_in.host == NULL) {
|
||||
return NGX_ABORT;
|
||||
}
|
||||
|
||||
if (authority->len == 0) {
|
||||
ph = ngx_http_v2_push_headers;
|
||||
|
||||
len = 1 + NGX_HTTP_V2_INT_OCTETS + host->value.len;
|
||||
|
||||
tmp = ngx_palloc(r->pool, len);
|
||||
pos = ngx_pnalloc(r->pool, len);
|
||||
|
||||
if (pos == NULL || tmp == NULL) {
|
||||
if (binary[0].len) {
|
||||
tmp = ngx_palloc(r->pool, path->len);
|
||||
if (tmp == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
authority->data = pos;
|
||||
} else {
|
||||
len = path->len;
|
||||
|
||||
*pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_AUTHORITY_INDEX);
|
||||
pos = ngx_http_v2_write_value(pos, host->value.data, host->value.len,
|
||||
tmp);
|
||||
for (i = 0; i < NGX_HTTP_V2_PUSH_HEADERS; i++) {
|
||||
h = (ngx_table_elt_t **) ((char *) &r->headers_in + ph[i].offset);
|
||||
|
||||
authority->len = pos - authority->data;
|
||||
if (*h) {
|
||||
len = ngx_max(len, (*h)->value.len);
|
||||
}
|
||||
}
|
||||
|
||||
tmp = ngx_palloc(r->pool, len);
|
||||
if (tmp == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
for (i = 0; i < NGX_HTTP_V2_PUSH_HEADERS; i++) {
|
||||
h = (ngx_table_elt_t **) ((char *) &r->headers_in + ph[i].offset);
|
||||
|
||||
if (*h == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
value = &(*h)->value;
|
||||
|
||||
len = 1 + NGX_HTTP_V2_INT_OCTETS + value->len;
|
||||
|
||||
pos = ngx_pnalloc(r->pool, len);
|
||||
if (pos == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
binary[i].data = pos;
|
||||
|
||||
*pos++ = ngx_http_v2_inc_indexed(ph[i].index);
|
||||
pos = ngx_http_v2_write_value(pos, value->data, value->len, tmp);
|
||||
|
||||
binary[i].len = pos - binary[i].data;
|
||||
}
|
||||
}
|
||||
|
||||
len = (h2c->table_update ? 1 : 0)
|
||||
+ 1
|
||||
+ 1 + NGX_HTTP_V2_INT_OCTETS + path->len
|
||||
+ authority->len
|
||||
+ 1;
|
||||
|
||||
tmp = ngx_palloc(r->pool, len);
|
||||
pos = ngx_pnalloc(r->pool, len);
|
||||
for (i = 0; i < NGX_HTTP_V2_PUSH_HEADERS; i++) {
|
||||
len += binary[i].len;
|
||||
}
|
||||
|
||||
if (pos == NULL || tmp == NULL) {
|
||||
pos = ngx_pnalloc(r->pool, len);
|
||||
if (pos == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
@@ -922,11 +984,6 @@ ngx_http_v2_push_resource(ngx_http_request_t *r, ngx_str_t *path,
|
||||
*pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_PATH_INDEX);
|
||||
pos = ngx_http_v2_write_value(pos, path->data, path->len, tmp);
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
|
||||
"http2 push header: \":authority: %V\"", &host->value);
|
||||
|
||||
pos = ngx_cpymem(pos, authority->data, authority->len);
|
||||
|
||||
#if (NGX_HTTP_SSL)
|
||||
if (fc->ssl) {
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0,
|
||||
@@ -941,6 +998,20 @@ ngx_http_v2_push_resource(ngx_http_request_t *r, ngx_str_t *path,
|
||||
*pos++ = ngx_http_v2_indexed(NGX_HTTP_V2_SCHEME_HTTP_INDEX);
|
||||
}
|
||||
|
||||
for (i = 0; i < NGX_HTTP_V2_PUSH_HEADERS; i++) {
|
||||
h = (ngx_table_elt_t **) ((char *) &r->headers_in + ph[i].offset);
|
||||
|
||||
if (*h == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, fc->log, 0,
|
||||
"http2 push header: \"%V: %V\"",
|
||||
&ph[i].name, &(*h)->value);
|
||||
|
||||
pos = ngx_cpymem(pos, binary[i].data, binary[i].len);
|
||||
}
|
||||
|
||||
frame = ngx_http_v2_create_push_frame(r, start, pos);
|
||||
if (frame == NULL) {
|
||||
return NGX_ERROR;
|
||||
@@ -950,8 +1021,14 @@ ngx_http_v2_push_resource(ngx_http_request_t *r, ngx_str_t *path,
|
||||
|
||||
stream->queued++;
|
||||
|
||||
return ngx_http_v2_push_stream(h2c, stream->node->id, pos - start,
|
||||
path, &host->value);
|
||||
stream = ngx_http_v2_push_stream(stream, path);
|
||||
|
||||
if (stream) {
|
||||
stream->request->request_length = pos - start;
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user