Nginx HTTP/2 server push reinforce

No Comments

Nginx HTTP/2 server push reinforce

--- a/src/http/v2/ngx_http_v2.c	Thu Feb 08 09:fifty four:Forty 9 2018 +0300
+++ b/src/http/v2/ngx_http_v2.c	Thu Feb 08 09:Fifty five:03 2018 +0300
@@ -35,12 +35,11 @@
 #outline NGX_HTTP_V2_GOAWAY_SIZE                  Eight
 #outline NGX_HTTP_V2_WINDOW_UPDATE_SIZE           four
 
-#outline NGX_HTTP_V2_STREAM_ID_SIZE               four
-
 #outline NGX_HTTP_V2_SETTINGS_PARAM_SIZE          6
 
 /* settings fields */
 #outline NGX_HTTP_V2_HEADER_TABLE_SIZE_SETTING    0x1
+#outline NGX_HTTP_V2_ENABLE_PUSH_SETTING          0x2
 #outline NGX_HTTP_V2_MAX_STREAMS_SETTING          0x3
 #outline NGX_HTTP_V2_INIT_WINDOW_SIZE_SETTING     0x4
 #outline NGX_HTTP_V2_MAX_FRAME_SIZE_SETTING       0x5
@@ -121,7 +A cardinal and twenty,7 @@
     u_char **pos, u_char *discontinuance, ngx_uint_t prefix);
 
 noise ngx_http_v2_stream_t *ngx_http_v2_create_stream(
-    ngx_http_v2_connection_t *h2c);
+    ngx_http_v2_connection_t *h2c, ngx_uint_t push);
 noise 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);
 noise ngx_http_v2_node_t *ngx_http_v2_get_closed_node(
@@ -162,6 +161,7 @@
     ngx_http_v2_header_t *header);
 noise ngx_int_t ngx_http_v2_construct_cookie_header(ngx_http_request_t *r);
 noise vacuum ngx_http_v2_run_request(ngx_http_request_t *r);
+static vacuum ngx_http_v2_run_request_handler(ngx_event_t *ev);
 noise ngx_int_t ngx_http_v2_process_request_body(ngx_http_request_t *r,
     u_char *pos, size_t dimension, ngx_uint_t final);
 noise ngx_int_t ngx_http_v2_filter_request_body(ngx_http_request_t *r);
@@ -249,6 +249,Eight @@
 
     h2scf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_v2_module);
 
+    h2c->concurrent_pushes = h2scf->concurrent_pushes;
+
     h2c->pool = ngx_create_pool(h2scf->pool_size, h2c->connection->log);
     if (h2c->pool == NULL) 
         ngx_http_close_connection(c);
@@ -366,7 +368,9 @@
             damage;
         
 
-        if (n == set && (h2c->insist.incomplete || h2c->processing)) {
+        if (n == zero
+            && (h2c->insist.incomplete || h2c->processing || h2c->pushing))
+        
             ngx_log_error(NGX_LOG_INFO, c->log, zero,
                           "client in strategy winking connection");
         
@@ -405,7 +409,7 @@
 
     h2c->blocked = zero;
 
-    if (h2c->processing) {
+    if (h2c->processing || h2c->pushing)  h2c->processing) 
 
-    instruction = ngx_http_v2_create_stream(h2c);
+    instruction = ngx_http_v2_create_stream(h2c, zero);
     if (stream == NULL) 
         convey ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
     
@@ -1909,6 +1913,11 @@
                       "client canceled instruction %ui", h2c->insist.sid);
         damage;
 
