ПРОЕКТЫ 


  АРХИВ 


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: proxy_set_x_var



Добрый день,

Вот мой патч для передачи хедера соединения от клиента. Делался для 0.1.13 и 
подходит без напильника к 0.1.20.

Инструкция:

Включается директивой в конфиге:

proxy_set_x_client_connection_status on;

Дальше на бэкэнд передается заголовок - X-Client-Connection с реальным 
значением соединения клиента к nginx.

On Monday 21 February 2005 09:34, Serge wrote:
> Игорь, а можно пример использования этой директивы? Можно ли с помощью
> нее передать реальное значение хидера клиента "Connection" и как?

Скоро будет страница, как я обещал здесь, с патчами и прочей инфой к nginx. 
Никак не закончу html.

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

-- 
Remote Admin Service
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/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       
2004-12-29 13:32:54.000000000 -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;
         }
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;


 




Copyright © Lexa Software, 1996-2009.