ПРОЕКТЫ 


  АРХИВ 


Apache-Talk @lexa.ru 

Inet-Admins @info.east.ru 

Filmscanners @halftone.co.uk 

Security-alerts @yandex-team.ru 

nginx-ru @sysoev.ru 


  СТАТЬИ 


  ПЕРСОНАЛЬНОЕ 


  ПРОГРАММЫ 



ПИШИТЕ
ПИСЬМА












     АРХИВ :: nginx-ru
Nginx-ru mailing list archive (nginx-ru@sysoev.ru)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Пара вопросов по nginx



On Wednesday 19 January 2005 12:05, SA wrote:
> И еще. Просто пожелание одной фичи, если
> возможно ее осуществить.
.........................
> некоторыми веб-приложениями(например,
> для определения примерного процента
> анонимных проксей во входящем траффике)
> - Connection, который становится равным
..................................
> директиву pass_real_connection, установка которой
> приведет к отправке неизменного
> заголовка Connection бэкенду. А на бэкенде
> просто отрубить Keep-Alive.

Такой патч сделан мной для версии 0.1.13, для версии 0.1.14 еще нет.

Патч прилагается (эта версия  патча включает в себя патч для 0.1.13 от Игоря 
Сысоева для решения ошибки "zero buffer..")

Заголовок включается директивой:
proxy_set_x_client_connection_status [on|off]

Соединение передается в заголовке: X-Client-Connection

2 Igor Sysoev - Я прошу разрешения выпускать этот патч и поддерживать его для 
всех версий nginx, пока не будет решения внести его в основную ветку.

С Уважением,
Дмитрий.

-- 
Remote Admin Service 
WWW: http://remote-admin-service.encrypted-life.net
Only in nginx-0.1.13.rapaman/: LOG
Only in nginx-0.1.13.rapaman/: Makefile
Only in nginx-0.1.13.rapaman/: objs
diff -ru nginx-0.1.13/src/event/ngx_event_pipe.c 
nginx-0.1.13.rapaman/src/event/ngx_event_pipe.c
--- nginx-0.1.13/src/event/ngx_event_pipe.c     2004-11-30 12:07:14.000000000 
-0500
+++ nginx-0.1.13.rapaman/src/event/ngx_event_pipe.c     2005-01-07 
17:39:48.371172024 -0500
@@ -379,7 +379,7 @@
 
 ngx_int_t ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p)
 {
-    off_t         bsize;
+    size_t        bsize;
     ngx_uint_t    flush;
     ngx_buf_t    *b;
     ngx_chain_t  *out, **ll, *cl, *tl;
@@ -433,16 +433,18 @@
             break;
         }
 
-        /* bsize is the size of the busy bufs */
+        /* bsize is the size of the busy recycled bufs */
 
         bsize = 0;
 
         for (cl = p->busy; cl; cl = cl->next) {
-            bsize += cl->buf->end - cl->buf->start;
+            if (cl->buf->recycled) {
+                bsize += cl->buf->end - cl->buf->start;
+            }
         }
 
         ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
-                       "pipe write busy: %O", bsize);
+                       "pipe write busy: %uz", bsize);
 
         out = NULL;
         ll = NULL;
