mirror of
https://github.com/nginx/nginx.git
synced 2025-01-19 01:42:58 +08:00
nginx-0.0.1-2003-10-29-20:39:05 import
This commit is contained in:
parent
b5faed2dc8
commit
14be46ee98
@ -196,8 +196,8 @@ static int ngx_http_gzip_header_filter(ngx_http_request_t *r)
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
r->headers_out.content_encoding->key.len = 0;
|
||||
r->headers_out.content_encoding->key.data = NULL;
|
||||
r->headers_out.content_encoding->key.len = sizeof("Content-Encoding") - 1;
|
||||
r->headers_out.content_encoding->key.data = "Content-Encoding";
|
||||
r->headers_out.content_encoding->value.len = sizeof("gzip") - 1;
|
||||
r->headers_out.content_encoding->value.data = "gzip";
|
||||
|
||||
|
@ -198,9 +198,14 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r)
|
||||
r->headers_out.status = rc;
|
||||
r->headers_out.ranges.nelts = 0;
|
||||
|
||||
ngx_test_null(r->headers_out.content_range,
|
||||
ngx_push_table(r->headers_out.headers),
|
||||
NGX_ERROR);
|
||||
if (!(r->headers_out.content_range =
|
||||
ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
|
||||
{
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
r->headers_out.content_range->key.len = sizeof("Content-Range") - 1;
|
||||
r->headers_out.content_range->key.data = "Content-Range";
|
||||
|
||||
ngx_test_null(r->headers_out.content_range->value.data,
|
||||
ngx_palloc(r->pool, 8 + 20 + 1),
|
||||
@ -212,7 +217,10 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r)
|
||||
r->headers_out.content_length_n);
|
||||
|
||||
r->headers_out.content_length_n = -1;
|
||||
r->headers_out.content_length = NULL;
|
||||
if (r->headers_out.content_length) {
|
||||
r->headers_out.content_length->key.len = 0;
|
||||
r->headers_out.content_length = NULL;
|
||||
}
|
||||
|
||||
return rc;
|
||||
|
||||
@ -220,9 +228,15 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r)
|
||||
r->headers_out.status = NGX_HTTP_PARTIAL_CONTENT;
|
||||
|
||||
if (r->headers_out.ranges.nelts == 1) {
|
||||
ngx_test_null(r->headers_out.content_range,
|
||||
ngx_push_table(r->headers_out.headers),
|
||||
NGX_ERROR);
|
||||
|
||||
if (!(r->headers_out.content_range =
|
||||
ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
|
||||
{
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
r->headers_out.content_range->key.len = sizeof("Content-Range") - 1;
|
||||
r->headers_out.content_range->key.data = "Content-Range";
|
||||
|
||||
ngx_test_null(r->headers_out.content_range->value.data,
|
||||
ngx_palloc(r->pool, 6 + 20 + 1 + 20 + 1 + 20 + 1),
|
||||
@ -243,9 +257,12 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r)
|
||||
|
||||
#if 0
|
||||
/* TODO: what if no content_type ?? */
|
||||
ngx_test_null(r->headers_out.content_type,
|
||||
ngx_push_table(r->headers_out.headers),
|
||||
NGX_ERROR);
|
||||
|
||||
if (!(r->headers_out.content_type =
|
||||
ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
|
||||
{
|
||||
return NGX_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
ngx_http_create_ctx(r, ctx, ngx_http_range_filter_module,
|
||||
|
@ -41,7 +41,6 @@ int ngx_http_static_translate_handler(ngx_http_request_t *r)
|
||||
{
|
||||
char *location, *last;
|
||||
ngx_err_t err;
|
||||
ngx_table_elt_t *h;
|
||||
ngx_http_core_loc_conf_t *clcf;
|
||||
|
||||
if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) {
|
||||
@ -181,16 +180,18 @@ ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data);
|
||||
r->file.info_valid = 0;
|
||||
#endif
|
||||
|
||||
ngx_test_null(h, ngx_push_table(r->headers_out.headers),
|
||||
NGX_HTTP_INTERNAL_SERVER_ERROR);
|
||||
if (!(r->headers_out.location =
|
||||
ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
|
||||
{
|
||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
|
||||
*last++ = '/';
|
||||
*last = '\0';
|
||||
h->key.len = 8;
|
||||
h->key.data = "Location" ;
|
||||
h->value.len = last - location;
|
||||
h->value.data = location;
|
||||
r->headers_out.location = h;
|
||||
r->headers_out.location->key.len = 8;
|
||||
r->headers_out.location->key.data = "Location" ;
|
||||
r->headers_out.location->value.len = last - location;
|
||||
r->headers_out.location->value.data = location;
|
||||
|
||||
return NGX_HTTP_MOVED_PERMANENTLY;
|
||||
}
|
||||
@ -262,9 +263,11 @@ static int ngx_http_static_handler(ngx_http_request_t *r)
|
||||
r->headers_out.content_length_n = ngx_file_size(r->file.info);
|
||||
r->headers_out.last_modified_time = ngx_file_mtime(r->file.info);
|
||||
|
||||
ngx_test_null(r->headers_out.content_type,
|
||||
ngx_push_table(r->headers_out.headers),
|
||||
NGX_HTTP_INTERNAL_SERVER_ERROR);
|
||||
if (!(r->headers_out.content_type =
|
||||
ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
|
||||
{
|
||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
|
||||
r->headers_out.content_type->key.len = 0;
|
||||
r->headers_out.content_type->key.data = NULL;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,186 +0,0 @@
|
||||
#ifndef _NGX_HTTP_PROXY_HANDLER_H_INCLUDED_
|
||||
#define _NGX_HTTP_PROXY_HANDLER_H_INCLUDED_
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_array.h>
|
||||
#include <ngx_event_proxy.h>
|
||||
#include <ngx_http.h>
|
||||
|
||||
|
||||
#define NGX_HTTP_PROXY_PARSE_NO_HEADER 20
|
||||
#define NGX_HTTP_PARSE_TOO_LONG_STATUS_LINE 21
|
||||
|
||||
typedef struct {
|
||||
ngx_table_elt_t *date;
|
||||
ngx_table_elt_t *server;
|
||||
ngx_table_elt_t *connection;
|
||||
ngx_table_elt_t *content_type;
|
||||
ngx_table_elt_t *content_length;
|
||||
ngx_table_elt_t *last_modified;
|
||||
|
||||
ngx_table_t *headers;
|
||||
} ngx_http_proxy_headers_in_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
u_int32_t addr;
|
||||
ngx_str_t host;
|
||||
int port;
|
||||
ngx_str_t addr_port_name;
|
||||
|
||||
int fails;
|
||||
time_t accessed;
|
||||
} ngx_http_proxy_upstream_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
int current;
|
||||
int number;
|
||||
int max_fails;
|
||||
int fail_timeout;
|
||||
|
||||
/* ngx_mutex_t mutex; */
|
||||
/* ngx_connection_t *cached; ??? */
|
||||
|
||||
ngx_http_proxy_upstream_t u[1];
|
||||
} ngx_http_proxy_upstreams_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_str_t host;
|
||||
ngx_str_t uri;
|
||||
ngx_str_t *location;
|
||||
ngx_str_t host_header;
|
||||
ngx_str_t port_name;
|
||||
int port;
|
||||
} ngx_http_proxy_upstream_url_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_http_proxy_upstreams_t *upstreams;
|
||||
ngx_http_proxy_upstream_url_t *upstream_url;
|
||||
|
||||
int client_request_buffer_size;
|
||||
int rcvbuf;
|
||||
int conn_pool_size;
|
||||
int connect_timeout;
|
||||
int send_timeout;
|
||||
int read_timeout;
|
||||
int header_size;
|
||||
int large_header;
|
||||
|
||||
int block_size;
|
||||
int max_block_size;
|
||||
int max_temp_file_size;
|
||||
int temp_file_write_size;
|
||||
|
||||
ngx_path_t *temp_path;
|
||||
int temp_file_warn;
|
||||
|
||||
int retry_500_error;
|
||||
|
||||
} ngx_http_proxy_loc_conf_t;
|
||||
|
||||
|
||||
#if 0
|
||||
/* location /one/ { proxy_pass http://localhost:9000/two/; } */
|
||||
|
||||
typedef struct {
|
||||
/* "/one/" */
|
||||
/* "http://localhost:9000/two/" */
|
||||
/* "/two/" */
|
||||
*upstream_farm;
|
||||
} ngx_http_proxy_pass_t;
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct ngx_http_proxy_ctx_s ngx_http_proxy_ctx_t;
|
||||
|
||||
struct ngx_http_proxy_ctx_s {
|
||||
ngx_event_proxy_t *event_proxy;
|
||||
|
||||
|
||||
ngx_chain_t *in_hunks;
|
||||
ngx_chain_t *last_in_hunk;
|
||||
|
||||
ngx_chain_t *shadow_hunks;
|
||||
|
||||
ngx_chain_t *out_hunks;
|
||||
ngx_chain_t *last_out_hunk;
|
||||
|
||||
ngx_chain_t *free_hunks;
|
||||
|
||||
|
||||
ngx_chain_t *request_hunks;
|
||||
|
||||
ngx_hunk_t *client_request_hunk;
|
||||
ngx_hunk_t *client_first_part_hunk;
|
||||
|
||||
ngx_connection_t *connection;
|
||||
ngx_http_request_t *request;
|
||||
ngx_http_proxy_headers_in_t headers_in;
|
||||
|
||||
|
||||
int block_size;
|
||||
int allocated;
|
||||
|
||||
ngx_file_t *temp_file;
|
||||
off_t temp_offset;
|
||||
|
||||
int last_hunk;
|
||||
ngx_array_t hunks;
|
||||
int nhunks;
|
||||
|
||||
int hunk_n;
|
||||
|
||||
ngx_http_proxy_upstream_url_t *upstream_url;
|
||||
ngx_http_proxy_upstreams_t *upstreams;
|
||||
int cur_upstream;
|
||||
int tries;
|
||||
|
||||
struct sockaddr *sockaddr;
|
||||
|
||||
ngx_http_proxy_loc_conf_t *lcf;
|
||||
|
||||
ngx_log_t *log;
|
||||
|
||||
int method;
|
||||
|
||||
ngx_hunk_t *header_in;
|
||||
int status;
|
||||
ngx_str_t status_line;
|
||||
ngx_str_t full_status_line;
|
||||
|
||||
int state;
|
||||
int status_count;
|
||||
char *status_start;
|
||||
char *status_end;
|
||||
int (*state_write_upstream_handler) (ngx_http_proxy_ctx_t *p);
|
||||
int (*state_read_upstream_handler) (ngx_http_proxy_ctx_t *p);
|
||||
int (*state_handler)(ngx_http_proxy_ctx_t *p);
|
||||
|
||||
int last_error;
|
||||
|
||||
unsigned accel:1;
|
||||
|
||||
unsigned cached_connection:1;
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
char *action;
|
||||
char *upstream;
|
||||
char *client;
|
||||
char *url;
|
||||
} ngx_http_proxy_log_ctx_t;
|
||||
|
||||
|
||||
extern ngx_module_t ngx_http_proxy_module;
|
||||
|
||||
|
||||
static int ngx_http_proxy_error(ngx_http_request_t *r, ngx_http_proxy_ctx_t *p,
|
||||
int error);
|
||||
|
||||
|
||||
#endif /* _NGX_HTTP_PROXY_HANDLER_H_INCLUDED_ */
|
@ -658,7 +658,7 @@ static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev)
|
||||
if (p->headers_in.headers) {
|
||||
p->headers_in.headers->nelts = 0;
|
||||
} else {
|
||||
p->headers_in.headers = ngx_create_table(p->request->pool, 10);
|
||||
p->headers_in.headers = ngx_create_table(p->request->pool, 20);
|
||||
}
|
||||
|
||||
c->read->event_handler = ngx_http_proxy_process_upstream_headers;
|
||||
@ -713,8 +713,7 @@ static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev)
|
||||
|
||||
/* a header line has been parsed successfully */
|
||||
|
||||
h = ngx_push_table(p->headers_in.headers);
|
||||
if (h == NULL) {
|
||||
if (!(h = ngx_http_add_header(&p->headers_in, headers_in))) {
|
||||
ngx_http_proxy_finalize_request(p,
|
||||
NGX_HTTP_INTERNAL_SERVER_ERROR);
|
||||
return;
|
||||
@ -831,7 +830,7 @@ static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *p)
|
||||
static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
|
||||
{
|
||||
int rc, i;
|
||||
ngx_table_elt_t *ch, *h;
|
||||
ngx_table_elt_t *ho, *h;
|
||||
ngx_event_pipe_t *ep;
|
||||
ngx_http_request_t *r;
|
||||
ngx_http_core_loc_conf_t *clcf;
|
||||
@ -869,13 +868,13 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
|
||||
continue;
|
||||
}
|
||||
|
||||
ch = ngx_push_table(r->headers_out.headers);
|
||||
if (ch == NULL) {
|
||||
if (!(ho = ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
|
||||
{
|
||||
ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
*ch = h[i];
|
||||
*ho = h[i];
|
||||
|
||||
/*
|
||||
* ngx_http_header_filter() output the following headers
|
||||
@ -886,21 +885,19 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
|
||||
*/
|
||||
|
||||
if (&h[i] == p->headers_in.server) {
|
||||
r->headers_out.server = ch;
|
||||
r->headers_out.server = ho;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (&h[i] == p->headers_in.date) {
|
||||
r->headers_out.date = ch;
|
||||
r->headers_out.date = ho;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (&h[i] == p->headers_in.content_length) {
|
||||
|
||||
r->headers_out.content_length_n =
|
||||
ngx_atoi(p->headers_in.content_length->value.data,
|
||||
p->headers_in.content_length->value.len);
|
||||
r->headers_out.content_length = ch;
|
||||
r->headers_out.content_length = ho;
|
||||
r->headers_out.content_length_n = ngx_atoi(ho->value.data,
|
||||
ho->value.len);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -519,49 +519,6 @@ int ngx_http_delay_handler(ngx_http_request_t *r)
|
||||
#endif
|
||||
|
||||
|
||||
ngx_table_elt_t *ngx_http_add_header(void *header,
|
||||
ngx_http_header_t *http_headers)
|
||||
{
|
||||
int i, j;
|
||||
char *prev;
|
||||
ngx_table_t *headers;
|
||||
ngx_table_elt_t *h, *new;
|
||||
|
||||
headers = *(ngx_table_t **) header;
|
||||
|
||||
prev = headers->elts;
|
||||
|
||||
if (!(new = ngx_push_table(headers))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (prev == headers->elts) {
|
||||
return new;
|
||||
}
|
||||
|
||||
h = headers->elts;
|
||||
for (i = 0; i < headers->nelts; 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;
|
||||
}
|
||||
|
||||
|
||||
static int ngx_http_core_init(ngx_cycle_t *cycle)
|
||||
{
|
||||
#if 0
|
||||
|
@ -152,15 +152,9 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
|
||||
len += sizeof("Date: Mon, 28 Sep 1970 00:00:00 GMT" CRLF) - 1;
|
||||
}
|
||||
|
||||
if (r->headers_out.content_range && r->headers_out.content_range->value.len)
|
||||
{
|
||||
len += sizeof("Content-Range: ") - 1
|
||||
+ r->headers_out.content_range->value.len + 2;
|
||||
}
|
||||
|
||||
if (r->headers_out.content_length == NULL) {
|
||||
if (r->headers_out.content_length_n >= 0) {
|
||||
/* 2^64 */
|
||||
/* 2^64 */
|
||||
len += sizeof("Content-Length: 18446744073709551616" CRLF) - 1;
|
||||
}
|
||||
}
|
||||
@ -175,12 +169,6 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
|
||||
}
|
||||
}
|
||||
|
||||
if (r->headers_out.content_encoding
|
||||
&& r->headers_out.content_encoding->value.len)
|
||||
{
|
||||
len += 18 + r->headers_out.content_encoding->value.len + 2;
|
||||
}
|
||||
|
||||
if (r->headers_out.location
|
||||
&& r->headers_out.location->value.len
|
||||
&& r->headers_out.location->value.data[0] == '/')
|
||||
@ -218,10 +206,11 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
|
||||
continue;
|
||||
}
|
||||
|
||||
/* 2 is for ": " and 2 is for "\r\n" */
|
||||
len += header[i].key.len + 2 + header[i].value.len + 2;
|
||||
}
|
||||
|
||||
ngx_test_null(h, ngx_create_temp_hunk(r->pool, len, 0, 64), NGX_ERROR);
|
||||
ngx_test_null(h, ngx_create_temp_hunk(r->pool, len, 0, 0), NGX_ERROR);
|
||||
|
||||
/* "HTTP/1.x " */
|
||||
h->last = ngx_cpymem(h->last, "HTTP/1.1 ", sizeof("HTTP/1.x ") - 1);
|
||||
@ -247,20 +236,9 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
|
||||
*(h->last++) = CR; *(h->last++) = LF;
|
||||
}
|
||||
|
||||
|
||||
if (r->headers_out.content_range && r->headers_out.content_range->value.len)
|
||||
{
|
||||
h->last = ngx_cpymem(h->last, "Content-Range: ",
|
||||
sizeof("Content-Range: ") - 1);
|
||||
h->last = ngx_cpymem(h->last, r->headers_out.content_range->value.data,
|
||||
r->headers_out.content_range->value.len);
|
||||
*(h->last++) = CR; *(h->last++) = LF;
|
||||
}
|
||||
|
||||
if (r->headers_out.content_length == NULL) {
|
||||
/* 2^64 is 20 characters */
|
||||
if (r->headers_out.content_length_n >= 0) {
|
||||
h->last += ngx_snprintf(h->last,
|
||||
h->last += ngx_snprintf(h->last, /* 2^64 */
|
||||
sizeof("Content-Length: 18446744073709551616" CRLF),
|
||||
"Content-Length: " OFF_FMT CRLF,
|
||||
r->headers_out.content_length_n);
|
||||
@ -283,18 +261,6 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
|
||||
*(h->last++) = CR; *(h->last++) = LF;
|
||||
}
|
||||
|
||||
if (r->headers_out.content_encoding
|
||||
&& r->headers_out.content_encoding->value.len)
|
||||
{
|
||||
h->last = ngx_cpymem(h->last, "Content-Encoding: ",
|
||||
sizeof("Content-Encoding: ") - 1);
|
||||
h->last = ngx_cpymem(h->last,
|
||||
r->headers_out.content_encoding->value.data,
|
||||
r->headers_out.content_encoding->value.len);
|
||||
|
||||
*(h->last++) = CR; *(h->last++) = LF;
|
||||
}
|
||||
|
||||
if (r->headers_out.location
|
||||
&& r->headers_out.location->value.len
|
||||
&& r->headers_out.location->value.data[0] == '/')
|
||||
|
100
src/http/ngx_http_headers.c
Normal file
100
src/http/ngx_http_headers.c
Normal file
@ -0,0 +1,100 @@
|
||||
|
||||
#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("Content-Length"),
|
||||
offsetof(ngx_http_headers_in_t, content_length) },
|
||||
{ ngx_string("Accept-Encoding"),
|
||||
offsetof(ngx_http_headers_in_t, accept_encoding) },
|
||||
{ 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
|
||||
|
||||
{ ngx_string("Keep-Alive"), offsetof(ngx_http_headers_in_t, keep_alive) },
|
||||
|
||||
{ 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_null_string, 0 }
|
||||
};
|
||||
|
||||
|
||||
ngx_table_elt_t *ngx_http_add_header(void *header,
|
||||
ngx_http_header_t *http_headers)
|
||||
{
|
||||
int i, j, nelts;
|
||||
char *prev;
|
||||
ngx_table_t *headers;
|
||||
ngx_table_elt_t *h, *new;
|
||||
|
||||
headers = *(ngx_table_t **) header;
|
||||
|
||||
prev = headers->elts;
|
||||
nelts = headers->nelts;
|
||||
|
||||
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", nelts);
|
||||
|
||||
h = headers->elts;
|
||||
for (i = 0; i < nelts; 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;
|
||||
}
|
||||
|
@ -43,50 +43,6 @@ 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("Content-Length"),
|
||||
offsetof(ngx_http_headers_in_t, content_length) },
|
||||
{ ngx_string("Accept-Encoding"),
|
||||
offsetof(ngx_http_headers_in_t, accept_encoding) },
|
||||
{ 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
|
||||
|
||||
{ ngx_string("Keep-Alive"), offsetof(ngx_http_headers_in_t, keep_alive) },
|
||||
|
||||
{ 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) },
|
||||
|
||||
/* 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_null_string, 0 }
|
||||
};
|
||||
|
||||
|
||||
static void ngx_http_dummy(ngx_event_t *wev)
|
||||
{
|
||||
return;
|
||||
@ -271,7 +227,7 @@ ngx_log_debug(rev->log, "IN: %08x" _ in_port);
|
||||
return;
|
||||
}
|
||||
|
||||
r->headers_out.headers = ngx_create_table(r->pool, 1);
|
||||
r->headers_out.headers = ngx_create_table(r->pool, 20);
|
||||
if (r->headers_out.headers == NULL) {
|
||||
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
||||
ngx_http_close_connection(c);
|
||||
@ -466,7 +422,7 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
|
||||
lctx = c->log->data;
|
||||
lctx->action = "reading client request headers";
|
||||
lctx->url = r->unparsed_uri.data;
|
||||
r->headers_in.headers = ngx_create_table(r->pool, 1);
|
||||
r->headers_in.headers = ngx_create_table(r->pool, 20);
|
||||
|
||||
if (cscf->large_client_header
|
||||
&& r->header_in->pos == r->header_in->last)
|
||||
|
@ -224,13 +224,17 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error)
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
r->headers_out.content_type->key.len = 12;
|
||||
r->headers_out.content_type->key.len = sizeof("Content-Type") - 1;
|
||||
r->headers_out.content_type->key.data = "Content-Type";
|
||||
r->headers_out.content_type->value.len = 9;
|
||||
r->headers_out.content_type->value.len = sizeof("text/html") - 1;
|
||||
r->headers_out.content_type->value.data = "text/html";
|
||||
|
||||
} else {
|
||||
r->headers_out.content_length_n = -1;
|
||||
}
|
||||
|
||||
if (r->headers_out.content_length) {
|
||||
r->headers_out.content_length->key.len = 0;
|
||||
r->headers_out.content_length = NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user