summaryrefslogtreecommitdiff
path: root/src/http
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2005-03-22 16:11:23 +0000
committerJonathan Kolb <jon@b0g.us>2005-03-22 16:11:23 +0000
commit766b94b670a551c0a881dad06f7bc404c51607ee (patch)
tree30ffd96d8209d6af8990ab701a1e4a62d7f62fee /src/http
parentc70429eafad3bdd2172cc50f1b0507668ba0dfcc (diff)
downloadnginx-766b94b670a551c0a881dad06f7bc404c51607ee.tar.gz
Changes with nginx 0.1.26 22 Mar 2005v0.1.26
*) Change: the invalid client header lines are now ignored and logged at the info level. *) Change: the host name is also logged in error log. *) Feature: the ngx_http_auth_basic_module module and the auth_basic and auth_basic_user_file directives.
Diffstat (limited to 'src/http')
-rw-r--r--src/http/modules/ngx_http_auth_basic_module.c436
-rw-r--r--src/http/modules/ngx_http_autoindex_module.c5
-rw-r--r--src/http/modules/ngx_http_fastcgi_module.c2
-rw-r--r--src/http/modules/ngx_http_userid_filter_module.c4
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.c6
-rw-r--r--src/http/ngx_http.c5
-rw-r--r--src/http/ngx_http_core_module.c5
-rw-r--r--src/http/ngx_http_parse.c34
-rw-r--r--src/http/ngx_http_request.c19
-rw-r--r--src/http/ngx_http_request.h7
-rw-r--r--src/http/ngx_http_special_response.c4
-rw-r--r--src/http/ngx_http_upstream.c4
12 files changed, 513 insertions, 18 deletions
diff --git a/src/http/modules/ngx_http_auth_basic_module.c b/src/http/modules/ngx_http_auth_basic_module.c
new file mode 100644
index 000000000..03314b5cf
--- /dev/null
+++ b/src/http/modules/ngx_http_auth_basic_module.c
@@ -0,0 +1,436 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ */
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+#include <ngx_http.h>
+
+
+#define NGX_HTTP_AUTH_BUF_SIZE 2048
+
+
+typedef struct {
+ ngx_str_t passwd;
+} ngx_http_auth_basic_ctx_t;
+
+
+typedef struct {
+ ngx_str_t realm;
+ ngx_str_t user_file;
+} ngx_http_auth_basic_loc_conf_t;
+
+
+static ngx_int_t ngx_http_auth_basic_handler(ngx_http_request_t *r);
+static ngx_int_t ngx_http_auth_basic_crypt_handler(ngx_http_request_t *r,
+ ngx_http_auth_basic_ctx_t *ctx, ngx_str_t *passwd, ngx_str_t *realm);
+static ngx_int_t ngx_http_auth_basic_set_realm(ngx_http_request_t *r,
+ ngx_str_t *realm);
+static void ngx_http_auth_basic_close(ngx_file_t *file);
+static void *ngx_http_auth_basic_create_loc_conf(ngx_conf_t *cf);
+static char *ngx_http_auth_basic_merge_loc_conf(ngx_conf_t *cf,
+ void *parent, void *child);
+static ngx_int_t ngx_http_auth_basic_init(ngx_cycle_t *cycle);
+static char *ngx_http_auth_basic(ngx_conf_t *cf, void *post, void *data);
+
+
+static ngx_conf_post_handler_pt ngx_http_auth_basic_p = ngx_http_auth_basic;
+
+static ngx_command_t ngx_http_auth_basic_commands[] = {
+
+ { ngx_string("auth_basic"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_str_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_auth_basic_loc_conf_t, realm),
+ &ngx_http_auth_basic_p },
+
+ { ngx_string("auth_basic_user_file"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_str_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_auth_basic_loc_conf_t, user_file),
+ NULL },
+
+ ngx_null_command
+};
+
+
+
+ngx_http_module_t ngx_http_auth_basic_module_ctx = {
+ NULL, /* pre conf */
+
+ NULL, /* create main configuration */
+ NULL, /* init main configuration */
+
+ NULL, /* create server configuration */
+ NULL, /* merge server configuration */
+
+ ngx_http_auth_basic_create_loc_conf, /* create location configuration */
+ ngx_http_auth_basic_merge_loc_conf /* merge location configuration */
+};
+
+
+ngx_module_t ngx_http_auth_basic_module = {
+ NGX_MODULE,
+ &ngx_http_auth_basic_module_ctx, /* module context */
+ ngx_http_auth_basic_commands, /* module directives */
+ NGX_HTTP_MODULE, /* module type */
+ ngx_http_auth_basic_init, /* init module */
+ NULL /* init process */
+};
+
+
+static ngx_int_t
+ngx_http_auth_basic_handler(ngx_http_request_t *r)
+{
+ off_t offset;
+ ssize_t n;
+ ngx_fd_t fd;
+ ngx_str_t auth, encoded, pwd;
+ ngx_uint_t i, login, len, left, passwd;
+ ngx_file_t file;
+ ngx_http_auth_basic_ctx_t *ctx;
+ ngx_http_auth_basic_loc_conf_t *alcf;
+ u_char buf[NGX_HTTP_AUTH_BUF_SIZE];
+ enum {
+ sw_login,
+ sw_passwd,
+ sw_skip
+ } state;
+
+ alcf = ngx_http_get_module_loc_conf(r, ngx_http_auth_basic_module);
+
+ if (alcf->realm.len == 0 || alcf->user_file.len == 0) {
+ return NGX_OK;
+ }
+
+ ctx = ngx_http_get_module_ctx(r, ngx_http_auth_basic_module);
+
+ if (ctx) {
+ return ngx_http_auth_basic_crypt_handler(r, ctx, &ctx->passwd,
+ &alcf->realm);
+ }
+
+ if (r->headers_in.authorization == NULL) {
+ return ngx_http_auth_basic_set_realm(r, &alcf->realm);
+ }
+
+ encoded = r->headers_in.authorization->value;
+
+ if (encoded.len < sizeof("Basic ") - 1
+ || ngx_strncasecmp(encoded.data, "Basic ", sizeof("Basic ") - 1) != 0)
+ {
+ return ngx_http_auth_basic_set_realm(r, &alcf->realm);
+ }
+
+ encoded.len -= sizeof("Basic ") - 1;
+ encoded.data += sizeof("Basic ") - 1;
+
+ while (encoded.len && encoded.data[0] == ' ') {
+ encoded.len--;
+ encoded.data++;
+ }
+
+ if (encoded.len == 0) {
+ return ngx_http_auth_basic_set_realm(r, &alcf->realm);
+ }
+
+ auth.len = ngx_base64_decoded_length(encoded.len);
+ auth.data = ngx_palloc(r->pool, auth.len + 1);
+ if (auth.data == NULL) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ if (ngx_decode_base64(&auth, &encoded) != NGX_OK) {
+ return ngx_http_auth_basic_set_realm(r, &alcf->realm);
+ }
+
+ auth.data[auth.len] = '\0';
+
+ for (len = 0; len < auth.len; len++) {
+ if (auth.data[len] == ':') {
+ break;
+ }
+ }
+
+ if (len == auth.len) {
+ return ngx_http_auth_basic_set_realm(r, &alcf->realm);
+ }
+
+ r->headers_in.user.len = len;
+ r->headers_in.user.data = auth.data;
+ r->headers_in.passwd.len = auth.len - len - 1;
+ r->headers_in.passwd.data = &auth.data[len + 1];
+
+ fd = ngx_open_file(alcf->user_file.data, NGX_FILE_RDONLY, NGX_FILE_OPEN);
+
+ if (fd == NGX_INVALID_FILE) {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno,
+ ngx_open_file_n " \"%s\" failed", alcf->user_file.data);
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ ngx_memzero(&file, sizeof(ngx_file_t));
+
+ file.fd = fd;
+ file.name = alcf->user_file;
+ file.log = r->connection->log;
+
+ state = sw_login;
+ passwd = 0;
+ login = 0;
+ left = 0;
+ offset = 0;
+
+ for ( ;; ) {
+ n = ngx_read_file(&file, buf + left, NGX_HTTP_AUTH_BUF_SIZE - left,
+ offset);
+
+ if (n == NGX_ERROR) {
+ ngx_http_auth_basic_close(&file);
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ if (n == 0) {
+ break;
+ }
+
+ for (i = left; i < left + n; i++) {
+ switch (state) {
+
+ case sw_login:
+ if (login == 0 && buf[i] == '#') {
+ state = sw_skip;
+ break;
+ }
+
+ if (buf[i] != auth.data[login]) {
+ state = sw_skip;
+ break;
+ }
+
+ if (login == len) {
+ state = sw_passwd;
+ passwd = i + 1;
+ }
+
+ login++;
+
+ break;
+
+ case sw_passwd:
+ if (buf[i] == LF || buf[i] == CR || buf[i] == ':') {
+ buf[i] = '\0';
+
+ ngx_http_auth_basic_close(&file);
+
+ pwd.len = i - passwd;
+ pwd.data = &buf[passwd];
+
+ return ngx_http_auth_basic_crypt_handler(r, NULL, &pwd,
+ &alcf->realm);
+ }
+
+ break;
+
+ case sw_skip:
+ if (buf[i] == LF) {
+ state = sw_login;
+ login = 0;
+ }
+
+ break;
+ }
+ }
+
+ if (state == sw_passwd) {
+ left = left + n - passwd;
+ ngx_memcpy(buf, &buf[passwd], left);
+ passwd = 0;
+
+ } else {
+ left = 0;
+ }
+
+ offset += n;
+ }
+
+ ngx_http_auth_basic_close(&file);
+
+ return ngx_http_auth_basic_set_realm(r, &alcf->realm);
+}
+
+
+static ngx_int_t
+ngx_http_auth_basic_crypt_handler(ngx_http_request_t *r,
+ ngx_http_auth_basic_ctx_t *ctx, ngx_str_t *passwd, ngx_str_t *realm)
+{
+ ngx_int_t rc;
+ u_char *encrypted;
+
+ rc = ngx_crypt(r->pool, r->headers_in.passwd.data, passwd->data,
+ &encrypted);
+
+ ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "rc: %d user: \"%V\" salt: \"%s\"",
+ rc, &r->headers_in.user, passwd->data);
+
+ if (rc == NGX_OK) {
+ if (ngx_strcmp(encrypted, passwd->data) == 0) {
+ return NGX_OK;
+ }
+
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "encrypted: \"%s\"", encrypted);
+
+ return ngx_http_auth_basic_set_realm(r, realm);
+ }
+
+ if (rc == NGX_ERROR) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ /* rc == NGX_AGAIN */
+
+ if (ctx == NULL) {
+ ctx = ngx_palloc(r->pool, sizeof(ngx_http_auth_basic_ctx_t));
+ if (ctx == NULL) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ ngx_http_set_ctx(r, ctx, ngx_http_auth_basic_module);
+
+ ctx->passwd.len = passwd->len;
+ passwd->len++;
+
+ ctx->passwd.data = ngx_pstrdup(r->pool, passwd);
+ if (ctx->passwd.data == NULL) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ }
+
+ /* TODO: add mutex event */
+
+ return rc;
+}
+
+
+static ngx_int_t
+ngx_http_auth_basic_set_realm(ngx_http_request_t *r, ngx_str_t *realm)
+{
+ r->headers_out.www_authenticate = ngx_list_push(&r->headers_out.headers);
+ if (r->headers_out.www_authenticate == NULL) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ r->headers_out.www_authenticate->key.len = sizeof("WWW-Authenticate") - 1;
+ r->headers_out.www_authenticate->key.data = (u_char *) "WWW-Authenticate";
+ r->headers_out.www_authenticate->value = *realm;
+
+ return NGX_HTTP_UNAUTHORIZED;
+}
+
+static void
+ngx_http_auth_basic_close(ngx_file_t *file)
+{
+ if (ngx_close_file(file->fd) == NGX_FILE_ERROR) {
+ ngx_log_error(NGX_LOG_ALERT, file->log, ngx_errno,
+ ngx_close_file_n " \"%s\" failed", file->name.data);
+ }
+}
+
+
+static void *
+ngx_http_auth_basic_create_loc_conf(ngx_conf_t *cf)
+{
+ ngx_http_auth_basic_loc_conf_t *conf;
+
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_auth_basic_loc_conf_t));
+ if (conf == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ return conf;
+}
+
+
+static char *
+ngx_http_auth_basic_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
+{
+ ngx_http_auth_basic_loc_conf_t *prev = parent;
+ ngx_http_auth_basic_loc_conf_t *conf = child;
+
+ size_t len;
+ u_char *realm, *p;
+
+ if (conf->realm.data) {
+ if (conf->realm.len) {
+ len = sizeof("Basic realm=\"") - 1 + conf->realm.len + 1;
+
+ realm = ngx_palloc(cf->pool, len);
+ if (realm == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ p = ngx_cpymem(realm, "Basic realm=\"",
+ sizeof("Basic realm=\"") - 1);
+ p = ngx_cpymem(p, conf->realm.data, conf->realm.len);
+ *p = '"';
+
+ conf->realm.len = len;
+ conf->realm.data = realm;
+ }
+
+ } else {
+ conf->realm = prev->realm;
+ }
+
+
+ if (conf->user_file.data) {
+ if (ngx_conf_full_name(cf->cycle, &conf->user_file) != NGX_OK) {
+ return NGX_CONF_ERROR;
+ }
+
+ } else {
+ conf->user_file = prev->user_file;
+ }
+
+ return NGX_CONF_OK;
+}
+
+
+static ngx_int_t
+ngx_http_auth_basic_init(ngx_cycle_t *cycle)
+{
+ ngx_http_handler_pt *h;
+ ngx_http_core_main_conf_t *cmcf;
+
+ cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
+
+ h = ngx_array_push(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
+ if (h == NULL) {
+ return NGX_ERROR;
+ }
+
+ *h = ngx_http_auth_basic_handler;
+
+ return NGX_OK;
+}
+
+
+static char *
+ngx_http_auth_basic(ngx_conf_t *cf, void *post, void *data)
+{
+ ngx_str_t *realm = data;
+
+ if (ngx_strcmp(realm->data, "off") == 0) {
+ realm->len = 0;
+ realm->data = (u_char *) "";
+ }
+
+ return NGX_CONF_OK;
+}
diff --git a/src/http/modules/ngx_http_autoindex_module.c b/src/http/modules/ngx_http_autoindex_module.c
index a7b998678..ff163ed3c 100644
--- a/src/http/modules/ngx_http_autoindex_module.c
+++ b/src/http/modules/ngx_http_autoindex_module.c
@@ -39,7 +39,8 @@ typedef struct {
#define NGX_HTTP_AUTOINDEX_NAME_LEN 50
-static int ngx_http_autoindex_cmp_entries(const void *one, const void *two);
+static int ngx_libc_cdecl ngx_http_autoindex_cmp_entries(const void *one,
+ const void *two);
static ngx_int_t ngx_http_autoindex_error(ngx_http_request_t *r,
ngx_dir_t *dir, u_char *name);
static ngx_int_t ngx_http_autoindex_init(ngx_cycle_t *cycle);
@@ -446,7 +447,7 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
}
-static int
+static int ngx_libc_cdecl
ngx_http_autoindex_cmp_entries(const void *one, const void *two)
{
ngx_http_autoindex_entry_t *first = (ngx_http_autoindex_entry_t *) one;
diff --git a/src/http/modules/ngx_http_fastcgi_module.c b/src/http/modules/ngx_http_fastcgi_module.c
index a5f9a02c8..986215ba0 100644
--- a/src/http/modules/ngx_http_fastcgi_module.c
+++ b/src/http/modules/ngx_http_fastcgi_module.c
@@ -153,7 +153,9 @@ static ngx_str_t ngx_http_fastcgi_methods[] = {
};
+#if (NGX_PCRE)
static ngx_str_t ngx_http_fastcgi_uri = ngx_string("/");
+#endif
static ngx_http_header_t ngx_http_fastcgi_headers_in[] = {
diff --git a/src/http/modules/ngx_http_userid_filter_module.c b/src/http/modules/ngx_http_userid_filter_module.c
index 62d40ac34..4889fbffd 100644
--- a/src/http/modules/ngx_http_userid_filter_module.c
+++ b/src/http/modules/ngx_http_userid_filter_module.c
@@ -605,7 +605,7 @@ ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data)
u_char *p, *new;
- if (domain->len == 4 && ngx_strcmp(domain->data, "none") == 0) {
+ if (ngx_strcmp(domain->data, "none") == 0) {
domain->len = 0;
domain->data = (u_char *) "";
@@ -690,7 +690,7 @@ ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data)
{
ngx_str_t *p3p = data;
- if (p3p->len == 4 && ngx_strcmp(p3p->data, "none") == 0) {
+ if (ngx_strcmp(p3p->data, "none") == 0) {
p3p->len = 0;
p3p->data = (u_char *) "";
}
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index edad22cdf..2b76c1f9d 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -362,7 +362,9 @@ static ngx_str_t cache_reasons[] = {
};
+#if (NGX_PCRE)
static ngx_str_t ngx_http_proxy_uri = ngx_string("/");
+#endif
static ngx_int_t ngx_http_proxy_handler(ngx_http_request_t *r)
@@ -812,9 +814,11 @@ u_char *ngx_http_proxy_log_error(ngx_log_t *log, u_char *buf, size_t len)
peer = &ctx->proxy->upstream->peer;
p = ngx_snprintf(buf, len,
- " while %s, client: %V, URL: %V, upstream: http://%V%s%V",
+ " while %s, client: %V, host: %V, URL: \"%V\","
+ " upstream: http://%V%s%V",
ctx->proxy->action,
&r->connection->addr_text,
+ &r->server_name,
&r->unparsed_uri,
&peer->peers->peer[peer->cur_peer].name,
ctx->proxy->lcf->upstream->uri_separator,
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c
index e4c8f2e9c..2c97d7190 100644
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -11,7 +11,8 @@
static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
-static int ngx_cmp_server_names(const void *one, const void *two);
+static int ngx_libc_cdecl ngx_cmp_server_names(const void *one,
+ const void *two);
static ngx_int_t ngx_http_add_address(ngx_conf_t *cf,
ngx_http_in_port_t *in_port, ngx_http_listen_t *lscf,
ngx_http_core_srv_conf_t *cscf);
@@ -687,7 +688,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
-static int
+static int ngx_libc_cdecl
ngx_cmp_server_names(const void *one, const void *two)
{
ngx_http_server_name_t *first = (ngx_http_server_name_t *) one;
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 620d2e9e5..d1bf10457 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -35,7 +35,8 @@ static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
void *dummy);
static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
void *dummy);
-static int ngx_http_core_cmp_locations(const void *first, const void *second);
+static int ngx_libc_cdecl ngx_http_core_cmp_locations(const void *first,
+ const void *second);
static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
@@ -1257,7 +1258,7 @@ ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
}
-static int
+static int ngx_libc_cdecl
ngx_http_core_cmp_locations(const void *one, const void *two)
{
ngx_int_t rc;
diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c
index a7d8fe37f..7f031cf0d 100644
--- a/src/http/ngx_http_parse.c
+++ b/src/http/ngx_http_parse.c
@@ -497,9 +497,10 @@ ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b)
sw_space_before_value,
sw_value,
sw_space_after_value,
+ sw_ignore_line,
+ sw_skip_line,
sw_almost_done,
- sw_header_almost_done,
- sw_ignore_line
+ sw_header_almost_done
} state;
state = r->state;
@@ -511,6 +512,8 @@ ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b)
/* first char */
case sw_start:
+ r->invalid_header = 0;
+
switch (ch) {
case CR:
r->header_end = p;
@@ -528,7 +531,7 @@ ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b)
break;
}
- if (ch == '-' || ch == '_' || ch == '~' || ch == '.') {
+ if (ch == '-') {
break;
}
@@ -536,7 +539,9 @@ ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b)
break;
}
- return NGX_HTTP_PARSE_INVALID_HEADER;
+ r->invalid_header = 1;
+ state = sw_skip_line;
+ break;
}
break;
@@ -554,7 +559,7 @@ ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b)
break;
}
- if (ch == '-' || ch == '_' || ch == '~' || ch == '.') {
+ if (ch == '-') {
break;
}
@@ -572,7 +577,9 @@ ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b)
break;
}
- return NGX_HTTP_PARSE_INVALID_HEADER;
+ r->invalid_header = 1;
+ state = sw_skip_line;
+ break;
/* space* before header value */
case sw_space_before_value:
@@ -637,6 +644,21 @@ ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b)
}
break;
+ /* skip header line */
+ case sw_skip_line:
+ switch (ch) {
+ case CR:
+ r->header_end = p;
+ state = sw_almost_done;
+ break;
+ case LF:
+ r->header_end = p;
+ goto done;
+ default:
+ break;
+ }
+ break;
+
/* end of header line */
case sw_almost_done:
switch (ch) {
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index 3876e39e7..461c028d9 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -722,6 +722,7 @@ ngx_http_process_request_headers(ngx_event_t *rev)
{
ssize_t n;
ngx_int_t rc, rv, i;
+ ngx_str_t header;
ngx_table_elt_t *h, **cookie;
ngx_connection_t *c;
ngx_http_request_t *r;
@@ -771,6 +772,19 @@ ngx_http_process_request_headers(ngx_event_t *rev)
if (rc == NGX_OK) {
+ if (r->invalid_header) {
+
+ /* there was error while a header line parsing */
+
+ header.len = r->header_end - r->header_name_start;
+ header.data = r->header_name_start;
+
+ ngx_log_error(NGX_LOG_INFO, rev->log, 0,
+ "client sent invalid header: \"%V\", ignored,",
+ &header);
+ continue;
+ }
+
/* a header line has been parsed successfully */
r->headers_n++;
@@ -2371,6 +2385,11 @@ ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len)
len -= p - buf;
+ if (ctx->request->server_name.data) {
+ p = ngx_snprintf(p, len, ", host: %V", &ctx->request->server_name);
+ len -= p - buf;
+ }
+
p = ngx_snprintf(p, len, ", URL: \"%V\"", &ctx->request->unparsed_uri);
if (ctx->request->headers_in.referer == NULL) {
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index 413af2fab..a1e9ae554 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -55,6 +55,7 @@
#define NGX_HTTP_NOT_MODIFIED 304
#define NGX_HTTP_BAD_REQUEST 400
+#define NGX_HTTP_UNAUTHORIZED 401
#define NGX_HTTP_FORBIDDEN 403
#define NGX_HTTP_NOT_FOUND 404
#define NGX_HTTP_NOT_ALLOWED 405
@@ -157,6 +158,9 @@ typedef struct {
ngx_table_elt_t *accept_language;
#endif
+ ngx_str_t user;
+ ngx_str_t passwd;
+
ngx_array_t cookies;
size_t host_name_len;
@@ -194,6 +198,7 @@ typedef struct {
ngx_table_elt_t *last_modified;
ngx_table_elt_t *content_range;
ngx_table_elt_t *accept_ranges;
+ ngx_table_elt_t *www_authenticate;
ngx_table_elt_t *expires;
ngx_table_elt_t *cache_control;
ngx_table_elt_t *etag;
@@ -336,6 +341,8 @@ struct ngx_http_request_s {
unsigned uri_changed:1;
unsigned uri_changes:4;
+ unsigned invalid_header:1;
+
unsigned low_case_exten:1;
unsigned header_timeout_set:1;
diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c
index 44da5f388..2ccf51cf4 100644
--- a/src/http/ngx_http_special_response.c
+++ b/src/http/ngx_http_special_response.c
@@ -53,9 +53,9 @@ static char error_400_page[] =
static char error_401_page[] =
"<html>" CRLF
-"<head><title>401 Unauthorized</title></head>" CRLF
+"<head><title>401 Authorization Required</title></head>" CRLF
"<body bgcolor=\"white\">" CRLF
-"<center><h1>401 Unauthorized</h1></center>" CRLF
+"<center><h1>401 Authorization Required</h1></center>" CRLF
;
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index 3076df7de..0624c0f9a 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -1148,9 +1148,11 @@ ngx_http_upstream_log_error(ngx_log_t *log, u_char *buf, size_t len)
peer = &u->peer;
p = ngx_snprintf(buf, len,
- " while %s, client: %V, URL: %V, upstream: %V%V%s%V",
+ " while %s, client: %V, host: %V, URL: \"%V\","
+ " upstream: %V%V%s%V",
log->action,
&r->connection->addr_text,
+ &r->server_name,
&r->unparsed_uri,
&u->schema,
&peer->peers->peer[peer->cur_peer].name,