diff src/stream/ngx_stream.c @ 6694:ea9dfe2f62e7

Stream: preread phase. In this phase, head of a stream is read and analysed before proceeding to the content phase. Amount of data read is controlled by the module implementing the phase, but not more than defined by the "preread_buffer_size" directive. The time spent on processing preread is controlled by the "preread_timeout" directive. The typical preread phase module will parse the beginning of a stream and set variable that may be used by the content phase, for example to make routing decision.
author Vladimir Homutov <vl@nginx.com>
date Thu, 15 Sep 2016 14:56:02 +0300
parents 3908156a51fa
children cebf5fed00bf
line wrap: on
line diff
--- a/src/stream/ngx_stream.c
+++ b/src/stream/ngx_stream.c
@@ -302,6 +302,13 @@ ngx_stream_init_phases(ngx_conf_t *cf, n
     }
 #endif
 
+    if (ngx_array_init(&cmcf->phases[NGX_STREAM_PREREAD_PHASE].handlers,
+                       cf->pool, 1, sizeof(ngx_stream_handler_pt))
+        != NGX_OK)
+    {
+        return NGX_ERROR;
+    }
+
     if (ngx_array_init(&cmcf->phases[NGX_STREAM_LOG_PHASE].handlers,
                        cf->pool, 1, sizeof(ngx_stream_handler_pt))
         != NGX_OK)
@@ -343,6 +350,10 @@ ngx_stream_init_phase_handlers(ngx_conf_
 
         switch (i) {
 
+        case NGX_STREAM_PREREAD_PHASE:
+            checker = ngx_stream_core_preread_phase;
+            break;
+
         case NGX_STREAM_CONTENT_PHASE:
             ph->checker = ngx_stream_core_content_phase;
             n++;