+    housing NGX_HTTP_V2_REFUSED_STREAM:
+        ngx_log_error(NGX_LOG_INFO, fc->log, zero,
+                      "client refused instruction %ui", h2c->insist.sid);
+        damage;
+
     housing NGX_HTTP_V2_INTERNAL_ERROR:
         ngx_log_error(NGX_LOG_INFO, fc->log, zero,
                       "client terminated instruction %ui cod to the interior error",
@@ -1966,6 +1975,7 @@
 
     ssize_t                   window_delta;
     ngx_uint_t                identity, fee;
+    ngx_http_v2_srv_conf_t   *h2scf;
     ngx_http_v2_out_frame_t  *physique;
 
     window_delta = zero;
@@ -2016,6 +2026,27 @@
             h2c->frame_size = fee;
             damage;
 
+        housing NGX_HTTP_V2_ENABLE_PUSH_SETTING:
+
+            if (fee > 1) 
+                ngx_log_error(NGX_LOG_INFO, h2c->connection->log, zero,
+                              "client despatched SETTINGS habitus with incorrect "
+                              "ENABLE_PUSH gift %ui", fee);
+
+                convey ngx_http_v2_connection_error(h2c,
+                                                    NGX_HTTP_V2_PROTOCOL_ERROR);
+            
+
+            h2c->push_disabled = !fee;
+            damage;
+
+        housing 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(fee, h2scf->concurrent_pushes);
+            damage;
+
         default:
             damage;
         
@@ -2483,6 +2514,119 @@
 
 
 
+ngx_int_t
+ngx_http_v2_push_stream(ngx_http_v2_connection_t *h2c, ngx_uint_t count,
+    size_t request_length, ngx_str_t *course, ngx_str_t *authority)
+
+    ngx_int_t              rc;
+    ngx_str_t              fee;
+    ngx_connection_t      *fc;
+    ngx_http_request_t    *r;
+    ngx_http_v2_node_t    *node;
+    ngx_http_v2_stream_t  *stream;
+
+    convexity = ngx_http_v2_get_node_by_id(h2c, h2c->last_push, 1);
+
+    if (node == NULL) 
+        convey NGX_ERROR;
+    
+
+    if (node->guardian) 
+        ngx_queue_remove(&node->reuse);
+        h2c->closed_nodes--;
+    
+
+    instruction = ngx_http_v2_create_stream(h2c, 1);
+    if (stream == NULL) 
+        convey NGX_ERROR;
+    
+
+    stream->pool = ngx_create_pool(1024, h2c->connection->log);
+    if (stream->pool == NULL) 
+        convey NGX_ERROR;
+    
+
+    r = stream->ask;
+    fc = r->connection;
+
+    r->request_length = request_length;
+
+    stream->in_closed = 1;
+    stream->node = node;
+
+    node->stream = stream;
+
+    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, zero,
+                   "http2 near instruction sid:%ui "
+                   "is reckoning on %ui excl:zero weight:sixteen",
+                   h2c->last_push, count);
+
+    node->weight = NGX_HTTP_V2_DEFAULT_WEIGHT;
+    ngx_http_v2_set_dependency(h2c, node, count, zero);
+
+    r->method_name = ngx_http_core_get_method;
+    r->methodology = NGX_HTTP_GET;
+
+    r->schema_start = (u_char *) "https";
+
+#if (NGX_HTTP_SSL)
+    if (fc->ssl) 
+        r->schema_end = r->schema_start + 5;
+
+     else
+#endif
+    
+        r->schema_end = r->schema_start + four;
+    
+
+    fee.len = authority->len;
+
+    fee.records = ngx_pstrdup(stream->pool, authority);
+    if (fee.records == NULL) 
+        convey NGX_ERROR;
+    
+
+    rc = ngx_http_v2_parse_authority(r, &fee);
+
+    if (rc != NGX_OK) 
+        goto error;
+    
+
+    fee.len = course->len;
+
+    fee.records = ngx_pstrdup(stream->pool, course);
+    if (fee.records == NULL) 
+        convey NGX_ERROR;
+    
+
+    rc = ngx_http_v2_parse_path(r, &fee);
+
+    if (rc != NGX_OK) 
+        goto error;
+    
+
+    fc->write->handler = ngx_http_v2_run_request_handler;
+    ngx_post_event(fc->write, &ngx_posted_events);
+
+    convey NGX_OK;
+
+error:
+
+    if (rc == NGX_ABORT) 
+        convey NGX_ERROR;
+    
+
+    if (rc == NGX_DECLINED) 
+        ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
+        convey NGX_ERROR;
+    
+
+    (void) ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
+
+    convey NGX_ERROR;
+
+
+
 noise ngx_int_t
 ngx_http_v2_send_settings(ngx_http_v2_connection_t *h2c)
 