@@ -452,19 +454,23 @@
             if (p->out) {
                 cl = p->out;
 
-                if (bsize + ngx_buf_size(cl->buf) > p->busy_size) {
+                if (cl->buf->recycled
+                    && bsize + cl->buf->last - cl->buf->pos > p->busy_size)
+                {
                     flush = 1;
                     break;
                 }
 
                 p->out = p->out->next;
-                ngx_event_pipe_free_shadow_raw_buf(&p->free_raw_bufs,
-                                                   cl->buf);
+
+                ngx_event_pipe_free_shadow_raw_buf(&p->free_raw_bufs, cl->buf);
 
             } else if (!p->cachable && p->in) {
                 cl = p->in;
 
-                if (bsize + ngx_buf_size(cl->buf) > p->busy_size) {
+                if (cl->buf->recycled
+                    && bsize + cl->buf->last - cl->buf->pos > p->busy_size)
+                {
                     flush = 1;
                     break;
                 }
@@ -475,7 +481,10 @@
                 break;
             }
 
-            bsize += ngx_buf_size(cl->buf);
+            if (cl->buf->recycled) {
+                bsize += cl->buf->last - cl->buf->pos;
+            }
+
             cl->next = NULL;
             ngx_chain_add_link(out, ll, cl);
         }
@@ -618,8 +627,6 @@
 
         b->in_file = 1;
         b->temp_file = 1;
-        b->temporary = 0;
-        b->recycled = 0;
 
         ngx_chain_add_link(p->out, p->last_out, cl);
 
@@ -781,7 +788,14 @@
                 b = cl->buf->shadow;
                 b->pos = b->last = b->start;
                 b->shadow = NULL;
-                ngx_alloc_link_and_set_buf(tl, b, p->pool, NGX_ABORT);
+
+                if (!(tl = ngx_alloc_chain_link(p->pool))) {
+                    return NGX_ABORT;
+                }
+
+                tl->buf = b;
+                tl->next = NULL;
+
                 ngx_event_pipe_add_free_buf(&p->free_raw_bufs, tl);
 
                 cl->buf->last_shadow = 0;
Only in nginx-0.1.13.rapaman/src/event: ngx_event_pipe.c.orig
Only in nginx-0.1.13.rapaman/src/event: ngx_event_pipe.c.rej
diff -ru nginx-0.1.13/src/http/modules/proxy/ngx_http_proxy_handler.c 
nginx-0.1.13.rapaman/src/http/modules/proxy/ngx_http_proxy_handler.c
--- nginx-0.1.13/src/http/modules/proxy/ngx_http_proxy_handler.c        
2004-12-10 07:52:06.000000000 -0500
+++ nginx-0.1.13.rapaman/src/http/modules/proxy/ngx_http_proxy_handler.c        
2004-12-27 18:11:26.000000000 -0500
@@ -105,6 +105,13 @@
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_proxy_loc_conf_t, set_x_url),
       NULL },
