nginx-0.0.1-2003-04-08-19:40:10 import

This commit is contained in:
Igor Sysoev 2003-04-08 15:40:10 +00:00
parent 3f76ec190a
commit e2a3154f0e
23 changed files with 1792 additions and 1596 deletions

View File

@ -36,6 +36,8 @@ ngx_log_t ngx_log;
ngx_pool_t *ngx_pool;
int ngx_max_module;
int ngx_connection_counter;
ngx_array_t ngx_listening_sockets;
@ -68,6 +70,11 @@ int main(int argc, char *const *argv)
ngx_init_array(ngx_listening_sockets, ngx_pool, 10, sizeof(ngx_listen_t),
1);
ngx_max_module = 0;
for (i = 0; ngx_modules[i]; i++) {
ngx_modules[i]->index = ngx_max_module++;
}
ngx_memzero(&conf, sizeof(ngx_conf_t));
ngx_test_null(conf.args,
ngx_create_array(ngx_pool, 10, sizeof(ngx_str_t)), 1);

View File

@ -5,6 +5,7 @@
#define NGINX_VER "nginx/0.0.1"
extern int ngx_max_module;
extern int ngx_connection_counter;

View File

@ -130,7 +130,7 @@ ngx_log_debug(cf->log, "command '%s'" _ cmd->name.data);
pconf = *(void **) ((char *) cf->ctx + cmd->conf);
if (pconf) {
conf = pconf[ngx_modules[i]->index];
conf = pconf[*(int *)(ngx_modules[i]->ctx)];
}
}

View File

@ -31,8 +31,8 @@
#define NGX_CONF_FILE_DONE 2
#define NGX_CORE_MODULE_TYPE 0x45524f43 /* "CORE" */
#define NGX_CONF_MODULE_TYPE 0x464E4f43 /* "CONF" */
#define NGX_CORE_MODULE_TYPE 0x45524F43 /* "CORE" */
#define NGX_CONF_MODULE_TYPE 0x464E4F43 /* "CONF" */
typedef struct ngx_conf_s ngx_conf_t;

View File

@ -93,6 +93,7 @@
#include <sys/uio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#ifndef HAVE_POLL

View File

@ -4,11 +4,15 @@
#define NGX_OK 0
#define NGX_ERROR -1
#define NGX_DONE NGX_ERROR
#define NGX_AGAIN -2
#define NGX_DONE -3
/*
#define NGX_BUSY -3
*/
#define NGX_DECLINED -4
/*
#define NGX_ALERT -5
*/
#define NGX_MAXHOSTNAMELEN 32

View File

@ -4,28 +4,32 @@
#include <ngx_conf_file.h>
extern ngx_module_t ngx_http_header_filter_module;
extern ngx_module_t ngx_http_module;
extern ngx_module_t ngx_http_core_module;
extern ngx_module_t ngx_http_write_filter_module;
extern ngx_module_t ngx_http_output_filter_module;
extern ngx_module_t ngx_http_header_filter_module;
extern ngx_module_t ngx_http_core_module;
extern ngx_module_t ngx_http_index_module;
extern ngx_module_t ngx_http_module;
extern ngx_module_t ngx_http_proxy_module;
ngx_module_t *ngx_modules[] = {
&ngx_http_header_filter_module,
&ngx_http_module,
&ngx_http_core_module,
&ngx_http_write_filter_module,
&ngx_http_output_filter_module,
&ngx_http_header_filter_module,
/* &ngx_http_gzip_filter_module, */
/* &ngx_http_range_filter_module, */
/* &ngx_http_ssi_filter_module, */
&ngx_http_index_module,
&ngx_http_core_module,
&ngx_http_module,
&ngx_http_proxy_module,
NULL
};

File diff suppressed because it is too large Load Diff

View File

@ -1,103 +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_http.h>
#define NGX_HTTP_PROXY_PARSE_NO_HEADER 20
#define NGX_HTTP_PARSE_TOO_LONG_STATUS_LINE 21
typedef struct {
int dummy;
} ngx_http_proxy_headers_in_t;
typedef struct {
int large_header;
} ngx_http_proxy_loc_conf_t;
typedef struct {
ngx_str_t host;
ngx_str_t uri;
ngx_str_t host_header;
ngx_str_t port_name;
int port;
} ngx_http_proxy_upstream_url_t;
typedef struct {
struct sockaddr_in;
ngx_str_t name;
time_t access;
int fails;
} ngx_http_proxy_upstream_t;
typedef struct {
int amount;
ngx_http_proxy_upstream_t *upstreams;
} ngx_http_proxy_upstream_farm_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_chain_t *out;
int last_hunk;
ngx_array_t hunks;
int hunk_n;
ngx_connection_t *connection;
ngx_http_request_t *request;
ngx_http_proxy_headers_in_t *headers_in;
ngx_http_proxy_upstream_farm_t *upstream;
int cur_upstream;
int upstreams;
ngx_log_t *log;
ngx_hunk_t *header_in;
int state;
int status;
int status_count;
char *status_line;
char *request_end;
int (*state_handler)(ngx_http_request_t *r, ngx_http_proxy_ctx_t *p);
};
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_ */