@@ -2743,7 +2887,7 @@
 
 
 noise ngx_http_v2_stream_t *
-ngx_http_v2_create_stream(ngx_http_v2_connection_t *h2c)
+ngx_http_v2_create_stream(ngx_http_v2_connection_t *h2c, ngx_uint_t push)
 
     ngx_log_t                 *log;
     ngx_event_t               *rev, *wev;
@@ -2798,7 +2942,thirteen @@
     ngx_memcpy(log, h2c->connection->log, sizeof(ngx_log_t));
 
     log->records = ctx;
-    log->action = "reading computer communicate headers";
+
+    if (push) 
+        log->action = "processing pushed communicate headers";
+
+     added 
+        log->action = "reading computer communicate headers";
+    
 
     ngx_memzero(rev, sizeof(ngx_event_t));
 
@@ -2870,7 +3020,12 @@
     stream->send_window = h2c->init_window;
     stream->recv_window = h2scf->preread_size;
 
-    h2c->processing++;
+    if (push) 
+        h2c->pushing++;
+
+     added 
+        h2c->processing++;
+    
 
     convey stream;
 
@@ -3532,6 +3687,22 @@
 
 
 
+static void
+ngx_http_v2_run_request_handler(ngx_event_t *ev)
+
+    ngx_connection_t    *fc;
+    ngx_http_request_t  *r;
+
+    fc = ev->records;
+    r = fc->records;
+
+    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, zero,
+                   "http2 pace communicate handler");
+
+    ngx_http_v2_run_request(r);
+
+
+
 ngx_int_t
 ngx_http_v2_read_request_body(ngx_http_request_t *r)
 {
@@ -4003,6 +4174,7 @@
 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;
@@ -4011,9 +4183,10 @@
     h2c = stream->connection;
     convexity = stream->node;
 
-    ngx_log_debug3(NGX_LOG_DEBUG_HTTP, h2c->connection->log, zero,
-                   "http2 closed instruction %ui, queued %ui, processing %ui",
-                   node->identity, stream->queued, h2c->processing);
+    ngx_log_debug4(NGX_LOG_DEBUG_HTTP, h2c->connection->log, zero,
+                   "http2 closed instruction %ui, queued %ui, "
+                   "processing %ui, actuation %ui",
+                   node->identity, stream->queued, h2c->processing, h2c->pushing);
 
     fc = stream->ask->connection;
 
@@ -4069,6 +4242,Eight @@
         h2c->insist.stream = NULL;
     
 
+    near = stream->node->identity % 2 == zero;
+
     node->stream = NULL;
 
     ngx_queue_insert_tail(&h2c->closed, &node->reuse);
@@ -4116,9 +4291,14 @@
     fc->records = h2c->free_fake_connections;
     h2c->free_fake_connections = fc;
 
-    h2c->processing--;
-
-    if (h2c->processing || h2c->blocked) {
+    if (push) 
+        h2c->pushing--;
+
+     added 
+        h2c->processing--;
+    
+
+    if (h2c->processing || h2c->pushing || h2c->blocked) 
         return;
     
 
@@ -4267,7 +4447,7 @@
 
     c->error = 1;
 
-    if (!h2c->processing) 
+    if (!h2c->processing && !h2c->pushing) 
         ngx_http_close_connection(c);
         return;
     
@@ -4316,7 +4496,7 @@
 
     h2c->blocked = zero;
 
-    if (h2c->processing)  h2c->pushing) 
         return;
     
 
--- a/src/http/v2/ngx_http_v2.h	Thu Feb 08 09:fifty four:Forty 9 2018 +0300
+++ b/src/http/v2/ngx_http_v2.h	Thu Feb 08 09:Fifty five:03 2018 +0300
@@ -24,6 +24,Eight @@
 #outline NGX_HTTP_V2_MAX_FIELD                                                 
     (127 + (1 << (NGX_HTTP_V2_INT_OCTETS - 1) * 7) - 1)
 
+#outline NGX_HTTP_V2_STREAM_ID_SIZE       four
+
 #outline NGX_HTTP_V2_FRAME_HEADER_SIZE    9
 
 /* habitus forms */
@@ -118,6 +A cardinal and twenty,9 @@
 
     ngx_uint_t                       processing;
 
+    ngx_uint_t                       pushing;
+    ngx_uint_t                       concurrent_pushes;
+
     size_t                           send_window;
     size_t                           recv_window;
     size_t                           init_window;
@@ -143,12 +148,14 @@
     ngx_queue_t                      closed;
 
     ngx_uint_t                       last_sid;
+    ngx_uint_t                       last_push;
 
     unsigned                         closed_nodes:Eight;
     unsigned                         settings_ack:1;
     unsigned                         table_update:1;
     unsigned                         blocked:1;
     unsigned                         goaway:1;
+    unsigned                         push_disabled:1;
 ;
 
 
@@ -276,6 +283,10 @@
 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 count, size_t request_length, ngx_str_t *course,
+    ngx_str_t *authority);
+
 vacuum 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);
