nginx-0.0.10-2004-09-06-22:45:00 import

This commit is contained in:
Igor Sysoev 2004-09-06 18:45:00 +00:00
parent 980a92472c
commit aab4d8c0c4
23 changed files with 138 additions and 198 deletions

View File

@ -226,7 +226,6 @@ HTTP_SRCS="src/http/ngx_http.c \
src/http/ngx_http_special_response.c \
src/http/ngx_http_request.c \
src/http/ngx_http_parse.c \
src/http/ngx_http_headers.c \
src/http/ngx_http_header_filter.c \
src/http/ngx_http_write_filter.c \
src/http/ngx_http_copy_filter.c \

View File

@ -20,7 +20,7 @@ void ngx_destroy_array(ngx_array_t *a);
void *ngx_push_array(ngx_array_t *a);
ngx_inline static ngx_int_t ngx_init_array0(ngx_array_t *array, ngx_pool_t *pool,
ngx_inline static ngx_int_t ngx_array_init(ngx_array_t *array, ngx_pool_t *pool,
ngx_uint_t n, size_t size)
{
if (!(array->elts = ngx_palloc(pool, n * size))) {

View File

@ -600,7 +600,7 @@ ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
}
}
if (!(file = ngx_push_list(&cycle->open_files))) {
if (!(file = ngx_list_push(&cycle->open_files))) {
return NULL;
}

View File

@ -81,7 +81,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
n = 20;
}
if (ngx_init_list(&cycle->open_files, pool, n, sizeof(ngx_open_file_t))
if (ngx_list_init(&cycle->open_files, pool, n, sizeof(ngx_open_file_t))
== NGX_ERROR)
{
ngx_destroy_pool(pool);

View File

@ -3,7 +3,7 @@
#include <ngx_core.h>
void *ngx_push_list(ngx_list_t *l)
void *ngx_list_push(ngx_list_t *l)
{
void *elt;
ngx_list_part_t *last;

View File

@ -24,7 +24,7 @@ typedef struct {
} ngx_list_t;
ngx_inline static ngx_int_t ngx_init_list(ngx_list_t *list, ngx_pool_t *pool,
ngx_inline static ngx_int_t ngx_list_init(ngx_list_t *list, ngx_pool_t *pool,
ngx_uint_t n, size_t size)
{
if (!(list->part.elts = ngx_palloc(pool, n * size))) {
@ -67,7 +67,7 @@ ngx_inline static ngx_int_t ngx_init_list(ngx_list_t *list, ngx_pool_t *pool,
*/
void *ngx_push_list(ngx_list_t *list);
void *ngx_list_push(ngx_list_t *list);
#endif /* _NGX_LIST_H_INCLUDED_ */

View File

@ -297,7 +297,7 @@ static ngx_int_t ngx_http_gzip_header_filter(ngx_http_request_t *r)
sizeof(ngx_http_gzip_ctx_t), NGX_ERROR);
ctx->request = r;
r->headers_out.content_encoding = ngx_push_list(&r->headers_out.headers);
r->headers_out.content_encoding = ngx_list_push(&r->headers_out.headers);
if (r->headers_out.content_encoding == NULL) {
return NGX_ERROR;
}

View File

@ -75,13 +75,13 @@ static ngx_int_t ngx_http_headers_filter(ngx_http_request_t *r)
if (conf->expires != NGX_HTTP_EXPIRES_OFF) {
if (!(expires = ngx_push_list(&r->headers_out.headers))) {
if (!(expires = ngx_list_push(&r->headers_out.headers))) {
return NGX_ERROR;
}
r->headers_out.expires = expires;
if (!(cc = ngx_push_list(&r->headers_out.headers))) {
if (!(cc = ngx_list_push(&r->headers_out.headers))) {
return NGX_ERROR;
}

View File

@ -123,7 +123,7 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r)
|| ngx_strncasecmp(r->headers_in.range->value.data, "bytes=", 6) != 0)
{
r->headers_out.accept_ranges = ngx_push_list(&r->headers_out.headers);
r->headers_out.accept_ranges = ngx_list_push(&r->headers_out.headers);
if (r->headers_out.accept_ranges == NULL) {
return NGX_ERROR;
}
@ -244,7 +244,7 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r)
r->headers_out.status = rc;
r->headers_out.ranges.nelts = 0;
r->headers_out.content_range = ngx_push_list(&r->headers_out.headers);
r->headers_out.content_range = ngx_list_push(&r->headers_out.headers);
if (r->headers_out.content_range == NULL) {
return NGX_ERROR;
}
@ -277,7 +277,7 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r)
if (r->headers_out.ranges.nelts == 1) {
r->headers_out.content_range =
ngx_push_list(&r->headers_out.headers);
ngx_list_push(&r->headers_out.headers);
if (r->headers_out.content_range == NULL) {
return NGX_ERROR;
}

View File

@ -341,8 +341,8 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
*last++ = '/';
*last = '\0';
if (!(r->headers_out.location = ngx_push_list(&r->headers_out.headers)))
{
r->headers_out.location = ngx_list_push(&r->headers_out.headers);
if (r->headers_out.location == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}

View File

@ -70,8 +70,8 @@ static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
return rc;
}
if (!(r->headers_out.content_type = ngx_push_list(&r->headers_out.headers)))
{
r->headers_out.content_type = ngx_list_push(&r->headers_out.headers);
if (r->headers_out.content_type == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}

View File

@ -381,7 +381,7 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"uid cookie: \"%s\"", cookie);
if (!(set_cookie = ngx_push_list(&r->headers_out.headers))) {
if (!(set_cookie = ngx_list_push(&r->headers_out.headers))) {
return NGX_ERROR;
}

View File

@ -107,7 +107,10 @@ typedef struct {
typedef struct {
ngx_list_t headers;
#if 0
ngx_table_t headers; /* it must be first field */
#endif
ngx_table_elt_t *date;
ngx_table_elt_t *server;

View File

@ -12,13 +12,31 @@ int ngx_http_proxy_copy_header(ngx_http_proxy_ctx_t *p,
ngx_http_proxy_headers_in_t *headers_in)
{
ngx_uint_t i;
ngx_list_part_t *part;
ngx_table_elt_t *ho, *h;
ngx_http_request_t *r;
r = p->request;
part = &headers_in->headers.part;
h = part->elts;
#if 0
h = headers_in->headers.elts;
for (i = 0; i < headers_in->headers.nelts; i++) {
#endif
for (i = 0 ; /* void */; i++) {
if (i >= part->nelts) {
if (part->next == NULL) {
break;
}
part = part->next;
h = part->elts;
i = 0;
}
/* ignore some headers */
@ -69,8 +87,7 @@ int ngx_http_proxy_copy_header(ngx_http_proxy_ctx_t *p,
/* copy some header pointers and set up r->headers_out */
if (!(ho = ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
{
if (!(ho = ngx_list_push(&r->headers_out.headers))) {
return NGX_ERROR;
}
@ -138,8 +155,7 @@ static int ngx_http_proxy_rewrite_location_header(ngx_http_proxy_ctx_t *p,
r = p->request;
uc = p->lcf->upstream;
location = ngx_http_add_header(&r->headers_out, ngx_http_headers_out);
if (location == NULL) {
if (!(location = ngx_list_push(&r->headers_out.headers))) {
return NGX_ERROR;
}

View File

@ -954,20 +954,22 @@ static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev)
/* init or reinit the p->upstream->headers_in.headers table */
if (p->upstream->headers_in.headers.elts) {
p->upstream->headers_in.headers.nelts = 0;
if (p->upstream->headers_in.headers.part.elts) {
p->upstream->headers_in.headers.part.nelts = 0;
p->upstream->headers_in.headers.part.next = NULL;
p->upstream->headers_in.headers.last =
&p->upstream->headers_in.headers.part;
ngx_memzero(&p->upstream->headers_in.date,
sizeof(ngx_http_proxy_headers_in_t) - sizeof(ngx_list_t));
} else {
p->upstream->headers_in.headers.elts = ngx_pcalloc(p->request->pool,
20 * sizeof(ngx_table_elt_t));
if (p->upstream->headers_in.headers.elts == NULL) {
if (ngx_list_init(&p->upstream->headers_in.headers, p->request->pool,
20, sizeof(ngx_table_elt_t)) == NGX_ERROR)
{
ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
/* p->upstream->headers_in.headers.nelts = 0; */
p->upstream->headers_in.headers.nalloc = 20;
p->upstream->headers_in.headers.size = sizeof(ngx_table_elt_t);
p->upstream->headers_in.headers.pool = p->request->pool;
}
@ -1025,9 +1027,7 @@ static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev)
/* a header line has been parsed successfully */
h = ngx_http_add_header(&p->upstream->headers_in,
ngx_http_proxy_headers_in);
if (h == NULL) {
if (!(h = ngx_list_push(&p->upstream->headers_in.headers))) {
ngx_http_proxy_finalize_request(p,
NGX_HTTP_INTERNAL_SERVER_ERROR);
return;

View File

@ -500,13 +500,16 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
in_addr = in_port[p].addrs.elts;
while (a < in_port[p].addrs.nelts) {
ngx_test_null(ls, ngx_push_array(&cf->cycle->listening),
NGX_CONF_ERROR);
if (!(ls = ngx_push_array(&cf->cycle->listening))) {
return NGX_CONF_ERROR;
}
ngx_memzero(ls, sizeof(ngx_listening_t));
ngx_test_null(addr_in,
ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)),
NGX_CONF_ERROR);
addr_in = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in));
if (addr_in == NULL) {
return NGX_CONF_ERROR;
}
#if (HAVE_SIN_LEN)
addr_in->sin_len = sizeof(struct sockaddr_in);
@ -515,16 +518,17 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
addr_in->sin_addr.s_addr = in_addr[a].addr;
addr_in->sin_port = htons((u_short) in_port[p].port);
ngx_test_null(ls->addr_text.data,
ngx_palloc(cf->pool, INET_ADDRSTRLEN + 6),
NGX_CONF_ERROR);
ls->addr_text.data = ngx_palloc(cf->pool, INET_ADDRSTRLEN + 6);
if (ls->addr_text.data == NULL) {
return NGX_CONF_ERROR;
}
ls->addr_text.len =
ngx_snprintf((char *) ls->addr_text.data
+ ngx_inet_ntop(AF_INET,
&in_addr[a].addr,
ls->addr_text.len = ngx_inet_ntop(AF_INET, &in_addr[a].addr,
ls->addr_text.data,
INET_ADDRSTRLEN),
ls->addr_text.len += ngx_snprintf((char *) ls->addr_text.data
+ ls->addr_text.len,
6, ":%d", in_port[p].port);
ls->fd = (ngx_socket_t) -1;

View File

@ -81,8 +81,6 @@ ngx_int_t ngx_http_special_response_handler(ngx_http_request_t *r, int error);
time_t ngx_http_parse_time(u_char *value, size_t len);
size_t ngx_http_get_time(char *buf, time_t t);
ngx_table_elt_t *ngx_http_add_header(void *header,
ngx_http_header_t *http_headers);

View File

@ -531,8 +531,8 @@ ngx_int_t ngx_http_find_location_config(ngx_http_request_t *r)
if (rc == NGX_HTTP_LOCATION_AUTO_REDIRECT) {
if (!(r->headers_out.location = ngx_push_list(&r->headers_out.headers)))
{
r->headers_out.location = ngx_list_push(&r->headers_out.headers);
if (r->headers_out.location == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@ -673,8 +673,8 @@ ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r)
ngx_http_type_t *type;
ngx_http_core_loc_conf_t *clcf;
if (!(r->headers_out.content_type = ngx_push_list(&r->headers_out.headers)))
{
r->headers_out.content_type = ngx_list_push(&r->headers_out.headers);
if (r->headers_out.content_type == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}

View File

@ -89,6 +89,28 @@ static ngx_str_t http_codes[] = {
};
ngx_http_header_t ngx_http_headers_out[] = {
{ ngx_string("Server"), offsetof(ngx_http_headers_out_t, server) },
{ ngx_string("Date"), offsetof(ngx_http_headers_out_t, date) },
{ ngx_string("Content-Type"),
offsetof(ngx_http_headers_out_t, content_type) },
{ ngx_string("Content-Length"),
offsetof(ngx_http_headers_out_t, content_length) },
{ ngx_string("Content-Encoding"),
offsetof(ngx_http_headers_out_t, content_encoding) },
{ ngx_string("Location"), offsetof(ngx_http_headers_out_t, location) },
{ ngx_string("Last-Modified"),
offsetof(ngx_http_headers_out_t, last_modified) },
{ ngx_string("Accept-Ranges"),
offsetof(ngx_http_headers_out_t, accept_ranges) },
{ ngx_string("Expires"), offsetof(ngx_http_headers_out_t, expires) },
{ ngx_string("Cache-Control"),
offsetof(ngx_http_headers_out_t, cache_control) },
{ ngx_string("ETag"), offsetof(ngx_http_headers_out_t, etag) },
{ ngx_null_string, 0 }
};
static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r)
{

View File

@ -1,116 +0,0 @@
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
ngx_http_header_t ngx_http_headers_in[] = {
{ ngx_string("Host"), offsetof(ngx_http_headers_in_t, host) },
{ ngx_string("Connection"), offsetof(ngx_http_headers_in_t, connection) },
{ ngx_string("If-Modified-Since"),
offsetof(ngx_http_headers_in_t, if_modified_since) },
{ ngx_string("User-Agent"), offsetof(ngx_http_headers_in_t, user_agent) },
{ ngx_string("Referer"), offsetof(ngx_http_headers_in_t, referer) },
{ ngx_string("Content-Length"),
offsetof(ngx_http_headers_in_t, content_length) },
{ ngx_string("Range"), offsetof(ngx_http_headers_in_t, range) },
#if 0
{ ngx_string("If-Range"), offsetof(ngx_http_headers_in_t, if_range) },
#endif
#if (NGX_HTTP_GZIP)
{ ngx_string("Accept-Encoding"),
offsetof(ngx_http_headers_in_t, accept_encoding) },
{ ngx_string("Via"), offsetof(ngx_http_headers_in_t, via) },
#endif
{ ngx_string("Authorization"),
offsetof(ngx_http_headers_in_t, authorization) },
{ ngx_string("Keep-Alive"), offsetof(ngx_http_headers_in_t, keep_alive) },
#if (NGX_HTTP_PROXY)
{ ngx_string("X-Forwarded-For"),
offsetof(ngx_http_headers_in_t, x_forwarded_for) },
#endif
{ ngx_null_string, 0 }
};
ngx_http_header_t ngx_http_headers_out[] = {
{ ngx_string("Server"), offsetof(ngx_http_headers_out_t, server) },
{ ngx_string("Date"), offsetof(ngx_http_headers_out_t, date) },
{ ngx_string("Content-Type"),
offsetof(ngx_http_headers_out_t, content_type) },
{ ngx_string("Content-Length"),
offsetof(ngx_http_headers_out_t, content_length) },
{ ngx_string("Content-Encoding"),
offsetof(ngx_http_headers_out_t, content_encoding) },
{ ngx_string("Location"), offsetof(ngx_http_headers_out_t, location) },
{ ngx_string("Last-Modified"),
offsetof(ngx_http_headers_out_t, last_modified) },
{ ngx_string("Accept-Ranges"),
offsetof(ngx_http_headers_out_t, accept_ranges) },
{ ngx_string("Expires"), offsetof(ngx_http_headers_out_t, expires) },
{ ngx_string("Cache-Control"),
offsetof(ngx_http_headers_out_t, cache_control) },
{ ngx_string("ETag"), offsetof(ngx_http_headers_out_t, etag) },
{ ngx_null_string, 0 }
};
ngx_table_elt_t *ngx_http_add_header(void *header,
ngx_http_header_t *http_headers)
{
void *prev;
ngx_uint_t i, j;
ngx_table_t *headers;
ngx_table_elt_t *h, *new;
headers = header;
prev = headers->elts;
if (!(new = ngx_push_table(headers))) {
return NULL;
}
if (prev == headers->elts) {
return new;
}
/*
* When table is relocated we need to update pointers in r->headers_in,
* r->headers_out, etc. However this relocation should be very rare
* because we preallocate enough space for the number of the real world
* HTTP headers.
*/
ngx_log_error(NGX_LOG_ALERT, headers->pool->log, 0,
"header table is small, %d elements", headers->nelts - 1);
h = headers->elts;
for (i = 0; i < headers->nelts - 1; i++) {
if (h[i].key.len == 0) {
continue;
}
for (j = 0; http_headers[j].name.len != 0; j++) {
if (http_headers[j].name.len != h[i].key.len) {
continue;
}
if (ngx_strcasecmp(http_headers[j].name.data, h[i].key.data) == 0) {
*((ngx_table_elt_t **)
((char *) header + http_headers[j].offset)) = &h[i];
break;
}
}
}
return new;
}

View File

@ -49,6 +49,41 @@ static char *client_header_errors[] = {
};
ngx_http_header_t ngx_http_headers_in[] = {
{ ngx_string("Host"), offsetof(ngx_http_headers_in_t, host) },
{ ngx_string("Connection"), offsetof(ngx_http_headers_in_t, connection) },
{ ngx_string("If-Modified-Since"),
offsetof(ngx_http_headers_in_t, if_modified_since) },
{ ngx_string("User-Agent"), offsetof(ngx_http_headers_in_t, user_agent) },
{ ngx_string("Referer"), offsetof(ngx_http_headers_in_t, referer) },
{ ngx_string("Content-Length"),
offsetof(ngx_http_headers_in_t, content_length) },
{ ngx_string("Range"), offsetof(ngx_http_headers_in_t, range) },
#if 0
{ ngx_string("If-Range"), offsetof(ngx_http_headers_in_t, if_range) },
#endif
#if (NGX_HTTP_GZIP)
{ ngx_string("Accept-Encoding"),
offsetof(ngx_http_headers_in_t, accept_encoding) },
{ ngx_string("Via"), offsetof(ngx_http_headers_in_t, via) },
#endif
{ ngx_string("Authorization"),
offsetof(ngx_http_headers_in_t, authorization) },
{ ngx_string("Keep-Alive"), offsetof(ngx_http_headers_in_t, keep_alive) },
#if (NGX_HTTP_PROXY)
{ ngx_string("X-Forwarded-For"),
offsetof(ngx_http_headers_in_t, x_forwarded_for) },
#endif
{ ngx_null_string, 0 }
};
#if 0
static void ngx_http_dummy(ngx_event_t *wev)
{
@ -310,7 +345,7 @@ static void ngx_http_init_request(ngx_event_t *rev)
r->cleanup.pool = r->pool;
if (ngx_init_list(&r->headers_out.headers, r->pool, 2,
if (ngx_list_init(&r->headers_out.headers, r->pool, 20,
sizeof(ngx_table_elt_t)) == NGX_ERROR)
{
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
@ -319,23 +354,6 @@ static void ngx_http_init_request(ngx_event_t *rev)
}
#if 0
/* init the r->headers_out.headers table */
r->headers_out.headers.elts = ngx_pcalloc(r->pool,
20 * sizeof(ngx_table_elt_t));
if (r->headers_out.headers.elts == NULL) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
ngx_http_close_connection(c);
return;
}
/* r->headers_out.headers.nelts = 0; */
r->headers_out.headers.nalloc = 20;
r->headers_out.headers.size = sizeof(ngx_table_elt_t);
r->headers_out.headers.pool = r->pool;
#endif
r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
if (r->ctx == NULL) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
@ -619,7 +637,7 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
}
if (ngx_init_list(&r->headers_in.headers, r->pool, 2,
if (ngx_list_init(&r->headers_in.headers, r->pool, 20,
sizeof(ngx_table_elt_t)) == NGX_ERROR)
{
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
@ -628,7 +646,7 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
}
if (ngx_init_array0(&r->headers_in.cookies, r->pool, 5,
if (ngx_array_init(&r->headers_in.cookies, r->pool, 5,
sizeof(ngx_table_elt_t *)) == NGX_ERROR)
{
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
@ -772,7 +790,7 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
r->headers_n++;
if (!(h = ngx_push_list(&r->headers_in.headers))) {
if (!(h = ngx_list_push(&r->headers_in.headers))) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
ngx_http_close_connection(c);
return;

View File

@ -160,9 +160,6 @@ typedef struct {
typedef struct {
ngx_list_t headers;
#if 0
ngx_table_t headers; /* it must be first field */
#endif
ngx_uint_t status;
ngx_str_t status_line;

View File

@ -282,9 +282,8 @@ ngx_int_t ngx_http_special_response_handler(ngx_http_request_t *r, int error)
msie_padding = 1;
}
if (!(r->headers_out.content_type =
ngx_push_list(&r->headers_out.headers)))
{
r->headers_out.content_type = ngx_list_push(&r->headers_out.headers);
if (r->headers_out.content_type == NULL) {
return NGX_ERROR;
}