Nginx-ru mailing list archive (nginx-ru@sysoev.ru)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: поддержка HTTP/1.1 для проксирования
Добрый вечер, Игорь !
> Да, получил, по нему есть два замечания. Во-первых, длину нужно вычиcлять
> так:
> len += sizeof(x_client_connection_status_header) - 1
> + r->headers_in.connection->value.len;
>
> А второе замечание связано как раз с падением.
Спасибо, я исправил. Ночью иногда работать вредно.
> > У меня вопрос, я обнаружил, что если включен параметр, который я добавил
> > и приходит запрос по HTTP 1.0, то nginx валится:
> >
> > Т.е. падает с ошибкой 17, как я понял - это хедеры неправильные.
> >
> > Как я понимаю, в моем случае не приходит хедер Connection от клиента и
> > r->headers_in.connection->value.data - пустое значение и соответственно
> > валится прокси модуль.
> >
> > Еще вопрос, r->headers_in.connection->value.data - всегда может иметь
> > только значения keep-alive или close, или может быть пустым или значение
> > keep-alive только если соединение с keep-alive, а иначе - пустое (т.е.
> > close) ?
>
> Если заголовка "Connection" нет, то r->headers_in.connection равен NULL.
> Это тоже нужно проверять, кроме p->lcf->set_x_client_connection_status.
> Что передавать в "X-Client-Connection" в этом случае - не знаю.
> Варианты такие:
> 1) для HTTP/1.1 (r->http_version == NGX_HTTP_VERSION_11)
> по умолчанию keep-alive.
> 1) для HTTP/1.0 и ниже (r->http_version <= NGX_HTTP_VERSION_10)
> по умолчанию close.
Понял, спасибо. Я дописал патч, высылаю его Вам для просмотра.
Я учел все условия и если Connection null, то я даю close в новом хедере.
А это модифицированный код для подмены Connection из хедера, работает в апаче
начиная с 2.0.51 (опция header - always):
# START OF HACK
# Set new headers from X-Client-Connection
RewriteEngine On
RewriteCond %{HTTP:X-Client-Connection} ^(.*)
RewriteRule ^.* - [env=REMOTE_X_CLIENT_CONNECTION:
%1,env=REMOTE_CLIENT_CONNECTION:%{HTTP:Connection}]
RequestHeader set Connection "%{REMOTE_X_CLIENT_CONNECTION}e"
RequestHeader unset X-Client-Connection
# Fix to old headers
Header always set Connection "%{REMOTE_CLIENT_CONNECTION}e"
env=REMOTE_CLIENT_CONNECTION
# END OF HACK
С Уважением,
Дмитрий.
Only in nginx-0.1.13.rapaman/: LOG
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.033462080 -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;
|