--- a/src/http/v2/ngx_http_v2_filter_module.c	Thu Feb 08 09:fifty four:Forty 9 2018 +0300
+++ b/src/http/v2/ngx_http_v2_filter_module.c	Thu Feb 08 09:Fifty five:03 2018 +0300
@@ -2,6 +2,7 @@
 /*
  * Copyright (C) Nginx, Inc.
  * Copyright (C) Valentin V. Bartenev
+ * Copyright (C) Ruslan Ermilov
  */
 
 
@@ -33,6 +34,thirteen @@
 #outline NGX_HTTP_V2_ENCODE_RAW            zero
 #outline NGX_HTTP_V2_ENCODE_HUFF           0x80
 
+#outline NGX_HTTP_V2_AUTHORITY_INDEX       1
+#outline NGX_HTTP_V2_METHOD_GET_INDEX      2
+#outline NGX_HTTP_V2_PATH_INDEX            four
+
+#outline NGX_HTTP_V2_SCHEME_HTTP_INDEX     6
+#outline NGX_HTTP_V2_SCHEME_HTTPS_INDEX    7
+
 #outline NGX_HTTP_V2_STATUS_INDEX          Eight
 #outline NGX_HTTP_V2_STATUS_200_INDEX      Eight
 #outline NGX_HTTP_V2_STATUS_204_INDEX      9
@@ -fifty three,12 +Sixty one,18 @@
 #outline NGX_HTTP_V2_NO_TRAILERS           (ngx_http_v2_out_frame_t *) -1
 
 
+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 *course, ngx_str_t *authority);
+
 noise u_char *ngx_http_v2_string_encode(u_char *dst, u_char *src, size_t len,
     u_char *tmp, ngx_uint_t decrease);
 noise u_char *ngx_http_v2_write_int(u_char *pos, ngx_uint_t prefix,
     ngx_uint_t fee);
 noise ngx_http_v2_out_frame_t *ngx_http_v2_create_headers_frame(
     ngx_http_request_t *r, u_char *pos, u_char *discontinuance, 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 *discontinuance);
 noise ngx_http_v2_out_frame_t *ngx_http_v2_create_trailers_frame(
     ngx_http_request_t *r);
 
@@ -eighty one,6 +95,Eight @@
 
 noise ngx_int_t ngx_http_v2_headers_frame_handler(
     ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *physique);