View File

@ -35,13 +35,13 @@ static ngx_command_t ngx_http_index_commands[] = {
ngx_http_module_t ngx_http_index_module_ctx = {
NGX_HTTP_MODULE,
NULL, /* create server config */
NULL, /* init server config */
ngx_http_index_create_conf, /* create location config */
ngx_http_index_merge_conf, /* merge location config */
NULL /* init filters */
ngx_http_index_merge_conf /* merge location config */
};
@ -74,10 +74,10 @@ int ngx_http_index_handler(ngx_http_request_t *r)
ngx_http_core_loc_conf_t *core_cf;
cf = (ngx_http_index_conf_t *)
ngx_http_get_module_loc_conf(r, ngx_http_index_module);
ngx_http_get_module_loc_conf(r, ngx_http_index_module_ctx);
core_cf = (ngx_http_core_loc_conf_t *)
ngx_http_get_module_loc_conf(r, ngx_http_core_module);
ngx_http_get_module_loc_conf(r, ngx_http_core_module_ctx);
ngx_test_null(r->path.data,
ngx_palloc(r->pool,

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,146 @@
#ifndef _NGX_HTTP_PROXY_HANDLER_H_INCLUDED_
#define _NGX_HTTP_PROXY_HANDLER_H_INCLUDED_
#include <ngx_config.h>
#include <ngx_array.h>
#include <ngx_http.h>
#define NGX_HTTP_PROXY_PARSE_NO_HEADER 20
#define NGX_HTTP_PARSE_TOO_LONG_STATUS_LINE 21
typedef struct {
int dummy;
} 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 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 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_chain_t *out;
int last_hunk;
ngx_array_t hunks;
int hunks_number;
int hunk_n;
ngx_connection_t *connection;
ngx_http_request_t *request;
ngx_http_proxy_headers_in_t *headers_in;
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 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_ */

View File

@ -33,6 +33,7 @@ ngx_array_t ngx_http_index_handlers;
int (*ngx_http_top_header_filter) (ngx_http_request_t *r);
int (*ngx_http_top_body_filter) (ngx_http_request_t *r, ngx_chain_t *ch);
static ngx_str_t http_name = ngx_string("http");
@ -59,32 +60,6 @@ ngx_module_t ngx_http_module = {
};
static void ngx_http_init_filters(ngx_pool_t *pool, ngx_module_t **modules)
{
int i;
ngx_http_module_t *module;
ngx_http_conf_filter_t cf;
cf.output_header_filter = NULL;
cf.output_body_filter = NULL;
for (i = 0; modules[i]; i++) {
if (modules[i]->type != NGX_HTTP_MODULE_TYPE) {
continue;
}
module = (ngx_http_module_t *) modules[i]->ctx;
if (module->init_filters) {
module->init_filters(pool, &cf);
}
}
ngx_http_top_header_filter = cf.output_header_filter;
}
static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy)
{
int i, s, l, p, a, n, start;
@ -108,12 +83,15 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy)
ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)),
NGX_CONF_ERROR);
ngx_http_max_module = 0;
for (i = 0; ngx_modules[i]; i++) {
if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) {
continue;
}
ngx_modules[i]->index = ngx_http_max_module++;
module = (ngx_http_module_t *) ngx_modules[i]->ctx;
module->index = ngx_http_max_module++;
}
/* null loc_conf */
@ -169,8 +147,6 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy)
ngx_init_array(ngx_http_index_handlers,
cf->pool, 3, sizeof(ngx_http_handler_pt), NGX_CONF_ERROR);
ngx_http_init_filters(cf->pool, ngx_modules);
/* create lists of ports, addresses and server names */
ngx_init_array(in_ports, cf->pool, 10, sizeof(ngx_http_in_port_t),

View File

@ -147,6 +147,7 @@ struct ngx_http_request_s {
ngx_str_t path;
int path_err;
unsigned proxy:1;
unsigned pipeline:1;
unsigned keepalive:1;
unsigned lingering_close:1;
@ -250,6 +251,9 @@ extern int ngx_http_url_in_error_log;
extern ngx_array_t ngx_http_translate_handlers;
extern ngx_array_t ngx_http_index_handlers;
extern int (*ngx_http_top_header_filter) (ngx_http_request_t *r);
extern int (*ngx_http_top_body_filter) (ngx_http_request_t *r, ngx_chain_t *ch);
/* STUB */
int ngx_http_log_handler(ngx_http_request_t *r);

View File

@ -19,18 +19,19 @@ typedef struct {
typedef struct {
int index;
void *(*create_srv_conf)(ngx_pool_t *p);
char *(*init_srv_conf)(ngx_pool_t *p, void *conf);
void *(*create_loc_conf)(ngx_pool_t *p);
char *(*merge_loc_conf)(ngx_pool_t *p, void *prev, void *conf);
void (*init_filters) (ngx_pool_t *p, ngx_http_conf_filter_t *cf);
} ngx_http_module_t;
#define NGX_HTTP_MODULE_TYPE 0x50545448 /* "HTTP" */
#define NGX_HTTP_MODULE 0
#define NGX_HTTP_MAIN_CONF 0x1000000
#define NGX_HTTP_SRV_CONF 0x2000000

View File

@ -24,6 +24,8 @@ static int ngx_http_core_init(ngx_pool_t *pool);
static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool);
static char *ngx_http_core_init_srv_conf(ngx_pool_t *pool, void *conf);
static void *ngx_http_core_create_loc_conf(ngx_pool_t *pool);
static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool,
void *parent, void *child);
static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy);
static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd,
@ -78,13 +80,13 @@ static ngx_command_t ngx_http_core_commands[] = {
{ngx_string("location"),
NGX_HTTP_SRV_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1,
ngx_location_block,
0,
NGX_HTTP_SRV_CONF_OFFSET,
0},
{ngx_string("listen"),
NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
ngx_set_listen,
0,
NGX_HTTP_SRV_CONF_OFFSET,
0},
{ngx_string("root"),
@ -93,6 +95,12 @@ static ngx_command_t ngx_http_core_commands[] = {
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_core_loc_conf_t, doc_root)},
{ngx_string("sendfile"),
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_flag_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_core_loc_conf_t, sendfile)},
{ngx_string("send_timeout"),
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_time_slot,
@ -100,13 +108,13 @@ static ngx_command_t ngx_http_core_commands[] = {
offsetof(ngx_http_core_loc_conf_t, send_timeout)},
{ngx_string("lingering_time"),
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_time_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_core_loc_conf_t, lingering_time)},
{ngx_string("lingering_timeout"),
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_time_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_core_loc_conf_t, lingering_timeout)},
@ -116,13 +124,13 @@ static ngx_command_t ngx_http_core_commands[] = {
ngx_http_module_t ngx_http_core_module_ctx = {
NGX_HTTP_MODULE,
ngx_http_core_create_srv_conf, /* create server config */
ngx_http_core_init_srv_conf, /* init server config */
ngx_http_core_create_loc_conf, /* create location config */
NULL, /* merge location config */
NULL /* init filters */
ngx_http_core_merge_loc_conf /* merge location config */
};
@ -137,24 +145,26 @@ ngx_module_t ngx_http_core_module = {
int ngx_http_handler(ngx_http_request_t *r)
{
int rc, a, n, i;
ngx_http_handler_pt *h;
ngx_http_module_t *module;
ngx_http_conf_ctx_t *ctx;
ngx_http_in_port_t *in_port;
ngx_http_in_addr_t *in_addr;
ngx_http_server_name_t *name;
int rc, a, n, i;
ngx_http_handler_pt *h;
ngx_http_module_t *module;
ngx_http_conf_ctx_t *ctx;
ngx_http_in_port_t *in_port;
ngx_http_in_addr_t *in_addr;
ngx_http_server_name_t *name;
ngx_http_core_srv_conf_t *scf;
ngx_http_core_loc_conf_t *lcf, **plcf;
r->connection->unexpected_eof = 0;
r->keepalive = 1;
r->lingering_close = 1;
#if 1
r->filter = NGX_HTTP_FILTER_NEED_IN_MEMORY;
#if 0
ngx_log_debug(r->connection->log, "servers: %0x" _ r->connection->servers);
#endif
ngx_log_debug(r->connection->log, "servers: %0x" _ r->connection->servers);
/* find server config */
if (r->connection->servers == NULL) {
ctx = (ngx_http_conf_ctx_t *) r->connection->ctx;
@ -206,15 +216,52 @@ ngx_log_debug(r->connection->log, "servers: %0x" _ r->connection->servers);
r->srv_conf = ctx->srv_conf;
r->loc_conf = ctx->loc_conf;
#if 0
ngx_log_debug(r->connection->log, "cxt: %08x" _ ctx);
ngx_log_debug(r->connection->log, "srv_conf: %0x" _ r->srv_conf);
ngx_log_debug(r->connection->log, "loc_conf: %0x" _ r->loc_conf);
#endif
/* run rewrite url phase */
/* find location config */
scf = (ngx_http_core_srv_conf_t *)
ngx_http_get_module_srv_conf(r, ngx_http_core_module_ctx);
plcf = (ngx_http_core_loc_conf_t **) scf->locations.elts;
for (i = 0; i < scf->locations.nelts; i++) {
#if 0
ngx_log_debug(r->connection->log, "trans: %s" _ plcf[i]->name.data);
#endif
if (r->uri.len < plcf[i]->name.len) {
continue;
}
rc = ngx_strncmp(r->uri.data, plcf[i]->name.data, plcf[i]->name.len);
if (rc < 0) {
break;
}
if (rc == 0) {
r->loc_conf = plcf[i]->loc_conf;
}
}
lcf = (ngx_http_core_loc_conf_t *)
ngx_http_get_module_loc_conf(r, ngx_http_core_module_ctx);
if (lcf->sendfile == 0) {
r->filter = NGX_HTTP_FILTER_NEED_IN_MEMORY;
}
/* run translation phase */
h = (ngx_http_handler_pt *) ngx_http_translate_handlers.elts;
for (i = 0; i < ngx_http_translate_handlers.nelts; i++) {
rc = h[i](r);
for (i = ngx_http_translate_handlers.nelts; i > 0; /* void */) {
rc = h[--i](r);
if (rc == NGX_DECLINED) {
continue;
@ -241,43 +288,24 @@ int ngx_http_core_translate_handler(ngx_http_request_t *r)
ngx_table_elt_t *h;
ngx_http_server_name_t *s_name;
ngx_http_core_srv_conf_t *scf;
ngx_http_core_loc_conf_t *lcf, **plcf;
ngx_http_core_loc_conf_t *lcf;
scf = (ngx_http_core_srv_conf_t *)
ngx_http_get_module_srv_conf(r, ngx_http_core_module);
lcf = (ngx_http_core_loc_conf_t *)
ngx_http_get_module_loc_conf(r, ngx_http_core_module_ctx);
/* find location config */
plcf = (ngx_http_core_loc_conf_t **) scf->locations.elts;
for (i = 0; i < scf->locations.nelts; i++) {
ngx_log_debug(r->connection->log, "trans: %s" _ plcf[i]->name.data);
if (r->uri.len < plcf[i]->name.len) {
continue;
}
rc = ngx_strncmp(r->uri.data, plcf[i]->name.data, plcf[i]->name.len);
if (rc < 0) {
break;
}
if (rc == 0) {
r->loc_conf = plcf[i]->loc_conf;
}
if (lcf->handler) {
r->handler = lcf->handler;
return NGX_OK;
}
#if 0
/* STUB */ r->handler = ngx_http_proxy_handler;
return NGX_OK;
#endif
scf = (ngx_http_core_srv_conf_t *)
ngx_http_get_module_srv_conf(r, ngx_http_core_module_ctx);
if (r->uri.data[r->uri.len - 1] == '/') {
r->handler = ngx_http_core_index_handler;
return NGX_OK;
}
lcf = (ngx_http_core_loc_conf_t *)
ngx_http_get_module_loc_conf(r, ngx_http_core_module);
ngx_log_debug(r->connection->log, "doc_root: %08x" _ &lcf->doc_root);
s_name = (ngx_http_server_name_t *) scf->server_names.elts;
@ -440,8 +468,7 @@ ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data);
return NGX_HTTP_MOVED_PERMANENTLY;
}
/* TODO: r->handler = lcf->default_handler; */
/* STUB */ r->handler = ngx_http_static_handler;
r->handler = ngx_http_static_handler;
return NGX_OK;
}
@ -453,8 +480,8 @@ static int ngx_http_core_index_handler(ngx_http_request_t *r)
ngx_http_handler_pt *h;
h = (ngx_http_handler_pt *) ngx_http_index_handlers.elts;
for (i = 0; i < ngx_http_index_handlers.nelts; i++) {
rc = h[i](r);
for (i = ngx_http_index_handlers.nelts; i > 0; /* void */) {
rc = h[--i](r);
if (rc != NGX_DECLINED) {
@ -545,7 +572,7 @@ int ngx_http_close_request(ngx_http_request_t *r, int error)
ngx_log_debug(c->log, "http closed");
return NGX_DONE;
return NGX_ERROR; /* to close connection */
}
@ -608,13 +635,13 @@ static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy)
module = (ngx_http_module_t *) ngx_modules[i]->ctx;
if (module->create_srv_conf) {
ngx_test_null(ctx->srv_conf[ngx_modules[i]->index],
ngx_test_null(ctx->srv_conf[module->index],
module->create_srv_conf(cf->pool),
NGX_CONF_ERROR);
}
if (module->create_loc_conf) {
ngx_test_null(ctx->loc_conf[ngx_modules[i]->index],
ngx_test_null(ctx->loc_conf[module->index],
module->create_loc_conf(cf->pool),
NGX_CONF_ERROR);
}
@ -629,7 +656,7 @@ static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy)
return rv;
scf = ctx->srv_conf[ngx_http_core_module.index];
scf = ctx->srv_conf[ngx_http_core_module_ctx.index];
scf->ctx = ctx;
plcf = (ngx_http_core_loc_conf_t **)scf->locations.elts;
@ -643,7 +670,7 @@ static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy)
if (module->init_srv_conf) {
if (module->init_srv_conf(cf->pool,
ctx->srv_conf[ngx_modules[i]->index])
ctx->srv_conf[module->index])
== NGX_CONF_ERROR) {
return NGX_CONF_ERROR;
}
@ -651,16 +678,16 @@ static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy)
if (module->merge_loc_conf) {
if (module->merge_loc_conf(cf->pool,
prev->loc_conf[ngx_modules[i]->index],
ctx->loc_conf[ngx_modules[i]->index])
prev->loc_conf[module->index],
ctx->loc_conf[module->index])
== NGX_CONF_ERROR) {
return NGX_CONF_ERROR;
}
for (j = 0; j < scf->locations.nelts; j++) {
if (module->merge_loc_conf(cf->pool,
ctx->loc_conf[ngx_modules[i]->index],
plcf[j]->loc_conf[ngx_modules[i]->index])
ctx->loc_conf[module->index],
plcf[j]->loc_conf[module->index])
== NGX_CONF_ERROR) {
return NGX_CONF_ERROR;
}
@ -701,21 +728,21 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy)
module = (ngx_http_module_t *) ngx_modules[i]->ctx;
if (module->create_loc_conf) {
ngx_test_null(ctx->loc_conf[ngx_modules[i]->index],
ngx_test_null(ctx->loc_conf[module->index],
module->create_loc_conf(cf->pool),
NGX_CONF_ERROR);
}
}
lcf = (ngx_http_core_loc_conf_t *)
ctx->loc_conf[ngx_http_core_module.index];
ctx->loc_conf[ngx_http_core_module_ctx.index];
location = (ngx_str_t *) cf->args->elts;
lcf->name.len = location[1].len;
lcf->name.data = location[1].data;
lcf->loc_conf = ctx->loc_conf;
scf = (ngx_http_core_srv_conf_t *)
ctx->srv_conf[ngx_http_core_module.index];
ctx->srv_conf[ngx_http_core_module_ctx.index];
ngx_test_null(plcf, ngx_push_array(&scf->locations), NGX_CONF_ERROR);
*plcf = lcf;
@ -793,6 +820,8 @@ static void *ngx_http_core_create_loc_conf(ngx_pool_t *pool)
lcf->doc_root.len = 4;
lcf->doc_root.data = "html";
lcf->sendfile = 0;
lcf->send_timeout = 10000;
lcf->discarded_buffer_size = 1500;
lcf->lingering_time = 30000;
@ -805,6 +834,12 @@ static void *ngx_http_core_create_loc_conf(ngx_pool_t *pool)
return lcf;
}
static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool,
void *parent, void *child)
{
return NGX_CONF_OK;
}
static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, char *conf)
{
ngx_str_t *args;

View File

@ -57,13 +57,17 @@ typedef struct {
void **loc_conf; /* pointer to modules loc_conf,
used in translation handler */
int (*handler) (ngx_http_request_t *r);
ngx_str_t doc_root; /* root */
int sendfile; /* sendfile */
time_t send_timeout; /* send_timeout */
size_t send_lowat; /* send_lowa */
size_t discarded_buffer_size; /* discarded_buffer_size */
time_t lingering_time; /* lingering_time */
ngx_msec_t lingering_timeout; /* lingering_timeout */
} ngx_http_core_loc_conf_t;
@ -76,10 +80,20 @@ typedef struct {
#endif
#if 0
#define ngx_http_set_loc_handler(conf_ctx, ngx_http_handler) \
{ \
ngx_http_conf_ctx_t *cx = conf_ctx; \
ngx_http_core_loc_conf_t *lcf; \
lcf = cx->loc_conf[ngx_http_core_module_ctx.index]; \
lcf->handler = ngx_http_handler; \
}
#endif
extern ngx_http_module_t ngx_http_core_module_ctx;
extern ngx_module_t ngx_http_core_module;
extern int (*ngx_http_top_header_filter) (ngx_http_request_t *r);
extern int ngx_http_max_module;

View File

@ -238,12 +238,12 @@ static int ngx_http_process_request(ngx_event_t *rev)
r->header_in->last += n;
}
/* the state_handlers are called in the following order:
/* the state handlers are called in the following order:
ngx_http_process_request_line(r)
ngx_http_process_request_headers(r) */
do {
rc = (r->state_handler)(r);
rc = r->state_handler(r);
} while (rc == NGX_AGAIN && r->header_in->pos < r->header_in->last);
@ -265,8 +265,8 @@ static int ngx_http_process_request(ngx_event_t *rev)
rc = ngx_http_handler(r);
/* a handler is still busy */
if (rc == NGX_BUSY) {
/* a handler does its own processing */
if (rc == NGX_DONE) {
return rc;
}
@ -310,6 +310,14 @@ static int ngx_http_process_request_line(ngx_http_request_t *r)
if (rc == NGX_OK) {
if (r->http_version >= NGX_HTTP_VERSION_10
&& ngx_http_large_client_header == 0
&& r->header_in->pos == r->header_in->end)
{
ngx_http_header_parse_error(r, NGX_HTTP_PARSE_TOO_LONG_URI);
return NGX_HTTP_REQUEST_URI_TOO_LARGE;
}
/* copy URI */
if (r->args_start) {
@ -329,7 +337,6 @@ static int ngx_http_process_request_line(ngx_http_request_t *r)
we need to copy a request line */
if (ngx_http_large_client_header) {
ngx_test_null(r->request_line.data,
ngx_palloc(r->pool, r->request_line.len + 1),
NGX_HTTP_INTERNAL_SERVER_ERROR);
@ -651,8 +658,8 @@ int ngx_http_finalize_request(ngx_http_request_t *r, int error)
but the transfer is still not completed */
lcf = (ngx_http_core_loc_conf_t *)
ngx_http_get_module_loc_conf(r->main ? r->main : r,
ngx_http_core_module);
ngx_http_get_module_loc_conf(r->main ? r->main : r,
ngx_http_core_module_ctx);
wev = r->connection->write;
wev->event_handler = ngx_http_writer;
wev->timer_set = 1;
@ -725,8 +732,8 @@ static int ngx_http_writer(ngx_event_t *wev)
if (rc == NGX_AGAIN) {
lcf = (ngx_http_core_loc_conf_t *)
ngx_http_get_module_loc_conf(r->main ? r->main : r,
ngx_http_core_module);
ngx_http_get_module_loc_conf(r->main ? r->main : r,
ngx_http_core_module_ctx);
if (wev->timer_set) {
ngx_del_timer(wev);
} else {
@ -824,7 +831,7 @@ static int ngx_http_read_discarded_body(ngx_event_t *ev)
r = (ngx_http_request_t *) c->data;
lcf = (ngx_http_core_loc_conf_t *)
ngx_http_get_module_loc_conf(r, ngx_http_core_module);
ngx_http_get_module_loc_conf(r, ngx_http_core_module_ctx);
if (r->discarded_buffer == NULL) {
ngx_test_null(r->discarded_buffer,
@ -944,7 +951,7 @@ static int ngx_http_keepalive_handler(ngx_event_t *rev)
ngx_log_debug(c->log, "http keepalive handler");
if (rev->timedout) {
return NGX_DONE;
return NGX_ERROR; /* to close connection */
}
/* MSIE closes a keepalive connection with RST flag
@ -965,7 +972,7 @@ static int ngx_http_keepalive_handler(ngx_event_t *rev)
if (n == 0) {
ngx_log_error(NGX_LOG_INFO, c->log, ngx_socket_errno,
"client %s closed keepalive connection", lctx->client);
return NGX_DONE;
return NGX_ERROR; /* to close connection */
}
c->buffer->last += n;
@ -986,7 +993,7 @@ static int ngx_http_set_lingering_close(ngx_http_request_t *r)
rev = c->read;
lcf = (ngx_http_core_loc_conf_t *)
ngx_http_get_module_loc_conf(r, ngx_http_core_module);
ngx_http_get_module_loc_conf(r, ngx_http_core_module_ctx);
r->lingering_time = ngx_time() + lcf->lingering_time / 1000;
r->connection->read->event_handler = ngx_http_lingering_close_handler;
@ -1063,7 +1070,7 @@ static int ngx_http_lingering_close_handler(ngx_event_t *rev)
}
lcf = (ngx_http_core_loc_conf_t *)
ngx_http_get_module_loc_conf(r, ngx_http_core_module);
ngx_http_get_module_loc_conf(r, ngx_http_core_module_ctx);
if (r->discarded_buffer == NULL) {

View File

@ -14,8 +14,7 @@
#include <ngx_http_write_filter.h>
static void ngx_http_header_filter_init(ngx_pool_t *pool,
ngx_http_conf_filter_t *cf);
static int ngx_http_header_filter_init(ngx_pool_t *pool);
static int ngx_http_header_filter(ngx_http_request_t *r);
@ -26,7 +25,7 @@ ngx_http_module_t ngx_http_header_filter_module_ctx = {
NULL, /* create location config */
NULL, /* merge location config */
ngx_http_header_filter_init /* init filters */
NULL /* init filters */
};
@ -35,7 +34,7 @@ ngx_module_t ngx_http_header_filter_module = {
&ngx_http_header_filter_module_ctx, /* module context */
NULL, /* module directives */
NGX_HTTP_MODULE_TYPE, /* module type */
NULL /* init module */
ngx_http_header_filter_init /* init module */
};
@ -294,8 +293,8 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
}
static void ngx_http_header_filter_init(ngx_pool_t *pool,
ngx_http_conf_filter_t *cf)
static int ngx_http_header_filter_init(ngx_pool_t *pool)
{
cf->output_header_filter = ngx_http_header_filter;
ngx_http_top_header_filter = ngx_http_header_filter;
return NGX_OK;
}

View File

@ -33,13 +33,13 @@ static ngx_command_t ngx_http_output_filter_commands[] = {
static ngx_http_module_t ngx_http_output_filter_module_ctx = {
NGX_HTTP_MODULE,
NULL, /* create server config */
NULL, /* init server config */
ngx_http_output_filter_create_conf, /* create location config */
ngx_http_output_filter_merge_conf, /* merge location config */
ngx_http_output_filter_init /* output body filter */
ngx_http_output_filter_merge_conf /* merge location config */
};
@ -52,8 +52,11 @@ ngx_module_t ngx_http_output_filter_module = {
};
#define next_filter (*ngx_http_top_body_filter)
#if 0
static int (*next_filter) (ngx_http_request_t *r, ngx_chain_t *ch);
#endif
#if 0
@ -77,10 +80,10 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
ctx = (ngx_http_output_filter_ctx_t *)
ngx_http_get_module_ctx(r->main ? r->main : r,
ngx_http_output_filter_module);
ngx_http_output_filter_module_ctx);
if (ctx == NULL) {
ngx_http_create_ctx(r, ctx, ngx_http_output_filter_module,
ngx_http_create_ctx(r, ctx, ngx_http_output_filter_module_ctx,
sizeof(ngx_http_output_filter_ctx_t), NGX_ERROR);
}
@ -120,8 +123,8 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
if (ctx->hunk == NULL) {
conf = (ngx_http_output_filter_conf_t *)
ngx_http_get_module_loc_conf(r->main ? r->main : r,
ngx_http_output_filter_module);
ngx_http_get_module_loc_conf(r->main ? r->main : r,
ngx_http_output_filter_module_ctx);
if (hunk->type & NGX_HUNK_LAST) {
if (hunk->type & NGX_HUNK_IN_MEMORY) {
@ -303,8 +306,10 @@ static int ngx_http_output_filter_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src)
static void ngx_http_output_filter_init(ngx_pool_t *pool,
ngx_http_conf_filter_t *cf)
{
#if 0
next_filter = cf->output_body_filter;
cf->output_body_filter = NULL;
#endif
}

View File

@ -338,6 +338,7 @@ int ngx_read_http_header_line(ngx_http_request_t *r, ngx_hunk_t *h)
sw_space_after_value,
sw_almost_done,
sw_header_almost_done,
sw_ignore_line,
sw_done,
sw_header_done
} state;
@ -404,6 +405,14 @@ int ngx_read_http_header_line(ngx_http_request_t *r, ngx_hunk_t *h)
break;
}
if (ch == '/') {
/* IIS can send duplicate "HTTP/1.1 ..." lines */
if (r->proxy && ngx_strncmp(r->header_start, "HTTP", 4) == 0) {
state = sw_ignore_line;
break;
}
}
return NGX_HTTP_PARSE_INVALID_HEADER;
/* space* before header value */
@ -461,6 +470,17 @@ int ngx_read_http_header_line(ngx_http_request_t *r, ngx_hunk_t *h)
}
break;
/* ignore header line */
case sw_ignore_line:
switch (ch) {
case LF:
state = sw_start;
break;
default:
break;
}
break;
/* end of header line */
case sw_almost_done:
switch (ch) {

View File

@ -122,11 +122,22 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error)
if (error < NGX_HTTP_BAD_REQUEST) {
err = error - NGX_HTTP_MOVED_PERMANENTLY;
} else if (error < NGX_HTTP_INTERNAL_SERVER_ERROR) {
err = error - NGX_HTTP_BAD_REQUEST + 3;
} else {
err = error - NGX_HTTP_INTERNAL_SERVER_ERROR + 3 + 17;
ngx_test_null(r->headers_out.content_type,
ngx_push_table(r->headers_out.headers),
NGX_HTTP_INTERNAL_SERVER_ERROR);
r->headers_out.content_type->key.len = 12;
r->headers_out.content_type->key.data = "Content-Type";
r->headers_out.content_type->value.len = 9;
r->headers_out.content_type->value.data = "text/html";
if (error < NGX_HTTP_INTERNAL_SERVER_ERROR) {
err = error - NGX_HTTP_BAD_REQUEST + 3;
} else {
err = error - NGX_HTTP_INTERNAL_SERVER_ERROR + 3 + 17;
}
}
if (r->keepalive != 0) {

View File

@ -16,30 +16,29 @@
static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool);
static char *ngx_http_write_filter_merge_conf(ngx_pool_t *pool,
void *parent, void *child);
static void ngx_http_write_filter_init(ngx_pool_t *pool,
ngx_http_conf_filter_t *cf);
static int ngx_http_write_filter_init(ngx_pool_t *pool);
static ngx_command_t ngx_http_write_filter_commands[] = {
{ngx_string("write_buffer"),
{ngx_string("buffer_output"),
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_write_filter_conf_t, buffer_output)},
{ngx_string(""), 0, NULL, 0, 0}
{ngx_null_string, 0, NULL, 0, 0}
};
ngx_http_module_t ngx_http_write_filter_module_ctx = {
NGX_HTTP_MODULE,
NULL, /* create server config */
NULL, /* init server config */
ngx_http_write_filter_create_conf, /* create location config */
ngx_http_write_filter_merge_conf, /* merge location config */
ngx_http_write_filter_init /* init filters */
ngx_http_write_filter_merge_conf /* merge location config */
};
@ -48,24 +47,24 @@ ngx_module_t ngx_http_write_filter_module = {
&ngx_http_write_filter_module_ctx, /* module context */
ngx_http_write_filter_commands, /* module directives */
NGX_HTTP_MODULE_TYPE, /* module type */
NULL /* init module */
ngx_http_write_filter_init /* init module */
};
int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
int last;
off_t size, flush;
ngx_chain_t *ce, **le, *chain;
ngx_http_write_filter_ctx_t *ctx;
ngx_http_write_filter_conf_t *conf;
int last;
off_t size, flush;
ngx_chain_t *ce, **le, *chain;
ngx_http_write_filter_ctx_t *ctx;
ngx_http_write_filter_conf_t *conf;
ctx = (ngx_http_write_filter_ctx_t *)
ngx_http_get_module_ctx(r->main ? r->main : r,
ngx_http_write_filter_module);
ngx_http_write_filter_module_ctx);
if (ctx == NULL) {
ngx_http_create_ctx(r, ctx, ngx_http_write_filter_module,
ngx_http_create_ctx(r, ctx, ngx_http_write_filter_module_ctx,
sizeof(ngx_http_write_filter_ctx_t), NGX_ERROR);
}
@ -73,7 +72,8 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
last = 0;
le = &ctx->out;
/* find the size, the flush point and the last entry of saved chain */
/* find the size, the flush point and the last entry of the saved chain */
for (ce = ctx->out; ce; ce = ce->next) {
le = &ce->next;
@ -93,6 +93,7 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
/* add the new chain to the existent one */
for (/* void */; in; in = in->next) {
ngx_test_null(ce, ngx_palloc(r->pool, sizeof(ngx_chain_t)), NGX_ERROR);
@ -118,7 +119,7 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
conf = (ngx_http_write_filter_conf_t *)
ngx_http_get_module_loc_conf(r->main ? r->main : r,
ngx_http_write_filter_module);
ngx_http_write_filter_module_ctx);
#if (NGX_DEBUG_WRITE_FILTER)
ngx_log_debug(r->connection->log, "write filter: last:%d flush:%d" _
@ -126,7 +127,8 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
#endif
/* avoid the output if there is no last hunk, no flush point and
size of the hunks is smaller then 'write_buffer' */
size of the hunks is smaller then "buffer_output" */
if (!last && flush == 0 && size < conf->buffer_output) {
return NGX_OK;
}
@ -152,13 +154,6 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
static void ngx_http_write_filter_init(ngx_pool_t *pool,
ngx_http_conf_filter_t *cf)
{
cf->output_body_filter = ngx_http_write_filter;
}
static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool)
{
ngx_http_write_filter_conf_t *conf;
@ -186,3 +181,10 @@ static char *ngx_http_write_filter_merge_conf(ngx_pool_t *pool,
return NULL;
}
static int ngx_http_write_filter_init(ngx_pool_t *pool)
{
ngx_http_top_body_filter = ngx_http_write_filter;
return NGX_OK;
}