Latest update - 9121
This commit is contained in:
@@ -423,7 +423,6 @@ 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
|
||||
@@ -444,7 +443,6 @@ if [ $HTTP = YES ]; then
|
||||
HTTP_SSL=YES
|
||||
|
||||
have=NGX_HTTP_V3 . auto/have
|
||||
have=NGX_HTTP_HEADERS . auto/have
|
||||
|
||||
ngx_module_name=ngx_http_v3_module
|
||||
ngx_module_incs=src/http/v3
|
||||
|
||||
@@ -43,8 +43,6 @@ static char *ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf,
|
||||
static ngx_int_t ngx_http_ssl_compile_certificates(ngx_conf_t *cf,
|
||||
ngx_http_ssl_srv_conf_t *conf);
|
||||
|
||||
static char *ngx_http_ssl_enable(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
static char *ngx_http_ssl_password_file(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
static char *ngx_http_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
@@ -90,24 +88,12 @@ static ngx_conf_enum_t ngx_http_ssl_ocsp[] = {
|
||||
};
|
||||
|
||||
|
||||
static ngx_conf_deprecated_t ngx_http_ssl_deprecated = {
|
||||
ngx_conf_deprecated, "ssl", "listen ... ssl"
|
||||
};
|
||||
|
||||
|
||||
static ngx_conf_post_t ngx_http_ssl_conf_command_post =
|
||||
{ ngx_http_ssl_conf_command_check };
|
||||
|
||||
|
||||
static ngx_command_t ngx_http_ssl_commands[] = {
|
||||
|
||||
{ ngx_string("ssl"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
||||
ngx_http_ssl_enable,
|
||||
NGX_HTTP_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_http_ssl_srv_conf_t, enable),
|
||||
&ngx_http_ssl_deprecated },
|
||||
|
||||
{ ngx_string("ssl_certificate"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_str_array_slot,
|
||||
@@ -470,6 +456,9 @@ ngx_http_ssl_alpn_select(ngx_ssl_conn_t *ssl_conn, const unsigned char **out,
|
||||
#if (NGX_HTTP_V2 || NGX_HTTP_V3)
|
||||
ngx_http_connection_t *hc;
|
||||
#endif
|
||||
#if (NGX_HTTP_V2)
|
||||
ngx_http_v2_srv_conf_t *h2scf;
|
||||
#endif
|
||||
#if (NGX_HTTP_V3)
|
||||
ngx_http_v3_srv_conf_t *h3scf;
|
||||
#endif
|
||||
@@ -491,12 +480,6 @@ ngx_http_ssl_alpn_select(ngx_ssl_conn_t *ssl_conn, const unsigned char **out,
|
||||
hc = c->data;
|
||||
#endif
|
||||
|
||||
#if (NGX_HTTP_V2)
|
||||
if (hc->addr_conf->http2) {
|
||||
srv = (unsigned char *) NGX_HTTP_V2_ALPN_PROTO NGX_HTTP_ALPN_PROTOS;
|
||||
srvlen = sizeof(NGX_HTTP_V2_ALPN_PROTO NGX_HTTP_ALPN_PROTOS) - 1;
|
||||
} else
|
||||
#endif
|
||||
#if (NGX_HTTP_V3)
|
||||
if (hc->addr_conf->quic) {
|
||||
|
||||
@@ -523,8 +506,19 @@ ngx_http_ssl_alpn_select(ngx_ssl_conn_t *ssl_conn, const unsigned char **out,
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
srv = (unsigned char *) NGX_HTTP_ALPN_PROTOS;
|
||||
srvlen = sizeof(NGX_HTTP_ALPN_PROTOS) - 1;
|
||||
#if (NGX_HTTP_V2)
|
||||
h2scf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_v2_module);
|
||||
|
||||
if (h2scf->enable || hc->addr_conf->http2) {
|
||||
srv = (unsigned char *) NGX_HTTP_V2_ALPN_PROTO NGX_HTTP_ALPN_PROTOS;
|
||||
srvlen = sizeof(NGX_HTTP_V2_ALPN_PROTO NGX_HTTP_ALPN_PROTOS) - 1;
|
||||
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
srv = (unsigned char *) NGX_HTTP_ALPN_PROTOS;
|
||||
srvlen = sizeof(NGX_HTTP_ALPN_PROTOS) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (SSL_select_next_proto((unsigned char **) out, outlen, srv, srvlen,
|
||||
@@ -652,7 +646,6 @@ ngx_http_ssl_create_srv_conf(ngx_conf_t *cf)
|
||||
* sscf->stapling_responder = { 0, NULL };
|
||||
*/
|
||||
|
||||
sscf->enable = NGX_CONF_UNSET;
|
||||
sscf->prefer_server_ciphers = NGX_CONF_UNSET;
|
||||
sscf->early_data = NGX_CONF_UNSET;
|
||||
sscf->reject_handshake = NGX_CONF_UNSET;
|
||||
@@ -689,17 +682,6 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
|
||||
ngx_pool_cleanup_t *cln;
|
||||
|
||||
if (conf->enable == NGX_CONF_UNSET) {
|
||||
if (prev->enable == NGX_CONF_UNSET) {
|
||||
conf->enable = 0;
|
||||
|
||||
} else {
|
||||
conf->enable = prev->enable;
|
||||
conf->file = prev->file;
|
||||
conf->line = prev->line;
|
||||
}
|
||||
}
|
||||
|
||||
ngx_conf_merge_value(conf->session_timeout,
|
||||
prev->session_timeout, 86400);
|
||||
|
||||
@@ -766,37 +748,7 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
|
||||
conf->ssl.log = cf->log;
|
||||
|
||||
if (conf->enable) {
|
||||
|
||||
if (conf->certificates) {
|
||||
if (conf->certificate_keys == NULL) {
|
||||
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
||||
"no \"ssl_certificate_key\" is defined for "
|
||||
"the \"ssl\" directive in %s:%ui",
|
||||
conf->file, conf->line);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
if (conf->certificate_keys->nelts < conf->certificates->nelts) {
|
||||
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
||||
"no \"ssl_certificate_key\" is defined "
|
||||
"for certificate \"%V\" and "
|
||||
"the \"ssl\" directive in %s:%ui",
|
||||
((ngx_str_t *) conf->certificates->elts)
|
||||
+ conf->certificates->nelts - 1,
|
||||
conf->file, conf->line);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
} else if (!conf->reject_handshake) {
|
||||
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
||||
"no \"ssl_certificate\" is defined for "
|
||||
"the \"ssl\" directive in %s:%ui",
|
||||
conf->file, conf->line);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
} else if (conf->certificates) {
|
||||
if (conf->certificates) {
|
||||
|
||||
if (conf->certificate_keys == NULL
|
||||
|| conf->certificate_keys->nelts < conf->certificates->nelts)
|
||||
@@ -1104,26 +1056,6 @@ found:
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
ngx_http_ssl_enable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
ngx_http_ssl_srv_conf_t *sscf = conf;
|
||||
|
||||
char *rv;
|
||||
|
||||
rv = ngx_conf_set_flag_slot(cf, cmd, conf);
|
||||
|
||||
if (rv != NGX_CONF_OK) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
sscf->file = cf->conf_file->file.name.data;
|
||||
sscf->line = cf->conf_file->line;
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
ngx_http_ssl_password_file(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_flag_t enable;
|
||||
|
||||
ngx_ssl_t ssl;
|
||||
|
||||
ngx_flag_t prefer_server_ciphers;
|
||||
@@ -65,9 +63,6 @@ typedef struct {
|
||||
ngx_str_t stapling_file;
|
||||
ngx_str_t stapling_responder;
|
||||
|
||||
u_char *file;
|
||||
ngx_uint_t line;
|
||||
|
||||
ngx_flag_t dyn_rec_enable;
|
||||
ngx_msec_t dyn_rec_timeout;
|
||||
size_t dyn_rec_size_lo;
|
||||
|
||||
@@ -4176,6 +4176,11 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
|
||||
if (ngx_strcmp(value[n].data, "http2") == 0) {
|
||||
#if (NGX_HTTP_V2)
|
||||
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
||||
"the \"listen ... http2\" directive "
|
||||
"is deprecated, use "
|
||||
"the \"http2\" directive instead");
|
||||
|
||||
lsopt.http2 = 1;
|
||||
continue;
|
||||
#else
|
||||
|
||||
+45
-22
@@ -318,12 +318,6 @@ ngx_http_init_connection(ngx_connection_t *c)
|
||||
rev->handler = ngx_http_wait_request_handler;
|
||||
c->write->handler = ngx_http_empty_handler;
|
||||
|
||||
#if (NGX_HTTP_V2)
|
||||
if (hc->addr_conf->http2) {
|
||||
rev->handler = ngx_http_v2_init;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (NGX_HTTP_V3)
|
||||
if (hc->addr_conf->quic) {
|
||||
ngx_http_v3_init_stream(c);
|
||||
@@ -332,17 +326,11 @@ ngx_http_init_connection(ngx_connection_t *c)
|
||||
#endif
|
||||
|
||||
#if (NGX_HTTP_SSL)
|
||||
{
|
||||
ngx_http_ssl_srv_conf_t *sscf;
|
||||
|
||||
sscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_ssl_module);
|
||||
|
||||
if (sscf->enable || hc->addr_conf->ssl) {
|
||||
if (hc->addr_conf->ssl) {
|
||||
hc->ssl = 1;
|
||||
c->log->action = "SSL handshaking";
|
||||
rev->handler = ngx_http_ssl_handshake;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (hc->addr_conf->proxy_protocol) {
|
||||
@@ -383,6 +371,9 @@ ngx_http_wait_request_handler(ngx_event_t *rev)
|
||||
ngx_buf_t *b;
|
||||
ngx_connection_t *c;
|
||||
ngx_http_connection_t *hc;
|
||||
#if (NGX_HTTP_V2)
|
||||
ngx_http_v2_srv_conf_t *h2scf;
|
||||
#endif
|
||||
ngx_http_core_srv_conf_t *cscf;
|
||||
|
||||
c = rev->data;
|
||||
@@ -429,6 +420,8 @@ ngx_http_wait_request_handler(ngx_event_t *rev)
|
||||
b->end = b->last + size;
|
||||
}
|
||||
|
||||
size = b->end - b->last;
|
||||
|
||||
n = c->recv(c, b->last, size);
|
||||
|
||||
if (n == NGX_AGAIN) {
|
||||
@@ -443,12 +436,16 @@ ngx_http_wait_request_handler(ngx_event_t *rev)
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* We are trying to not hold c->buffer's memory for an idle connection.
|
||||
*/
|
||||
if (b->pos == b->last) {
|
||||
|
||||
if (ngx_pfree(c->pool, b->start) == NGX_OK) {
|
||||
b->start = NULL;
|
||||
/*
|
||||
* We are trying to not hold c->buffer's memory for an
|
||||
* idle connection.
|
||||
*/
|
||||
|
||||
if (ngx_pfree(c->pool, b->start) == NGX_OK) {
|
||||
b->start = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -489,6 +486,29 @@ ngx_http_wait_request_handler(ngx_event_t *rev)
|
||||
}
|
||||
}
|
||||
|
||||
#if (NGX_HTTP_V2)
|
||||
|
||||
h2scf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_v2_module);
|
||||
|
||||
if (!hc->ssl && (h2scf->enable || hc->addr_conf->http2)) {
|
||||
|
||||
size = ngx_min(sizeof(NGX_HTTP_V2_PREFACE) - 1,
|
||||
(size_t) (b->last - b->pos));
|
||||
|
||||
if (ngx_memcmp(b->pos, NGX_HTTP_V2_PREFACE, size) == 0) {
|
||||
|
||||
if (size == sizeof(NGX_HTTP_V2_PREFACE) - 1) {
|
||||
ngx_http_v2_init(rev);
|
||||
return;
|
||||
}
|
||||
|
||||
ngx_post_event(rev, &ngx_posted_events);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
c->log->action = "reading client request line";
|
||||
|
||||
ngx_reusable_connection(c, 0);
|
||||
@@ -808,13 +828,16 @@ ngx_http_ssl_handshake_handler(ngx_connection_t *c)
|
||||
#if (NGX_HTTP_V2 \
|
||||
&& defined TLSEXT_TYPE_application_layer_protocol_negotiation)
|
||||
{
|
||||
unsigned int len;
|
||||
const unsigned char *data;
|
||||
ngx_http_connection_t *hc;
|
||||
unsigned int len;
|
||||
const unsigned char *data;
|
||||
ngx_http_connection_t *hc;
|
||||
ngx_http_v2_srv_conf_t *h2scf;
|
||||
|
||||
hc = c->data;
|
||||
|
||||
if (hc->addr_conf->http2) {
|
||||
h2scf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_v2_module);
|
||||
|
||||
if (h2scf->enable || hc->addr_conf->http2) {
|
||||
|
||||
SSL_get0_alpn_selected(c->ssl->connection, &data, &len);
|
||||
|
||||
|
||||
+70
-306
@@ -11,14 +11,6 @@
|
||||
#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
|
||||
@@ -63,8 +55,6 @@ static void ngx_http_v2_handle_connection(ngx_http_v2_connection_t *h2c);
|
||||
static void ngx_http_v2_lingering_close(ngx_connection_t *c);
|
||||
static void ngx_http_v2_lingering_close_handler(ngx_event_t *rev);
|
||||
|
||||
static u_char *ngx_http_v2_state_proxy_protocol(ngx_http_v2_connection_t *h2c,
|
||||
u_char *pos, u_char *end);
|
||||
static u_char *ngx_http_v2_state_preface(ngx_http_v2_connection_t *h2c,
|
||||
u_char *pos, u_char *end);
|
||||
static u_char *ngx_http_v2_state_preface_end(ngx_http_v2_connection_t *h2c,
|
||||
@@ -128,7 +118,7 @@ static ngx_int_t ngx_http_v2_parse_int(ngx_http_v2_connection_t *h2c,
|
||||
u_char **pos, u_char *end, ngx_uint_t prefix);
|
||||
|
||||
static ngx_http_v2_stream_t *ngx_http_v2_create_stream(
|
||||
ngx_http_v2_connection_t *h2c, ngx_uint_t push);
|
||||
ngx_http_v2_connection_t *h2c);
|
||||
static ngx_http_v2_node_t *ngx_http_v2_get_node_by_id(
|
||||
ngx_http_v2_connection_t *h2c, ngx_uint_t sid, ngx_uint_t alloc);
|
||||
static ngx_http_v2_node_t *ngx_http_v2_get_closed_node(
|
||||
@@ -164,14 +154,11 @@ 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);
|
||||
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 void ngx_http_v2_run_request_handler(ngx_event_t *ev);
|
||||
static ngx_int_t ngx_http_v2_process_request_body(ngx_http_request_t *r,
|
||||
u_char *pos, size_t size, ngx_uint_t last, ngx_uint_t flush);
|
||||
static ngx_int_t ngx_http_v2_filter_request_body(ngx_http_request_t *r);
|
||||
@@ -212,26 +199,10 @@ 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)
|
||||
{
|
||||
u_char *p, *end;
|
||||
ngx_connection_t *c;
|
||||
ngx_pool_cleanup_t *cln;
|
||||
ngx_http_connection_t *hc;
|
||||
@@ -278,7 +249,6 @@ ngx_http_v2_init(ngx_event_t *rev)
|
||||
|
||||
h2scf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_v2_module);
|
||||
|
||||
h2c->concurrent_pushes = h2scf->concurrent_pushes;
|
||||
h2c->priority_limit = ngx_max(h2scf->concurrent_streams, 100);
|
||||
|
||||
h2c->pool = ngx_create_pool(h2scf->pool_size, h2c->connection->log);
|
||||
@@ -316,8 +286,7 @@ ngx_http_v2_init(ngx_event_t *rev)
|
||||
return;
|
||||
}
|
||||
|
||||
h2c->state.handler = hc->proxy_protocol ? ngx_http_v2_state_proxy_protocol
|
||||
: ngx_http_v2_state_preface;
|
||||
h2c->state.handler = ngx_http_v2_state_preface;
|
||||
|
||||
ngx_queue_init(&h2c->waiting);
|
||||
ngx_queue_init(&h2c->dependencies);
|
||||
@@ -337,6 +306,23 @@ ngx_http_v2_init(ngx_event_t *rev)
|
||||
c->idle = 1;
|
||||
ngx_reusable_connection(c, 0);
|
||||
|
||||
if (c->buffer) {
|
||||
p = c->buffer->pos;
|
||||
end = c->buffer->last;
|
||||
|
||||
do {
|
||||
p = h2c->state.handler(h2c, p, end);
|
||||
|
||||
if (p == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
} while (p != end);
|
||||
|
||||
h2c->total_bytes += p - c->buffer->pos;
|
||||
c->buffer->pos = p;
|
||||
}
|
||||
|
||||
ngx_http_v2_read_handler(rev);
|
||||
}
|
||||
|
||||
@@ -372,7 +358,7 @@ ngx_http_v2_read_handler(ngx_event_t *rev)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!h2c->processing && !h2c->pushing) {
|
||||
if (!h2c->processing) {
|
||||
ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_NO_ERROR);
|
||||
return;
|
||||
}
|
||||
@@ -415,9 +401,7 @@ ngx_http_v2_read_handler(ngx_event_t *rev)
|
||||
break;
|
||||
}
|
||||
|
||||
if (n == 0
|
||||
&& (h2c->state.incomplete || h2c->processing || h2c->pushing))
|
||||
{
|
||||
if (n == 0 && (h2c->state.incomplete || h2c->processing)) {
|
||||
ngx_log_error(NGX_LOG_INFO, c->log, 0,
|
||||
"client prematurely closed connection");
|
||||
}
|
||||
@@ -640,7 +624,7 @@ ngx_http_v2_handle_connection(ngx_http_v2_connection_t *h2c)
|
||||
ngx_connection_t *c;
|
||||
ngx_http_core_loc_conf_t *clcf;
|
||||
|
||||
if (h2c->last_out || h2c->processing || h2c->pushing) {
|
||||
if (h2c->last_out || h2c->processing) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -848,32 +832,11 @@ ngx_http_v2_lingering_close_handler(ngx_event_t *rev)
|
||||
}
|
||||
|
||||
|
||||
static u_char *
|
||||
ngx_http_v2_state_proxy_protocol(ngx_http_v2_connection_t *h2c, u_char *pos,
|
||||
u_char *end)
|
||||
{
|
||||
ngx_log_t *log;
|
||||
|
||||
log = h2c->connection->log;
|
||||
log->action = "reading PROXY protocol";
|
||||
|
||||
pos = ngx_proxy_protocol_read(h2c->connection, pos, end);
|
||||
|
||||
log->action = "processing HTTP/2 connection";
|
||||
|
||||
if (pos == NULL) {
|
||||
return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
|
||||
}
|
||||
|
||||
return ngx_http_v2_state_preface(h2c, pos, end);
|
||||
}
|
||||
|
||||
|
||||
static u_char *
|
||||
ngx_http_v2_state_preface(ngx_http_v2_connection_t *h2c, u_char *pos,
|
||||
u_char *end)
|
||||
{
|
||||
static const u_char preface[] = "PRI * HTTP/2.0\r\n";
|
||||
static const u_char preface[] = NGX_HTTP_V2_PREFACE_START;
|
||||
|
||||
if ((size_t) (end - pos) < sizeof(preface) - 1) {
|
||||
return ngx_http_v2_state_save(h2c, pos, end, ngx_http_v2_state_preface);
|
||||
@@ -894,7 +857,7 @@ static u_char *
|
||||
ngx_http_v2_state_preface_end(ngx_http_v2_connection_t *h2c, u_char *pos,
|
||||
u_char *end)
|
||||
{
|
||||
static const u_char preface[] = "\r\nSM\r\n\r\n";
|
||||
static const u_char preface[] = NGX_HTTP_V2_PREFACE_END;
|
||||
|
||||
if ((size_t) (end - pos) < sizeof(preface) - 1) {
|
||||
return ngx_http_v2_state_save(h2c, pos, end,
|
||||
@@ -1346,7 +1309,7 @@ ngx_http_v2_state_headers(ngx_http_v2_connection_t *h2c, u_char *pos,
|
||||
h2c->closed_nodes--;
|
||||
}
|
||||
|
||||
stream = ngx_http_v2_create_stream(h2c, 0);
|
||||
stream = ngx_http_v2_create_stream(h2c);
|
||||
if (stream == NULL) {
|
||||
return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
|
||||
}
|
||||
@@ -2135,11 +2098,6 @@ ngx_http_v2_state_rst_stream(ngx_http_v2_connection_t *h2c, u_char *pos,
|
||||
"client canceled stream %ui", h2c->state.sid);
|
||||
break;
|
||||
|
||||
case NGX_HTTP_V2_REFUSED_STREAM:
|
||||
ngx_log_error(NGX_LOG_INFO, fc->log, 0,
|
||||
"client refused stream %ui", h2c->state.sid);
|
||||
break;
|
||||
|
||||
case NGX_HTTP_V2_INTERNAL_ERROR:
|
||||
ngx_log_error(NGX_LOG_INFO, fc->log, 0,
|
||||
"client terminated stream %ui due to internal error",
|
||||
@@ -2207,7 +2165,6 @@ ngx_http_v2_state_settings_params(ngx_http_v2_connection_t *h2c, u_char *pos,
|
||||
{
|
||||
ssize_t window_delta;
|
||||
ngx_uint_t id, value;
|
||||
ngx_http_v2_srv_conf_t *h2scf;
|
||||
ngx_http_v2_out_frame_t *frame;
|
||||
|
||||
window_delta = 0;
|
||||
@@ -2269,14 +2226,6 @@ ngx_http_v2_state_settings_params(ngx_http_v2_connection_t *h2c, u_char *pos,
|
||||
NGX_HTTP_V2_PROTOCOL_ERROR);
|
||||
}
|
||||
|
||||
h2c->push_disabled = !value;
|
||||
break;
|
||||
|
||||
case NGX_HTTP_V2_MAX_STREAMS_SETTING:
|
||||
h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
|
||||
ngx_http_v2_module);
|
||||
|
||||
h2c->concurrent_pushes = ngx_min(value, h2scf->concurrent_pushes);
|
||||
break;
|
||||
|
||||
case NGX_HTTP_V2_HEADER_TABLE_SIZE_SETTING:
|
||||
@@ -2738,163 +2687,6 @@ ngx_http_v2_parse_int(ngx_http_v2_connection_t *h2c, u_char **pos, u_char *end,
|
||||
}
|
||||
|
||||
|
||||
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_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) {
|
||||
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) {
|
||||
ngx_queue_remove(&node->reuse);
|
||||
h2c->closed_nodes--;
|
||||
}
|
||||
|
||||
stream->pool = pool;
|
||||
|
||||
r = stream->request;
|
||||
fc = r->connection;
|
||||
|
||||
stream->in_closed = 1;
|
||||
stream->node = node;
|
||||
|
||||
node->stream = stream;
|
||||
|
||||
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, parent->node->id);
|
||||
|
||||
node->weight = NGX_HTTP_V2_DEFAULT_WEIGHT;
|
||||
ngx_http_v2_set_dependency(h2c, node, parent->node->id, 0);
|
||||
|
||||
r->method_name = ngx_http_core_get_method;
|
||||
r->method = NGX_HTTP_GET;
|
||||
|
||||
r->schema.data = ngx_pstrdup(pool, &parent->request->schema);
|
||||
if (r->schema.data == NULL) {
|
||||
goto close;
|
||||
}
|
||||
|
||||
r->schema.len = parent->request->schema.len;
|
||||
|
||||
value.data = ngx_pstrdup(pool, path);
|
||||
if (value.data == NULL) {
|
||||
goto close;
|
||||
}
|
||||
|
||||
value.len = path->len;
|
||||
|
||||
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 stream;
|
||||
|
||||
error:
|
||||
|
||||
if (rc == NGX_ABORT) {
|
||||
/* header handler has already finalized request */
|
||||
ngx_http_run_posted_requests(fc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (rc == NGX_DECLINED) {
|
||||
ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
|
||||
ngx_http_run_posted_requests(fc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
close:
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_v2_send_settings(ngx_http_v2_connection_t *h2c)
|
||||
{
|
||||
@@ -3166,7 +2958,7 @@ ngx_http_v2_frame_handler(ngx_http_v2_connection_t *h2c,
|
||||
|
||||
|
||||
static ngx_http_v2_stream_t *
|
||||
ngx_http_v2_create_stream(ngx_http_v2_connection_t *h2c, ngx_uint_t push)
|
||||
ngx_http_v2_create_stream(ngx_http_v2_connection_t *h2c)
|
||||
{
|
||||
ngx_log_t *log;
|
||||
ngx_event_t *rev, *wev;
|
||||
@@ -3221,13 +3013,7 @@ ngx_http_v2_create_stream(ngx_http_v2_connection_t *h2c, ngx_uint_t push)
|
||||
ngx_memcpy(log, h2c->connection->log, sizeof(ngx_log_t));
|
||||
|
||||
log->data = ctx;
|
||||
|
||||
if (push) {
|
||||
log->action = "processing pushed request headers";
|
||||
|
||||
} else {
|
||||
log->action = "reading client request headers";
|
||||
}
|
||||
log->action = "reading client request headers";
|
||||
|
||||
ngx_memzero(rev, sizeof(ngx_event_t));
|
||||
|
||||
@@ -3299,12 +3085,7 @@ ngx_http_v2_create_stream(ngx_http_v2_connection_t *h2c, ngx_uint_t push)
|
||||
stream->send_window = h2c->init_window;
|
||||
stream->recv_window = h2scf->preread_size;
|
||||
|
||||
if (push) {
|
||||
h2c->pushing++;
|
||||
|
||||
} else {
|
||||
h2c->processing++;
|
||||
}
|
||||
h2c->processing++;
|
||||
|
||||
h2c->priority_limit += h2scf->concurrent_streams;
|
||||
|
||||
@@ -3726,46 +3507,42 @@ 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)
|
||||
{
|
||||
return ngx_http_v2_parse_header(r, &ngx_http_v2_parse_headers[0], 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)
|
||||
{
|
||||
ngx_table_elt_t *h;
|
||||
ngx_http_header_t *hh;
|
||||
ngx_http_core_main_conf_t *cmcf;
|
||||
|
||||
static ngx_str_t host = ngx_string("host");
|
||||
|
||||
h = ngx_list_push(&r->headers_in.headers);
|
||||
if (h == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
h->key.len = header->name.len;
|
||||
h->key.data = header->name.data;
|
||||
h->lowcase_key = header->name.data;
|
||||
h->hash = ngx_hash(ngx_hash(ngx_hash('h', 'o'), 's'), 't');
|
||||
|
||||
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->key.len = host.len;
|
||||
h->key.data = host.data;
|
||||
|
||||
h->value.len = value->len;
|
||||
h->value.data = value->data;
|
||||
|
||||
if (header->hh->handler(r, h, header->hh->offset) != NGX_OK) {
|
||||
/* header handler has already finalized request */
|
||||
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()
|
||||
*/
|
||||
return NGX_ABORT;
|
||||
}
|
||||
|
||||
@@ -3952,10 +3729,22 @@ static void
|
||||
ngx_http_v2_run_request(ngx_http_request_t *r)
|
||||
{
|
||||
ngx_connection_t *fc;
|
||||
ngx_http_v2_srv_conf_t *h2scf;
|
||||
ngx_http_v2_connection_t *h2c;
|
||||
|
||||
fc = r->connection;
|
||||
|
||||
h2scf = ngx_http_get_module_srv_conf(r, ngx_http_v2_module);
|
||||
|
||||
if (!h2scf->enable && !r->http_connection->addr_conf->http2) {
|
||||
ngx_log_error(NGX_LOG_INFO, fc->log, 0,
|
||||
"client attempted to request the server name "
|
||||
"for which the negotiated protocol is disabled");
|
||||
|
||||
ngx_http_finalize_request(r, NGX_HTTP_MISDIRECTED_REQUEST);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (ngx_http_v2_construct_request_line(r) != NGX_OK) {
|
||||
goto failed;
|
||||
}
|
||||
@@ -3996,22 +3785,6 @@ failed:
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
ngx_http_v2_run_request_handler(ngx_event_t *ev)
|
||||
{
|
||||
ngx_connection_t *fc;
|
||||
ngx_http_request_t *r;
|
||||
|
||||
fc = ev->data;
|
||||
r = fc->data;
|
||||
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0,
|
||||
"http2 run request handler");
|
||||
|
||||
ngx_http_v2_run_request(r);
|
||||
}
|
||||
|
||||
|
||||
ngx_int_t
|
||||
ngx_http_v2_read_request_body(ngx_http_request_t *r)
|
||||
{
|
||||
@@ -4615,7 +4388,6 @@ void
|
||||
ngx_http_v2_close_stream(ngx_http_v2_stream_t *stream, ngx_int_t rc)
|
||||
{
|
||||
ngx_pool_t *pool;
|
||||
ngx_uint_t push;
|
||||
ngx_event_t *ev;
|
||||
ngx_connection_t *fc;
|
||||
ngx_http_v2_node_t *node;
|
||||
@@ -4624,10 +4396,9 @@ ngx_http_v2_close_stream(ngx_http_v2_stream_t *stream, ngx_int_t rc)
|
||||
h2c = stream->connection;
|
||||
node = stream->node;
|
||||
|
||||
ngx_log_debug4(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
|
||||
"http2 close stream %ui, queued %ui, "
|
||||
"processing %ui, pushing %ui",
|
||||
node->id, stream->queued, h2c->processing, h2c->pushing);
|
||||
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
|
||||
"http2 close stream %ui, queued %ui, processing %ui",
|
||||
node->id, stream->queued, h2c->processing);
|
||||
|
||||
fc = stream->request->connection;
|
||||
|
||||
@@ -4662,8 +4433,6 @@ ngx_http_v2_close_stream(ngx_http_v2_stream_t *stream, ngx_int_t rc)
|
||||
h2c->state.stream = NULL;
|
||||
}
|
||||
|
||||
push = stream->node->id % 2 == 0;
|
||||
|
||||
node->stream = NULL;
|
||||
|
||||
ngx_queue_insert_tail(&h2c->closed, &node->reuse);
|
||||
@@ -4713,14 +4482,9 @@ ngx_http_v2_close_stream(ngx_http_v2_stream_t *stream, ngx_int_t rc)
|
||||
fc->data = h2c->free_fake_connections;
|
||||
h2c->free_fake_connections = fc;
|
||||
|
||||
if (push) {
|
||||
h2c->pushing--;
|
||||
h2c->processing--;
|
||||
|
||||
} else {
|
||||
h2c->processing--;
|
||||
}
|
||||
|
||||
if (h2c->processing || h2c->pushing || h2c->blocked) {
|
||||
if (h2c->processing || h2c->blocked) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4896,7 +4660,7 @@ ngx_http_v2_finalize_connection(ngx_http_v2_connection_t *h2c,
|
||||
}
|
||||
}
|
||||
|
||||
if (!h2c->processing && !h2c->pushing) {
|
||||
if (!h2c->processing) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -4944,7 +4708,7 @@ ngx_http_v2_finalize_connection(ngx_http_v2_connection_t *h2c,
|
||||
|
||||
h2c->blocked = 0;
|
||||
|
||||
if (h2c->processing || h2c->pushing) {
|
||||
if (h2c->processing) {
|
||||
c->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
+16
-16
@@ -24,8 +24,6 @@
|
||||
#define NGX_HTTP_V2_MAX_FIELD \
|
||||
(127 + (1 << (NGX_HTTP_V2_INT_OCTETS - 1) * 7) - 1)
|
||||
|
||||
#define NGX_HTTP_V2_STREAM_ID_SIZE 4
|
||||
|
||||
#define NGX_HTTP_V2_FRAME_HEADER_SIZE 9
|
||||
|
||||
/* frame types */
|
||||
@@ -71,6 +69,15 @@ typedef u_char *(*ngx_http_v2_handler_pt) (ngx_http_v2_connection_t *h2c,
|
||||
u_char *pos, u_char *end);
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_flag_t enable;
|
||||
size_t pool_size;
|
||||
ngx_uint_t concurrent_streams;
|
||||
size_t preread_size;
|
||||
ngx_uint_t streams_index_mask;
|
||||
} ngx_http_v2_srv_conf_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_str_t name;
|
||||
ngx_str_t value;
|
||||
@@ -174,9 +181,6 @@ struct ngx_http_v2_connection_s {
|
||||
ngx_uint_t idle;
|
||||
ngx_uint_t priority_limit;
|
||||
|
||||
ngx_uint_t pushing;
|
||||
ngx_uint_t concurrent_pushes;
|
||||
|
||||
size_t send_window;
|
||||
size_t recv_window;
|
||||
size_t init_window;
|
||||
@@ -205,7 +209,6 @@ struct ngx_http_v2_connection_s {
|
||||
|
||||
ngx_uint_t closed_nodes;
|
||||
ngx_uint_t last_sid;
|
||||
ngx_uint_t last_push;
|
||||
|
||||
time_t lingering_time;
|
||||
|
||||
@@ -213,7 +216,6 @@ struct ngx_http_v2_connection_s {
|
||||
unsigned table_update:1;
|
||||
unsigned blocked:1;
|
||||
unsigned goaway:1;
|
||||
unsigned push_disabled:1;
|
||||
unsigned indicate_resize:1;
|
||||
|
||||
#if (NGX_HTTP_V2_HPACK_ENC)
|
||||
@@ -350,9 +352,6 @@ 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_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);
|
||||
|
||||
ngx_int_t ngx_http_v2_send_output_queue(ngx_http_v2_connection_t *h2c);
|
||||
@@ -454,20 +453,18 @@ ngx_int_t ngx_http_v2_table_size(ngx_http_v2_connection_t *h2c, size_t size);
|
||||
#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
|
||||
|
||||
|
||||
u_char *ngx_http_v2_string_encode(u_char *dst, u_char *src, size_t len,
|
||||
u_char *tmp, ngx_uint_t lower);
|
||||
#define NGX_HTTP_V2_PREFACE_START "PRI * HTTP/2.0\r\n"
|
||||
#define NGX_HTTP_V2_PREFACE_END "\r\nSM\r\n\r\n"
|
||||
#define NGX_HTTP_V2_PREFACE NGX_HTTP_V2_PREFACE_START \
|
||||
NGX_HTTP_V2_PREFACE_END
|
||||
|
||||
|
||||
u_char *ngx_http_v2_string_encode(u_char *dst, u_char *src, size_t len,
|
||||
@@ -501,4 +498,7 @@ ngx_http_v2_table_resize(ngx_http_v2_connection_t *h2c);
|
||||
ngx_http_v2_write_header(h2c, pos, (u_char *) key, sizeof(key) - 1, \
|
||||
val->data, val->len, tmp);
|
||||
|
||||
extern ngx_module_t ngx_http_v2_module;
|
||||
|
||||
|
||||
#endif /* _NGX_HTTP_V2_H_INCLUDED_ */
|
||||
@@ -70,39 +70,8 @@ static const struct {
|
||||
};
|
||||
|
||||
|
||||
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 *binary);
|
||||
|
||||
static ngx_http_v2_out_frame_t *ngx_http_v2_create_headers_frame(
|
||||
ngx_http_request_t *r, u_char *pos, u_char *end, ngx_uint_t fin);
|
||||
static ngx_http_v2_out_frame_t *ngx_http_v2_create_push_frame(
|
||||
ngx_http_request_t *r, u_char *pos, u_char *end);
|
||||
static ngx_http_v2_out_frame_t *ngx_http_v2_create_trailers_frame(
|
||||
ngx_http_request_t *r);
|
||||
|
||||
@@ -125,8 +94,6 @@ static ngx_inline ngx_int_t ngx_http_v2_filter_send(
|
||||
|
||||
static ngx_int_t ngx_http_v2_headers_frame_handler(
|
||||
ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *frame);
|
||||
static ngx_int_t ngx_http_v2_push_frame_handler(
|
||||
ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *frame);
|
||||
static ngx_int_t ngx_http_v2_data_frame_handler(
|
||||
ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *frame);
|
||||
static ngx_inline void ngx_http_v2_handle_frame(
|
||||
@@ -286,15 +253,6 @@ ngx_http_v2_header_filter(ngx_http_request_t *r)
|
||||
|
||||
h2c = stream->connection;
|
||||
|
||||
if (!h2c->push_disabled && !h2c->goaway
|
||||
&& stream->node->id % 2 == 1
|
||||
&& r->method != NGX_HTTP_HEAD)
|
||||
{
|
||||
if (ngx_http_v2_push_resources(r) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
len = h2c->table_update ? 1 : 0;
|
||||
|
||||
len += status ? 1 : 1 + ngx_http_v2_literal_size("418");
|
||||
@@ -641,7 +599,7 @@ ngx_http_v2_header_filter(ngx_http_request_t *r)
|
||||
|
||||
ngx_http_v2_queue_blocked_frame(h2c, frame);
|
||||
|
||||
stream->queued++;
|
||||
stream->queued = 1;
|
||||
|
||||
cln = ngx_http_cleanup_add(r, 0);
|
||||
if (cln == NULL) {
|
||||
@@ -659,418 +617,6 @@ ngx_http_v2_header_filter(ngx_http_request_t *r)
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_v2_push_resources(ngx_http_request_t *r)
|
||||
{
|
||||
u_char *start, *end, *last;
|
||||
ngx_int_t rc;
|
||||
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_memzero(binary, NGX_HTTP_V2_PUSH_HEADERS * sizeof(ngx_str_t));
|
||||
|
||||
h2lcf = ngx_http_get_module_loc_conf(r, ngx_http_v2_module);
|
||||
|
||||
if (h2lcf->pushes) {
|
||||
pushes = h2lcf->pushes->elts;
|
||||
|
||||
for (i = 0; i < h2lcf->pushes->nelts; i++) {
|
||||
|
||||
if (ngx_http_complex_value(r, &pushes[i], &path) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (path.len == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (path.len == 3 && ngx_strncmp(path.data, "off", 3) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = ngx_http_v2_push_resource(r, &path, binary);
|
||||
|
||||
if (rc == NGX_ERROR) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (rc == NGX_ABORT) {
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
/* NGX_OK, NGX_DECLINED */
|
||||
}
|
||||
}
|
||||
|
||||
if (!h2lcf->push_preload) {
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
for (h = r->headers_out.link; h; h = h->next) {
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||
"http2 parse link: \"%V\"", &h->value);
|
||||
|
||||
start = h->value.data;
|
||||
end = h->value.data + h->value.len;
|
||||
|
||||
next_link:
|
||||
|
||||
while (start < end && *start == ' ') { start++; }
|
||||
|
||||
if (start == end || *start++ != '<') {
|
||||
continue;
|
||||
}
|
||||
|
||||
while (start < end && *start == ' ') { start++; }
|
||||
|
||||
for (last = start; last < end && *last != '>'; last++) {
|
||||
/* void */
|
||||
}
|
||||
|
||||
if (last == start || last == end) {
|
||||
continue;
|
||||
}
|
||||
|
||||
path.len = last - start;
|
||||
path.data = start;
|
||||
|
||||
start = last + 1;
|
||||
|
||||
while (start < end && *start == ' ') { start++; }
|
||||
|
||||
if (start == end) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (*start == ',') {
|
||||
start++;
|
||||
goto next_link;
|
||||
}
|
||||
|
||||
if (*start++ != ';') {
|
||||
continue;
|
||||
}
|
||||
|
||||
last = ngx_strlchr(start, end, ',');
|
||||
|
||||
if (last == NULL) {
|
||||
last = end;
|
||||
}
|
||||
|
||||
push = 0;
|
||||
|
||||
for ( ;; ) {
|
||||
|
||||
while (start < last && *start == ' ') { start++; }
|
||||
|
||||
if (last - start >= 6
|
||||
&& ngx_strncasecmp(start, (u_char *) "nopush", 6) == 0)
|
||||
{
|
||||
start += 6;
|
||||
|
||||
if (start == last || *start == ' ' || *start == ';') {
|
||||
push = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
goto next_param;
|
||||
}
|
||||
|
||||
if (last - start >= 11
|
||||
&& ngx_strncasecmp(start, (u_char *) "rel=preload", 11) == 0)
|
||||
{
|
||||
start += 11;
|
||||
|
||||
if (start == last || *start == ' ' || *start == ';') {
|
||||
push = 1;
|
||||
}
|
||||
|
||||
goto next_param;
|
||||
}
|
||||
|
||||
if (last - start >= 4
|
||||
&& ngx_strncasecmp(start, (u_char *) "rel=", 4) == 0)
|
||||
{
|
||||
start += 4;
|
||||
|
||||
while (start < last && *start == ' ') { start++; }
|
||||
|
||||
if (start == last || *start++ != '"') {
|
||||
goto next_param;
|
||||
}
|
||||
|
||||
for ( ;; ) {
|
||||
|
||||
while (start < last && *start == ' ') { start++; }
|
||||
|
||||
if (last - start >= 7
|
||||
&& ngx_strncasecmp(start, (u_char *) "preload", 7) == 0)
|
||||
{
|
||||
start += 7;
|
||||
|
||||
if (start < last && (*start == ' ' || *start == '"')) {
|
||||
push = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (start < last && *start != ' ' && *start != '"') {
|
||||
start++;
|
||||
}
|
||||
|
||||
if (start == last) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (*start == '"') {
|
||||
break;
|
||||
}
|
||||
|
||||
start++;
|
||||
}
|
||||
}
|
||||
|
||||
next_param:
|
||||
|
||||
start = ngx_strlchr(start, last, ';');
|
||||
|
||||
if (start == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
start++;
|
||||
}
|
||||
|
||||
if (push) {
|
||||
while (path.len && path.data[path.len - 1] == ' ') {
|
||||
path.len--;
|
||||
}
|
||||
}
|
||||
|
||||
if (push && path.len
|
||||
&& !(path.len > 1 && path.data[0] == '/' && path.data[1] == '/'))
|
||||
{
|
||||
rc = ngx_http_v2_push_resource(r, &path, binary);
|
||||
|
||||
if (rc == NGX_ERROR) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (rc == NGX_ABORT) {
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
/* NGX_OK, NGX_DECLINED */
|
||||
}
|
||||
|
||||
if (last < end) {
|
||||
start = last + 1;
|
||||
goto next_link;
|
||||
}
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_v2_push_resource(ngx_http_request_t *r, ngx_str_t *path,
|
||||
ngx_str_t *binary)
|
||||
{
|
||||
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;
|
||||
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0, "http2 push resource");
|
||||
|
||||
stream = r->stream;
|
||||
h2c = stream->connection;
|
||||
|
||||
if (!ngx_path_separator(path->data[0])) {
|
||||
ngx_log_error(NGX_LOG_WARN, fc->log, 0,
|
||||
"non-absolute path \"%V\" not pushed", path);
|
||||
return NGX_DECLINED;
|
||||
}
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
|
||||
"http2 pushing:%ui limit:%ui",
|
||||
h2c->pushing, h2c->concurrent_pushes);
|
||||
|
||||
if (h2c->pushing >= h2c->concurrent_pushes) {
|
||||
return NGX_ABORT;
|
||||
}
|
||||
|
||||
if (h2c->last_push == 0x7ffffffe) {
|
||||
return NGX_ABORT;
|
||||
}
|
||||
|
||||
if (path->len > NGX_HTTP_V2_MAX_FIELD) {
|
||||
return NGX_DECLINED;
|
||||
}
|
||||
|
||||
if (r->headers_in.host == NULL) {
|
||||
return NGX_ABORT;
|
||||
}
|
||||
|
||||
ph = ngx_http_v2_push_headers;
|
||||
|
||||
len = ngx_max(r->schema.len, path->len);
|
||||
|
||||
if (binary[0].len) {
|
||||
tmp = ngx_palloc(r->pool, len);
|
||||
if (tmp == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
} else {
|
||||
for (i = 0; i < NGX_HTTP_V2_PUSH_HEADERS; i++) {
|
||||
h = (ngx_table_elt_t **) ((char *) &r->headers_in + ph[i].offset);
|
||||
|
||||
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
|
||||
+ 1 + NGX_HTTP_V2_INT_OCTETS + r->schema.len;
|
||||
|
||||
for (i = 0; i < NGX_HTTP_V2_PUSH_HEADERS; i++) {
|
||||
len += binary[i].len;
|
||||
len += push_header[i].len + 1;
|
||||
}
|
||||
|
||||
pos = ngx_pnalloc(r->pool, len);
|
||||
if (pos == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
start = pos;
|
||||
|
||||
h2c = r->stream->connection;
|
||||
|
||||
if (h2c->indicate_resize) {
|
||||
*pos = 32;
|
||||
pos = ngx_http_v2_write_int(pos, ngx_http_v2_prefix(5),
|
||||
h2c->max_hpack_table_size);
|
||||
h2c->indicate_resize = 0;
|
||||
#if (NGX_HTTP_V2_HPACK_ENC)
|
||||
ngx_http_v2_table_resize(h2c);
|
||||
#endif
|
||||
}
|
||||
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0,
|
||||
"http2 push header: \":method: GET\"");
|
||||
|
||||
*pos++ = ngx_http_v2_indexed(NGX_HTTP_V2_METHOD_GET_INDEX);
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
|
||||
"http2 push header: \":path: %V\"", path);
|
||||
|
||||
pos = ngx_http_v2_write_header_pot(":path", path);
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
|
||||
"http2 push header: \":scheme: %V\"", &r->schema);
|
||||
|
||||
if (r->schema.len == 5 && ngx_strncmp(r->schema.data, "https", 5) == 0) {
|
||||
*pos++ = ngx_http_v2_indexed(NGX_HTTP_V2_SCHEME_HTTPS_INDEX);
|
||||
|
||||
} else if (r->schema.len == 4
|
||||
&& ngx_strncmp(r->schema.data, "http", 4) == 0)
|
||||
{
|
||||
*pos++ = ngx_http_v2_indexed(NGX_HTTP_V2_SCHEME_HTTP_INDEX);
|
||||
|
||||
} else {
|
||||
*pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_SCHEME_HTTP_INDEX);
|
||||
pos = ngx_http_v2_write_value(pos, r->schema.data, r->schema.len, tmp);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, fc->log, 0,
|
||||
"http2 push header: \"%V: %V\"",
|
||||
&ph[i].name, &(*h)->value);
|
||||
|
||||
pos = ngx_http_v2_write_header(h2c, pos,
|
||||
push_header[i].name, push_header[i].len, value->data, value->len,
|
||||
tmp);
|
||||
}
|
||||
|
||||
frame = ngx_http_v2_create_push_frame(r, start, pos);
|
||||
if (frame == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
ngx_http_v2_queue_blocked_frame(h2c, frame);
|
||||
|
||||
stream->queued++;
|
||||
|
||||
stream = ngx_http_v2_push_stream(stream, path);
|
||||
|
||||
if (stream) {
|
||||
stream->request->request_length = pos - start;
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
|
||||
static ngx_http_v2_out_frame_t *
|
||||
ngx_http_v2_create_headers_frame(ngx_http_request_t *r, u_char *pos,
|
||||
u_char *end, ngx_uint_t fin)
|
||||
@@ -1176,125 +722,6 @@ ngx_http_v2_create_headers_frame(ngx_http_request_t *r, u_char *pos,
|
||||
}
|
||||
|
||||
|
||||
static ngx_http_v2_out_frame_t *
|
||||
ngx_http_v2_create_push_frame(ngx_http_request_t *r, u_char *pos, u_char *end)
|
||||
{
|
||||
u_char type, flags;
|
||||
size_t rest, frame_size, len;
|
||||
ngx_buf_t *b;
|
||||
ngx_chain_t *cl, **ll;
|
||||
ngx_http_v2_stream_t *stream;
|
||||
ngx_http_v2_out_frame_t *frame;
|
||||
ngx_http_v2_connection_t *h2c;
|
||||
|
||||
stream = r->stream;
|
||||
h2c = stream->connection;
|
||||
rest = NGX_HTTP_V2_STREAM_ID_SIZE + (end - pos);
|
||||
|
||||
frame = ngx_palloc(r->pool, sizeof(ngx_http_v2_out_frame_t));
|
||||
if (frame == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
frame->handler = ngx_http_v2_push_frame_handler;
|
||||
frame->stream = stream;
|
||||
frame->length = rest;
|
||||
frame->blocked = 1;
|
||||
frame->fin = 0;
|
||||
|
||||
ll = &frame->first;
|
||||
|
||||
type = NGX_HTTP_V2_PUSH_PROMISE_FRAME;
|
||||
flags = NGX_HTTP_V2_NO_FLAG;
|
||||
frame_size = h2c->frame_size;
|
||||
|
||||
for ( ;; ) {
|
||||
if (rest <= frame_size) {
|
||||
frame_size = rest;
|
||||
flags |= NGX_HTTP_V2_END_HEADERS_FLAG;
|
||||
}
|
||||
|
||||
b = ngx_create_temp_buf(r->pool,
|
||||
NGX_HTTP_V2_FRAME_HEADER_SIZE
|
||||
+ ((type == NGX_HTTP_V2_PUSH_PROMISE_FRAME)
|
||||
? NGX_HTTP_V2_STREAM_ID_SIZE : 0));
|
||||
if (b == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b->last = ngx_http_v2_write_len_and_type(b->last, frame_size, type);
|
||||
*b->last++ = flags;
|
||||
b->last = ngx_http_v2_write_sid(b->last, stream->node->id);
|
||||
|
||||
b->tag = (ngx_buf_tag_t) &ngx_http_v2_module;
|
||||
|
||||
if (type == NGX_HTTP_V2_PUSH_PROMISE_FRAME) {
|
||||
h2c->last_push += 2;
|
||||
|
||||
b->last = ngx_http_v2_write_sid(b->last, h2c->last_push);
|
||||
len = frame_size - NGX_HTTP_V2_STREAM_ID_SIZE;
|
||||
|
||||
} else {
|
||||
len = frame_size;
|
||||
}
|
||||
|
||||
cl = ngx_alloc_chain_link(r->pool);
|
||||
if (cl == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cl->buf = b;
|
||||
|
||||
*ll = cl;
|
||||
ll = &cl->next;
|
||||
|
||||
b = ngx_calloc_buf(r->pool);
|
||||
if (b == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b->pos = pos;
|
||||
|
||||
pos += len;
|
||||
|
||||
b->last = pos;
|
||||
b->start = b->pos;
|
||||
b->end = b->last;
|
||||
b->temporary = 1;
|
||||
|
||||
cl = ngx_alloc_chain_link(r->pool);
|
||||
if (cl == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cl->buf = b;
|
||||
|
||||
*ll = cl;
|
||||
ll = &cl->next;
|
||||
|
||||
rest -= frame_size;
|
||||
|
||||
if (rest) {
|
||||
frame->length += NGX_HTTP_V2_FRAME_HEADER_SIZE;
|
||||
|
||||
type = NGX_HTTP_V2_CONTINUATION_FRAME;
|
||||
continue;
|
||||
}
|
||||
|
||||
cl->next = NULL;
|
||||
frame->last = cl;
|
||||
|
||||
ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||
"http2:%ui create PUSH_PROMISE frame %p: "
|
||||
"sid:%ui len:%uz",
|
||||
stream->node->id, frame, h2c->last_push,
|
||||
frame->length);
|
||||
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static ngx_http_v2_out_frame_t *
|
||||
ngx_http_v2_create_trailers_frame(ngx_http_request_t *r)
|
||||
{
|
||||
@@ -1898,62 +1325,6 @@ ngx_http_v2_headers_frame_handler(ngx_http_v2_connection_t *h2c,
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_v2_push_frame_handler(ngx_http_v2_connection_t *h2c,
|
||||
ngx_http_v2_out_frame_t *frame)
|
||||
{
|
||||
ngx_chain_t *cl, *ln;
|
||||
ngx_http_v2_stream_t *stream;
|
||||
|
||||
stream = frame->stream;
|
||||
cl = frame->first;
|
||||
|
||||
for ( ;; ) {
|
||||
if (cl->buf->pos != cl->buf->last) {
|
||||
frame->first = cl;
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
|
||||
"http2:%ui PUSH_PROMISE frame %p was sent partially",
|
||||
stream->node->id, frame);
|
||||
|
||||
return NGX_AGAIN;
|
||||
}
|
||||
|
||||
ln = cl->next;
|
||||
|
||||
if (cl->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_module) {
|
||||
cl->next = stream->free_frame_headers;
|
||||
stream->free_frame_headers = cl;
|
||||
|
||||
} else {
|
||||
cl->next = stream->free_bufs;
|
||||
stream->free_bufs = cl;
|
||||
}
|
||||
|
||||
if (cl == frame->last) {
|
||||
break;
|
||||
}
|
||||
|
||||
cl = ln;
|
||||
}
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
|
||||
"http2:%ui PUSH_PROMISE frame %p was sent",
|
||||
stream->node->id, frame);
|
||||
|
||||
stream->request->header_size += NGX_HTTP_V2_FRAME_HEADER_SIZE
|
||||
+ frame->length;
|
||||
|
||||
h2c->payload_bytes += frame->length;
|
||||
|
||||
ngx_http_v2_handle_frame(stream, frame);
|
||||
|
||||
ngx_http_v2_handle_stream(h2c, stream);
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_v2_data_frame_handler(ngx_http_v2_connection_t *h2c,
|
||||
ngx_http_v2_out_frame_t *frame)
|
||||
|
||||
@@ -27,8 +27,6 @@ static void *ngx_http_v2_create_loc_conf(ngx_conf_t *cf);
|
||||
static char *ngx_http_v2_merge_loc_conf(ngx_conf_t *cf, void *parent,
|
||||
void *child);
|
||||
|
||||
static char *ngx_http_v2_push(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
|
||||
static char *ngx_http_v2_recv_buffer_size(ngx_conf_t *cf, void *post,
|
||||
void *data);
|
||||
static char *ngx_http_v2_pool_size(ngx_conf_t *cf, void *post, void *data);
|
||||
@@ -75,6 +73,13 @@ static ngx_conf_post_t ngx_http_v2_chunk_size_post =
|
||||
|
||||
static ngx_command_t ngx_http_v2_commands[] = {
|
||||
|
||||
{ ngx_string("http2"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
||||
ngx_conf_set_flag_slot,
|
||||
NGX_HTTP_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_http_v2_srv_conf_t, enable),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("http2_recv_buffer_size"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_size_slot,
|
||||
@@ -98,9 +103,9 @@ static ngx_command_t ngx_http_v2_commands[] = {
|
||||
|
||||
{ ngx_string("http2_max_concurrent_pushes"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_num_slot,
|
||||
NGX_HTTP_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_http_v2_srv_conf_t, concurrent_pushes),
|
||||
ngx_http_v2_obsolete,
|
||||
0,
|
||||
0,
|
||||
NULL },
|
||||
|
||||
{ ngx_string("http2_max_requests"),
|
||||
@@ -161,15 +166,15 @@ static ngx_command_t ngx_http_v2_commands[] = {
|
||||
|
||||
{ ngx_string("http2_push_preload"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
||||
ngx_conf_set_flag_slot,
|
||||
NGX_HTTP_LOC_CONF_OFFSET,
|
||||
offsetof(ngx_http_v2_loc_conf_t, push_preload),
|
||||
ngx_http_v2_obsolete,
|
||||
0,
|
||||
0,
|
||||
NULL },
|
||||
|
||||
{ ngx_string("http2_push"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
||||
ngx_http_v2_push,
|
||||
NGX_HTTP_LOC_CONF_OFFSET,
|
||||
ngx_http_v2_obsolete,
|
||||
0,
|
||||
0,
|
||||
NULL },
|
||||
|
||||
@@ -314,10 +319,11 @@ ngx_http_v2_create_srv_conf(ngx_conf_t *cf)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
h2scf->enable = NGX_CONF_UNSET;
|
||||
|
||||
h2scf->pool_size = NGX_CONF_UNSET_SIZE;
|
||||
|
||||
h2scf->concurrent_streams = NGX_CONF_UNSET_UINT;
|
||||
h2scf->concurrent_pushes = NGX_CONF_UNSET_UINT;
|
||||
|
||||
h2scf->preread_size = NGX_CONF_UNSET_SIZE;
|
||||
|
||||
@@ -333,12 +339,12 @@ ngx_http_v2_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
ngx_http_v2_srv_conf_t *prev = parent;
|
||||
ngx_http_v2_srv_conf_t *conf = child;
|
||||
|
||||
ngx_conf_merge_value(conf->enable, prev->enable, 0);
|
||||
|
||||
ngx_conf_merge_size_value(conf->pool_size, prev->pool_size, 4096);
|
||||
|
||||
ngx_conf_merge_uint_value(conf->concurrent_streams,
|
||||
prev->concurrent_streams, 128);
|
||||
ngx_conf_merge_uint_value(conf->concurrent_pushes,
|
||||
prev->concurrent_pushes, 10);
|
||||
|
||||
ngx_conf_merge_size_value(conf->preread_size, prev->preread_size, 65536);
|
||||
|
||||
@@ -359,17 +365,8 @@ ngx_http_v2_create_loc_conf(ngx_conf_t *cf)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* set by ngx_pcalloc():
|
||||
*
|
||||
* h2lcf->pushes = NULL;
|
||||
*/
|
||||
|
||||
h2lcf->chunk_size = NGX_CONF_UNSET_SIZE;
|
||||
|
||||
h2lcf->push_preload = NGX_CONF_UNSET;
|
||||
h2lcf->push = NGX_CONF_UNSET;
|
||||
|
||||
return h2lcf;
|
||||
}
|
||||
|
||||
@@ -382,72 +379,6 @@ ngx_http_v2_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
|
||||
ngx_conf_merge_size_value(conf->chunk_size, prev->chunk_size, 8 * 1024);
|
||||
|
||||
ngx_conf_merge_value(conf->push, prev->push, 1);
|
||||
|
||||
if (conf->push && conf->pushes == NULL) {
|
||||
conf->pushes = prev->pushes;
|
||||
}
|
||||
|
||||
ngx_conf_merge_value(conf->push_preload, prev->push_preload, 0);
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
ngx_http_v2_push(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
ngx_http_v2_loc_conf_t *h2lcf = conf;
|
||||
|
||||
ngx_str_t *value;
|
||||
ngx_http_complex_value_t *cv;
|
||||
ngx_http_compile_complex_value_t ccv;
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
if (ngx_strcmp(value[1].data, "off") == 0) {
|
||||
|
||||
if (h2lcf->pushes) {
|
||||
return "\"off\" parameter cannot be used with URI";
|
||||
}
|
||||
|
||||
if (h2lcf->push == 0) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
h2lcf->push = 0;
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
if (h2lcf->push == 0) {
|
||||
return "URI cannot be used with \"off\" parameter";
|
||||
}
|
||||
|
||||
h2lcf->push = 1;
|
||||
|
||||
if (h2lcf->pushes == NULL) {
|
||||
h2lcf->pushes = ngx_array_create(cf->pool, 1,
|
||||
sizeof(ngx_http_complex_value_t));
|
||||
if (h2lcf->pushes == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
cv = ngx_array_push(h2lcf->pushes);
|
||||
if (cv == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
|
||||
|
||||
ccv.cf = cf;
|
||||
ccv.value = &value[1];
|
||||
ccv.complex_value = cv;
|
||||
|
||||
if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
@@ -551,10 +482,17 @@ ngx_http_v2_obsolete(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
ngx_conf_deprecated_t *d = cmd->post;
|
||||
|
||||
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
||||
"the \"%s\" directive is obsolete, "
|
||||
"use the \"%s\" directive instead",
|
||||
d->old_name, d->new_name);
|
||||
if (d) {
|
||||
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
||||
"the \"%s\" directive is obsolete, "
|
||||
"use the \"%s\" directive instead",
|
||||
d->old_name, d->new_name);
|
||||
|
||||
} else {
|
||||
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
||||
"the \"%V\" directive is obsolete, ignored",
|
||||
&cmd->name);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
@@ -20,26 +20,9 @@ typedef struct {
|
||||
} ngx_http_v2_main_conf_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
size_t pool_size;
|
||||
ngx_uint_t concurrent_streams;
|
||||
ngx_uint_t concurrent_pushes;
|
||||
size_t preread_size;
|
||||
ngx_uint_t streams_index_mask;
|
||||
} ngx_http_v2_srv_conf_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
size_t chunk_size;
|
||||
|
||||
ngx_flag_t push_preload;
|
||||
|
||||
ngx_flag_t push;
|
||||
ngx_array_t *pushes;
|
||||
} ngx_http_v2_loc_conf_t;
|
||||
|
||||
|
||||
extern ngx_module_t ngx_http_v2_module;
|
||||
|
||||
|
||||
#endif /* _NGX_HTTP_V2_MODULE_H_INCLUDED_ */
|
||||
@@ -283,11 +283,11 @@ ngx_mail_init_session_handler(ngx_event_t *rev)
|
||||
|
||||
s = c->data;
|
||||
|
||||
sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
|
||||
|
||||
if (sslcf->enable || s->ssl) {
|
||||
if (s->ssl) {
|
||||
c->log->action = "SSL handshaking";
|
||||
|
||||
sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
|
||||
|
||||
ngx_mail_ssl_init_connection(&sslcf->ssl, c);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,6 @@ static int ngx_mail_ssl_alpn_select(ngx_ssl_conn_t *ssl_conn,
|
||||
static void *ngx_mail_ssl_create_conf(ngx_conf_t *cf);
|
||||
static char *ngx_mail_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child);
|
||||
|
||||
static char *ngx_mail_ssl_enable(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
static char *ngx_mail_ssl_starttls(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
static char *ngx_mail_ssl_password_file(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
@@ -66,24 +64,12 @@ static ngx_conf_enum_t ngx_mail_ssl_verify[] = {
|
||||
};
|
||||
|
||||
|
||||
static ngx_conf_deprecated_t ngx_mail_ssl_deprecated = {
|
||||
ngx_conf_deprecated, "ssl", "listen ... ssl"
|
||||
};
|
||||
|
||||
|
||||
static ngx_conf_post_t ngx_mail_ssl_conf_command_post =
|
||||
{ ngx_mail_ssl_conf_command_check };
|
||||
|
||||
|
||||
static ngx_command_t ngx_mail_ssl_commands[] = {
|
||||
|
||||
{ ngx_string("ssl"),
|
||||
NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG,
|
||||
ngx_mail_ssl_enable,
|
||||
NGX_MAIL_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_mail_ssl_conf_t, enable),
|
||||
&ngx_mail_ssl_deprecated },
|
||||
|
||||
{ ngx_string("starttls"),
|
||||
NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_mail_ssl_starttls,
|
||||
@@ -323,7 +309,6 @@ ngx_mail_ssl_create_conf(ngx_conf_t *cf)
|
||||
* scf->shm_zone = NULL;
|
||||
*/
|
||||
|
||||
scf->enable = NGX_CONF_UNSET;
|
||||
scf->starttls = NGX_CONF_UNSET_UINT;
|
||||
scf->certificates = NGX_CONF_UNSET_PTR;
|
||||
scf->certificate_keys = NGX_CONF_UNSET_PTR;
|
||||
@@ -350,7 +335,6 @@ ngx_mail_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
char *mode;
|
||||
ngx_pool_cleanup_t *cln;
|
||||
|
||||
ngx_conf_merge_value(conf->enable, prev->enable, 0);
|
||||
ngx_conf_merge_uint_value(conf->starttls, prev->starttls,
|
||||
NGX_MAIL_STARTTLS_OFF);
|
||||
|
||||
@@ -393,9 +377,6 @@ ngx_mail_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
if (conf->listen) {
|
||||
mode = "listen ... ssl";
|
||||
|
||||
} else if (conf->enable) {
|
||||
mode = "ssl";
|
||||
|
||||
} else if (conf->starttls != NGX_MAIL_STARTTLS_OFF) {
|
||||
mode = "starttls";
|
||||
|
||||
@@ -544,34 +525,6 @@ ngx_mail_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
ngx_mail_ssl_enable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
ngx_mail_ssl_conf_t *scf = conf;
|
||||
|
||||
char *rv;
|
||||
|
||||
rv = ngx_conf_set_flag_slot(cf, cmd, conf);
|
||||
|
||||
if (rv != NGX_CONF_OK) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (scf->enable && (ngx_int_t) scf->starttls > NGX_MAIL_STARTTLS_OFF) {
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||
"\"starttls\" directive conflicts with \"ssl on\"");
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
if (!scf->listen) {
|
||||
scf->file = cf->conf_file->file.name.data;
|
||||
scf->line = cf->conf_file->line;
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
ngx_mail_ssl_starttls(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
@@ -585,12 +538,6 @@ ngx_mail_ssl_starttls(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (scf->enable == 1 && (ngx_int_t) scf->starttls > NGX_MAIL_STARTTLS_OFF) {
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||
"\"ssl\" directive conflicts with \"starttls\"");
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
if (!scf->listen) {
|
||||
scf->file = cf->conf_file->file.name.data;
|
||||
scf->line = cf->conf_file->line;
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_flag_t enable;
|
||||
ngx_flag_t prefer_server_ciphers;
|
||||
|
||||
ngx_ssl_t ssl;
|
||||
|
||||
Reference in New Issue
Block a user