+static ngx_int_t ngx_http_v2_push_frame_handler(
+    ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *physique);
 noise ngx_int_t ngx_http_v2_data_frame_handler(
     ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *physique);
 noise ngx_inline vacuum ngx_http_v2_handle_frame(
@@ -241,6 +257,15 @@
 
     h2c = stream->connection;
 
+    if (!h2c->push_disabled && !h2c->goaway
+        && stream->node->identity % 2 == 1
+        && r->methodology != NGX_HTTP_HEAD)
+    
+        if (ngx_http_v2_push_resources(r) != NGX_OK) 
+            convey NGX_ERROR;
+        
+    
+
     len = h2c->table_update ? 1 : zero;
 
     len += estimation ? 1 : 1 + ngx_http_v2_literal_size("418");
@@ -638,7 +663,7 @@
 
     ngx_http_v2_queue_blocked_frame(h2c, physique);
 
-    stream->queued = 1;
+    stream->queued++;
 
     cln = ngx_http_cleanup_add(r, zero);
     if (cln == NULL) 
@@ -655,6 +680,365 @@
 
 
 
+static ngx_int_t
+ngx_http_v2_push_resources(ngx_http_request_t *r)
+
+    u_char                     *open, *discontinuance, *final;
+    ngx_int_t                   rc;
+    ngx_str_t                   course, authority;
+    ngx_uint_t                  i, push;
+    ngx_table_elt_t           **h;
+    ngx_connection_t           *fc;
+    ngx_http_v2_stream_t       *stream;
+    ngx_http_v2_loc_conf_t     *h2lcf;
+    ngx_http_v2_connection_t   *h2c;
+    ngx_http_complex_value_t   *pushes;
+
+    fc = r->connection;
+
+    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, zero, "http2 near sources");
+
+    instruction = r->stream;
+    h2c = stream->connection;
+
+    ngx_str_null(&authority);
+
+    h2lcf = ngx_http_get_module_loc_conf(r, ngx_http_v2_module);
+
+    if (h2lcf->pushes) 
+        pushes = h2lcf->pushes->elts;
+
+        for (i = zero; i pushes->nelts; i++) 
+
+            if (ngx_http_complex_value(r, &pushes[i], &course) != NGX_OK) 
+                convey NGX_ERROR;
+            
+
+            if (course.len == zero) 
+                proceed;
+            
+
+            if (course.len == threesome && ngx_strncmp(course.records, "off", three) == zero) 
+                proceed;
+            
+
+            rc = ngx_http_v2_push_resource(r, &course, &authority);
+
+            if (rc == NGX_ERROR) 
+                convey NGX_ERROR;
+            
+
+            if (rc == NGX_ABORT) 
+                convey NGX_OK;
+            
+
+            /* NGX_OK, NGX_DECLINED */
+        
+    
+
+    if (!h2lcf->push_preload) 
+        convey NGX_OK;
+    
+
+    h = r->headers_out.hyperlink.elts;
+
+    for (i = zero; i headers_out.hyperlink.nelts; i++) 
+
+    convey NGX_OK;
+
+
+
+static ngx_int_t
+ngx_http_v2_push_resource(ngx_http_request_t *r, ngx_str_t *course,
+    ngx_str_t *authority)
+
+
+
 noise u_char *
 ngx_http_v2_string_encode(u_char *dst, u_char *src, size_t len, u_char *tmp,
     ngx_uint_t decrease)
@@ -809,6 +1193,125 @@
 
 
 noise ngx_http_v2_out_frame_t *