+/* rapaman hack */
+    { ngx_string("proxy_set_x_client_connection_status"),
+      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_proxy_loc_conf_t, set_x_client_connection_status),
+      NULL },
 
     { ngx_string("proxy_set_x_real_ip"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
@@ -1069,6 +1076,8 @@
 
     conf->preserve_host = NGX_CONF_UNSET;
     conf->set_x_url = NGX_CONF_UNSET;
+    /* rapaman hack */
+    conf->set_x_client_connection_status = NGX_CONF_UNSET;
     conf->set_x_real_ip = NGX_CONF_UNSET;
     conf->add_x_forwarded_for = NGX_CONF_UNSET;
 
@@ -1109,6 +1118,8 @@
 
     ngx_conf_merge_value(conf->preserve_host, prev->preserve_host, 0);
     ngx_conf_merge_value(conf->set_x_url, prev->set_x_url, 0);
+    /* rapaman hack */
+    ngx_conf_merge_value(conf->set_x_client_connection_status, 
prev->set_x_client_connection_status, 0);
     ngx_conf_merge_value(conf->set_x_real_ip, prev->set_x_real_ip, 0);
     ngx_conf_merge_value(conf->add_x_forwarded_for,
                          prev->add_x_forwarded_for, 0);
diff -ru nginx-0.1.13/src/http/modules/proxy/ngx_http_proxy_handler.h 
nginx-0.1.13.rapaman/src/http/modules/proxy/ngx_http_proxy_handler.h
--- nginx-0.1.13/src/http/modules/proxy/ngx_http_proxy_handler.h        
2004-11-21 12:24:16.000000000 -0500
+++ nginx-0.1.13.rapaman/src/http/modules/proxy/ngx_http_proxy_handler.h        
2004-12-27 18:12:13.000000000 -0500
@@ -77,6 +77,8 @@
     ngx_flag_t                       preserve_host;
     ngx_flag_t                       set_x_url;
     ngx_flag_t                       set_x_real_ip;
+    /* rapaman hack */
+    ngx_flag_t                       set_x_client_connection_status;
     ngx_flag_t                       add_x_forwarded_for;
     ngx_flag_t                       pass_server;
     ngx_flag_t                       pass_x_accel_expires;
diff -ru nginx-0.1.13/src/http/modules/proxy/ngx_http_proxy_upstream.c 
nginx-0.1.13.rapaman/src/http/modules/proxy/ngx_http_proxy_upstream.c
--- nginx-0.1.13/src/http/modules/proxy/ngx_http_proxy_upstream.c       
2004-11-30 11:55:15.000000000 -0500
+++ nginx-0.1.13.rapaman/src/http/modules/proxy/ngx_http_proxy_upstream.c       
2005-01-07 17:39:48.397168072 -0500
@@ -46,6 +46,9 @@
 static char  host_header[] = "Host: ";
 static char  x_url_header[] = "X-URL: http";
 static char  x_real_ip_header[] = "X-Real-IP: ";
+/*     rapaman hack for Connection header      */
+static char  x_client_connection_status_header[] = "X-Client-Connection: ";
+static char  x_client_connection_status_header_default_value[] = "close";
 static char  x_forwarded_for_header[] = "X-Forwarded-For: ";
 static char  connection_close_header[] = "Connection: close" CRLF;
 
@@ -183,7 +186,15 @@
     if (p->lcf->set_x_real_ip) {                          /* 2 is for "\r\n" */
         len += sizeof(x_real_ip_header) - 1 + INET_ADDRSTRLEN - 1 + 2;
     }
+/*     rapaman hack for Connection header      */
+    if (p->lcf->set_x_client_connection_status) {                          /* 
2 is for "\r\n" */
 
+       if (r->headers_in.connection != NULL && (r->http_version == 
NGX_HTTP_VERSION_11 || r->http_version <= NGX_HTTP_VERSION_10)) {
+           len += sizeof(x_client_connection_status_header) - 1 + 
r->headers_in.connection->value.len + 2;
+       } else {
+           len += sizeof(x_client_connection_status_header) - 1 + 
sizeof(x_client_connection_status_header_default_value) - 1 + 2;
+       }
+    }
 
     if (p->lcf->add_x_forwarded_for) {
         if (r->headers_in.x_forwarded_for) {
@@ -335,6 +346,24 @@
         *(b->last++) = CR; *(b->last++) = LF;
     }
 
+/*     rapaman hack for Connection header      */
+    /* the "X-Client-Connection" header */
+
+    if (p->lcf->set_x_client_connection_status) {
+        if (r->headers_in.connection != NULL && (r->http_version == 
NGX_HTTP_VERSION_11 || r->http_version <= NGX_HTTP_VERSION_10)) {
+           b->last = ngx_cpymem(b->last, x_client_connection_status_header,
+                             sizeof(x_client_connection_status_header) - 1);
+           b->last = ngx_cpymem(b->last, r->headers_in.connection->value.data,
+                             r->headers_in.connection->value.len);
+       } else {
+           b->last = ngx_cpymem(b->last, x_client_connection_status_header,
+                             sizeof(x_client_connection_status_header) - 1);
+           b->last = ngx_cpymem(b->last, 
x_client_connection_status_header_default_value,
+                             
sizeof(x_client_connection_status_header_default_value) - 1);
+       }
+        *(b->last++) = CR; *(b->last++) = LF;
+    }
+
 
     /* the "X-Forwarded-For" header */
 
@@ -397,6 +426,11 @@
             continue;
         }
 
+/* rapaman hack */
+        if (&header[i] == r->headers_in.x_client_connection_status && 
p->lcf->set_x_client_connection_status) {
+            continue;
+        }
+
         if (&header[i] == r->headers_in.x_url && p->lcf->set_x_url) {
             continue;
         }
@@ -1347,6 +1381,7 @@
     }
     ep->preread_bufs->buf = p->header_in;
     ep->preread_bufs->next = NULL;
+    p->header_in->recycled = 1;
 
     ep->preread_size = p->header_in->last - p->header_in->pos;
 
Only in nginx-0.1.13.rapaman/src/http/modules/proxy: 
ngx_http_proxy_upstream.c.orig
diff -ru nginx-0.1.13/src/http/ngx_http_request.c 
nginx-0.1.13.rapaman/src/http/ngx_http_request.c
--- nginx-0.1.13/src/http/ngx_http_request.c    2004-12-21 06:29:43.000000000 
-0500
+++ nginx-0.1.13.rapaman/src/http/ngx_http_request.c    2004-12-27 
19:04:34.000000000 -0500
@@ -85,6 +85,7 @@
                            offsetof(ngx_http_headers_in_t, x_forwarded_for) },
     { ngx_string("X-Real-IP"), offsetof(ngx_http_headers_in_t, x_real_ip) },
     { ngx_string("X-URL"), offsetof(ngx_http_headers_in_t, x_url) },
