[PATCH] Option to disable buffering in uwsgi module

Maxim Dounin mdounin at mdounin.ru
Fri Sep 30 10:17:21 UTC 2011


Hello!

On Fri, Sep 30, 2011 at 01:00:12PM +0300, Peter Smit wrote:

> Attached and inlined is a patch which makes it possible to disable
> buffering for the fastcgi,scgi and uwsgi modules in the following
> ways:
> 
> - By using a {module}_buffering on|off configuration value
> - By using the X-Accel-Buffering header
> 
> This is essential for any apps that want to do comet / websocket style
> communications.
> 
> 
> 
> Index: ngx_http_fastcgi_module.c
> ===================================================================
> --- ngx_http_fastcgi_module.c	(revision 4157)
> +++ ngx_http_fastcgi_module.c	(working copy)
> @@ -228,6 +228,13 @@
>        offsetof(ngx_http_fastcgi_loc_conf_t, upstream.store_access),
>        NULL },
> 
> +    { ngx_string("fastcgi_buffering"),
> +      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_fastcgi_loc_conf_t, upstream.buffering),
> +      NULL },
> +
>      { ngx_string("fastcgi_ignore_client_abort"),
>        NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
>        ngx_conf_set_flag_slot,
> @@ -602,7 +609,7 @@
>      u->abort_request = ngx_http_fastcgi_abort_request;
>      u->finalize_request = ngx_http_fastcgi_finalize_request;
> 
> -    u->buffering = 1;
> +    u->buffering = flcf->upstream.buffering;
> 
>      u->pipe = ngx_pcalloc(r->pool, sizeof(ngx_event_pipe_t));
>      if (u->pipe == NULL) {
> @@ -2072,6 +2079,8 @@
>      conf->catch_stderr = NGX_CONF_UNSET_PTR;
> 
>      conf->keep_conn = NGX_CONF_UNSET;
> +
> +    conf->upstream.change_buffering = 1;
> 
>      ngx_str_set(&conf->upstream.module, "fastcgi");
> 

The fastcgi part is just wrong.

You can't enable non-buffered mode for fastcgi without providing 
appropriate input filter, this will result in fastcgi response 
(i.e. with all fastcgi framing and so on) to be sent to client 
(or, rather, part of it).

> Index: ngx_http_scgi_module.c
> ===================================================================
> --- ngx_http_scgi_module.c	(revision 4157)
> +++ ngx_http_scgi_module.c	(working copy)
> @@ -96,6 +96,13 @@
>        offsetof(ngx_http_scgi_loc_conf_t, upstream.store_access),
>        NULL },
> 
> +    { ngx_string("scgi_buffering"),
> +      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_scgi_loc_conf_t, upstream.buffering),
> +      NULL },
> +
>      { ngx_string("scgi_ignore_client_abort"),
>        NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
>        ngx_conf_set_flag_slot,
> @@ -412,7 +419,7 @@
>      u->abort_request = ngx_http_scgi_abort_request;
>      u->finalize_request = ngx_http_scgi_finalize_request;
> 
> -    u->buffering = 1;
> +    u->buffering = scf->upstream.buffering;
> 
>      u->pipe = ngx_pcalloc(r->pool, sizeof(ngx_event_pipe_t));
>      if (u->pipe == NULL) {
> @@ -1038,6 +1045,8 @@
>      /* "scgi_cyclic_temp_file" is disabled */
>      conf->upstream.cyclic_temp_file = 0;
> 
> +    conf->upstream.change_buffering = 1;
> +
>      ngx_str_set(&conf->upstream.module, "scgi");
> 
>      return conf;
> Index: ngx_http_uwsgi_module.c
> ===================================================================
> --- ngx_http_uwsgi_module.c	(revision 4157)
> +++ ngx_http_uwsgi_module.c	(working copy)
> @@ -123,6 +123,13 @@
>        offsetof(ngx_http_uwsgi_loc_conf_t, upstream.store_access),
>        NULL },
> 
> +    { ngx_string("uwsgi_buffering"),
> +      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_uwsgi_loc_conf_t, upstream.buffering),
> +      NULL },
> +
>      { ngx_string("uwsgi_ignore_client_abort"),
>        NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
>        ngx_conf_set_flag_slot,
> @@ -445,7 +452,7 @@
>      u->abort_request = ngx_http_uwsgi_abort_request;
>      u->finalize_request = ngx_http_uwsgi_finalize_request;
> 
> -    u->buffering = 1;
> +    u->buffering = uwcf->upstream.buffering;
> 
>      u->pipe = ngx_pcalloc(r->pool, sizeof(ngx_event_pipe_t));
>      if (u->pipe == NULL) {
> @@ -1091,6 +1098,8 @@
>      /* "uwsgi_cyclic_temp_file" is disabled */
>      conf->upstream.cyclic_temp_file = 0;
> 
> +    conf->upstream.change_buffering = 1;
> +
>      ngx_str_set(&conf->upstream.module, "uwsgi");
> 
>      return conf;

The scgi/uwsgi part looks ok.  I'll commit as soon as Igor approves.

Maxim Dounin



More information about the nginx-devel mailing list