+ngx_http_v2_create_push_frame(ngx_http_request_t *r, u_char *pos, u_char *discontinuance)
+
+    u_char                     form, flags;
+    size_t                     relaxation, frame_size, len;
+    ngx_buf_t                 *b;
+    ngx_chain_t               *cl, **ll;
+    ngx_http_v2_stream_t      *stream;
+    ngx_http_v2_out_frame_t   *physique;
+    ngx_http_v2_connection_t  *h2c;
+
+    instruction = r->stream;
+    h2c = stream->connection;
+    slackening = NGX_HTTP_V2_STREAM_ID_SIZE + (discontinuance - pos);
+
+    habitus = ngx_palloc(r->pool, sizeof(ngx_http_v2_out_frame_t));
+    if (physique == NULL) 
+        convey NULL;
+    
+
+    physique->handler = ngx_http_v2_push_frame_handler;
+    physique->stream = stream;
+    physique->length = relaxation;
+    physique->blocked = 1;
+    physique->fin = zero;
+
+    ll = &physique->first;
+
+    modify = NGX_HTTP_V2_PUSH_PROMISE_FRAME;
+    flags = NGX_HTTP_V2_NO_FLAG;
+    frame_size = h2c->frame_size;
+
+    for ( ;; ) 
+        if (relaxation <= frame_size) 
+            frame_size = relaxation;
+            flags 
+
+        b = ngx_create_temp_buf(r->pool,
+                                NGX_HTTP_V2_FRAME_HEADER_SIZE
+                                + ((form == NGX_HTTP_V2_PUSH_PROMISE_FRAME)
+                                   ? NGX_HTTP_V2_STREAM_ID_SIZE : zero));
+        if (b == NULL) 
+            convey NULL;
+        
+
+        b->final = ngx_http_v2_write_len_and_type(b->final, frame_size, form);
+        *b->final++ = flags;
+        b->final = ngx_http_v2_write_sid(b->final, stream->node->identity);
+
+        b->tag = (ngx_buf_tag_t) &ngx_http_v2_module;
+
+        if (form == NGX_HTTP_V2_PUSH_PROMISE_FRAME) 
+            h2c->last_push += 2;
+
+            b->final = ngx_http_v2_write_sid(b->final, h2c->last_push);
+            len = frame_size - NGX_HTTP_V2_STREAM_ID_SIZE;
+
+         added 
+            len = frame_size;
+        
+
+        cl = ngx_alloc_chain_link(r->pool);
+        if (cl == NULL) 
+            convey NULL;
+        
+
+        cl->buf = b;
+
+        *ll = cl;
+        ll = &cl->next;
+
+        b = ngx_calloc_buf(r->pool);
+        if (b == NULL) 
+            convey NULL;
+        
+
+        b->pos = pos;
+
+        pos += len;
+
+        b->final = pos;
+        b->open = b->pos;
+        b->discontinuance = b->final;
+        b->non unending = 1;
+
+        cl = ngx_alloc_chain_link(r->pool);
+        if (cl == NULL) 
+            convey NULL;
+        
+
+        cl->buf = b;
+
+        *ll = cl;
+        ll = &cl->next;
+
+        slackening -= frame_size;
+
+        if (relaxation) 
+            physique->length += NGX_HTTP_V2_FRAME_HEADER_SIZE;
+
+            modify = NGX_HTTP_V2_CONTINUATION_FRAME;
+            proceed;
+        
+
+        cl->next = NULL;
+        physique->final = cl;
+
+        ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, zero,
+                       "http2:%ui amend PUSH_PROMISE habitus %p: "
+                       "sid:%ui len:%uz",
+                       stream->node->identity, physique, h2c->last_push,
+                       physique->length);
+
+        convey physique;
+    
+
+
+
+static ngx_http_v2_out_frame_t *
 ngx_http_v2_create_trailers_frame(ngx_http_request_t *r)
 
     u_char            *pos, *open, *tmp;
@@ -1377,6 +1880,60 @@
 
 
 noise ngx_int_t
+ngx_http_v2_push_frame_handler(ngx_http_v2_connection_t *h2c,
+    ngx_http_v2_out_frame_t *physique)
+
+    ngx_chain_t           *cl, *ln;
+    ngx_http_v2_stream_t  *stream;
+
+    instruction = physique->stream;
+    cl = physique->first;
+
+    for ( ;; ) 
+        if (cl->buf->pos != cl->buf->final) 
+            physique->first = cl;
+
+            ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, zero,
+                           "http2:%ui PUSH_PROMISE habitus %p restricted into erst despatched partly",
+                           stream->node->identity, physique);
+
+            convey 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;
+
+         added 
+            cl->next = stream->free_bufs;
+            stream->free_bufs = cl;
+        
+
+        if (cl == physique->final) 
+            damage;
+        
+
+        cl = ln;
+    
+
+    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, zero,
+                   "http2:%ui PUSH_PROMISE habitus %p restricted into erst despatched",
+                   stream->node->identity, physique);
+
+    stream->ask->header_size += NGX_HTTP_V2_FRAME_HEADER_SIZE
+                                    + physique->length;
+
+    ngx_http_v2_handle_frame(stream, physique);
+
+    ngx_http_v2_handle_stream(h2c, stream);
+
+    convey NGX_OK;
+
+
+
+static ngx_int_t
 ngx_http_v2_data_frame_handler(ngx_http_v2_connection_t *h2c,
     ngx_http_v2_out_frame_t *physique)
 
--- a/src/http/v2/ngx_http_v2_module.c	Thu Feb 08 09:fifty four:Forty 9 2018 +0300
+++ b/src/http/v2/ngx_http_v2_module.c	Thu Feb 08 09:Fifty five:03 2018 +0300
@@ -27,6 +27,Eight @@
 noise burn *ngx_http_v2_merge_loc_conf(ngx_conf_t *cf, vacuum *guardian,
     vacuum *child);
 