+    { ngx_string("X-Client-Connection"), offsetof(ngx_http_headers_in_t, 
x_client_connection_status) },
 #endif
     
     { ngx_null_string, 0 }
diff -ru nginx-0.1.13/src/http/ngx_http_request.h 
nginx-0.1.13.rapaman/src/http/ngx_http_request.h
--- nginx-0.1.13/src/http/ngx_http_request.h    2004-12-12 08:29:32.000000000 
-0500
+++ nginx-0.1.13.rapaman/src/http/ngx_http_request.h    2004-12-27 
19:08:06.000000000 -0500
@@ -149,6 +149,7 @@
     ngx_table_elt_t  *x_forwarded_for;
     ngx_table_elt_t  *x_real_ip;
     ngx_table_elt_t  *x_url;
+    ngx_table_elt_t  *x_client_connection_status; 
 #endif
 
     ngx_array_t       cookies;
diff -ru nginx-0.1.13/src/http/ngx_http_write_filter.c 
nginx-0.1.13.rapaman/src/http/ngx_http_write_filter.c
--- nginx-0.1.13/src/http/ngx_http_write_filter.c       2004-11-30 
10:44:36.000000000 -0500
+++ nginx-0.1.13.rapaman/src/http/ngx_http_write_filter.c       2005-01-07 
17:39:48.384170048 -0500
@@ -69,6 +69,15 @@
     for (cl = ctx->out; cl; cl = cl->next) {
         ll = &cl->next;
 
+        ngx_log_debug7(NGX_LOG_DEBUG_EVENT, r->connection->log, 0,
+                       "write old buf t:%d f:%d %p, pos %p, size: %z "
+                       "file: %O, size: %z",
+                       cl->buf->temporary, cl->buf->in_file,
+                       cl->buf->start, cl->buf->pos,
+                       cl->buf->last - cl->buf->pos,
+                       cl->buf->file_pos,
+                       cl->buf->file_last - cl->buf->file_pos);
+
 #if 1
         if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) {
             ngx_debug_point();
@@ -97,6 +106,15 @@
         *ll = cl;
         ll = &cl->next;
 
+        ngx_log_debug7(NGX_LOG_DEBUG_EVENT, r->connection->log, 0,
+                       "write new buf t:%d f:%d %p, pos %p, size: %z "
+                       "file: %O, size: %z",
+                       cl->buf->temporary, cl->buf->in_file,
+                       cl->buf->start, cl->buf->pos,
+                       cl->buf->last - cl->buf->pos,
+                       cl->buf->file_pos,
+                       cl->buf->file_last - cl->buf->file_pos);
+
 #if 1
         if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) {
             ngx_debug_point();


 




Copyright © Lexa Software, 1996-2009.