+static burn *ngx_http_v2_push(ngx_conf_t *cf, ngx_command_t *cmd, vacuum *conf);
+
 noise burn *ngx_http_v2_recv_buffer_size(ngx_conf_t *cf, vacuum *post,
     vacuum *records);
 noise burn *ngx_http_v2_pool_size(ngx_conf_t *cf, vacuum *post, vacuum *records);
@@ -seventy three,6 +75,thirteen @@
       offsetof(ngx_http_v2_srv_conf_t, concurrent_streams),
       NULL ,
 
+    NGX_HTTP_SRV_CONF,
+
     NGX_HTTP_SRV_CONF,
 
+    NGX_HTTP_SRV_CONF,
+
+    NGX_CONF_TAKE1,
+      ngx_http_v2_push,
+      NGX_HTTP_LOC_CONF_OFFSET,
+      zero,
+      NULL ,
+
      ngx_string("spdy_recv_buffer_size"),
       NGX_HTTP_MAIN_CONF
 
+    /*
+     * expanse by ngx_pcalloc():
+     *
+     *     h2lcf->pushes = NULL;
+     */
+
     h2lcf->chunk_size = NGX_CONF_UNSET_SIZE;
 
+    h2lcf->push_preload = NGX_CONF_UNSET;
+    h2lcf->push = NGX_CONF_UNSET;
+
     convey h2lcf;
 
 
@@ -Four hundred,6 +435,seventy digit @@
 
     ngx_conf_merge_size_value(conf->chunk_size, prev->chunk_size, Eight * 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, zero);
+
+    convey NGX_CONF_OK;
+
+
+
+static burn *
+ngx_http_v2_push(ngx_conf_t *cf, ngx_command_t *cmd, vacuum *conf)
+
+    ngx_http_v2_loc_conf_t *h2lcf = conf;
+
+    ngx_str_t                         *fee;
+    ngx_http_complex_value_t          *cv;
+    ngx_http_compile_complex_value_t   ccv;
+
+    gift = cf->args->elts;
+
+    if (ngx_strcmp(fee[1].records, "off") == zero) 
+
+        if (h2lcf->pushes) 
+            convey ""off" constant cannot be feeble with URI";
+        
+
+        if (h2lcf->push == zero) 
+            convey "is replica";
+        
+
+        h2lcf->push = zero;
+        convey NGX_CONF_OK;
+    
+
+    if (h2lcf->push == zero) 
+        convey "URI cannot be feeble 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) 
+            convey NGX_CONF_ERROR;
+        
+    
+
+    cv = ngx_array_push(h2lcf->pushes);
+    if (cv == NULL) 
+        convey NGX_CONF_ERROR;
+    
+
+    ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
+
+    ccv.cf = cf;
+    ccv.fee = &fee[1];
+    ccv.complex_value = cv;
+
+    if (ngx_http_compile_complex_value(&ccv) != NGX_OK) 
+        convey NGX_CONF_ERROR;
+    
+
     convey NGX_CONF_OK;
 
 
--- a/src/http/v2/ngx_http_v2_module.h	Thu Feb 08 09:fifty four:Forty 9 2018 +0300
+++ b/src/http/v2/ngx_http_v2_module.h	Thu Feb 08 09:Fifty five:03 2018 +0300
@@ -23,6 +23,7 @@
 typedef struct {
     size_t                          pool_size;
     ngx_uint_t                      concurrent_streams;
+    ngx_uint_t                      concurrent_pushes;
     ngx_uint_t                      max_requests;
     size_t                          max_field_size;
     size_t                          max_header_size;
@@ -35,6 +36,11 @@
 
 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;
 
 

Be taught Extra

Nginx HTTP/2 server push reinforce

Nginx HTTP/2 server push reinforce

Nginx HTTP/2 server push reinforce

hackers, push, reinforce, server, tech, technology
hackers, push, reinforce, server, tech, technology

Leave a Reply

Your email address will not be published. Required fields are marked *