nginx-0.0.1-2003-05-19-20:39:14 import
diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c
index 2a236ee..49a4e0a 100644
--- a/src/http/modules/ngx_http_index_handler.c
+++ b/src/http/modules/ngx_http_index_handler.c
@@ -38,11 +38,14 @@
ngx_http_module_t ngx_http_index_module_ctx = {
NGX_HTTP_MODULE,
- NULL, /* create server config */
- NULL, /* init server config */
+ NULL, /* create main configuration */
+ NULL, /* init main configuration */
- ngx_http_index_create_conf, /* create location config */
- ngx_http_index_merge_conf /* merge location config */
+ NULL, /* create server configuration */
+ NULL, /* merge server configuration */
+
+ ngx_http_index_create_conf, /* create location configration */
+ ngx_http_index_merge_conf /* merge location configration */
};
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c
index 17c3da5..ffa94cf 100644
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -16,17 +16,6 @@
int ngx_http_max_module;
-ngx_array_t ngx_http_servers; /* array of ngx_http_core_srv_conf_t */
-
-int ngx_http_post_accept_timeout = 30000;
-int ngx_http_connection_pool_size = 16384;
-int ngx_http_request_pool_size = 16384;
-int ngx_http_client_header_timeout = 60000;
-int ngx_http_client_header_buffer_size = 1024;
-int ngx_http_large_client_header = 1;
-
-int ngx_http_url_in_error_log = 1;
-
ngx_array_t ngx_http_translate_handlers;
ngx_array_t ngx_http_index_handlers;
@@ -63,65 +52,79 @@
static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, char *conf)
{
- int i, s, l, p, a, n, start;
- int port_found, addr_found, virtual_names;
- char *rv;
- struct sockaddr_in *addr_in;
- ngx_array_t in_ports;
- ngx_listen_t *ls;
- ngx_http_module_t *module;
- ngx_conf_t pcf;
- ngx_http_conf_ctx_t *ctx;
- ngx_http_in_port_t *in_port, *inport;
- ngx_http_in_addr_t *in_addr, *inaddr;
- ngx_http_core_srv_conf_t **cscf;
- ngx_http_listen_t *lscf;
- ngx_http_server_name_t *s_name, *name;
+ int mi, m, s, l, p, a, n;
+ int port_found, addr_found, virtual_names;
+ char *rv;
+ struct sockaddr_in *addr_in;
+ ngx_array_t in_ports;
+ ngx_listen_t *ls;
+ ngx_http_module_t *module;
+ ngx_conf_t pcf;
+ ngx_http_conf_ctx_t *ctx;
+ ngx_http_in_port_t *in_port, *inport;
+ ngx_http_in_addr_t *in_addr, *inaddr;
+ ngx_http_core_main_conf_t *cmcf;
+ ngx_http_core_srv_conf_t **cscfp;
+ ngx_http_core_loc_conf_t **clcfp;
+ ngx_http_listen_t *lscf;
+ ngx_http_server_name_t *s_name, *name;
- ngx_init_array(ngx_http_servers, cf->pool, 10,
- sizeof(ngx_http_core_srv_conf_t *), NGX_CONF_ERROR);
-
+ /* the main http context */
ngx_test_null(ctx,
ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)),
NGX_CONF_ERROR);
*(ngx_http_conf_ctx_t **) conf = ctx;
+
+ /* count the number of the http modules and set up their indices */
+
ngx_http_max_module = 0;
- for (i = 0; ngx_modules[i]; i++) {
- if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) {
+ for (m = 0; ngx_modules[m]; m++) {
+ if (ngx_modules[m]->type != NGX_HTTP_MODULE_TYPE) {
continue;
}
- module = (ngx_http_module_t *) ngx_modules[i]->ctx;
-
+ module = (ngx_http_module_t *) ngx_modules[m]->ctx;
module->index = ngx_http_max_module++;
}
- /* TODO: http main_conf */
-
+ /* the main http main_conf, it's the same in the all http contexts */
ngx_test_null(ctx->main_conf,
ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
NGX_CONF_ERROR);
- /* TODO: http srv_conf */
-
+ /* the http null srv_conf, it's used to merge the server{}s' srv_conf's */
ngx_test_null(ctx->srv_conf,
ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
NGX_CONF_ERROR);
- /* http null loc_conf */
-
+ /* the http null loc_conf, it's used to merge the server{}s' loc_conf's */
ngx_test_null(ctx->loc_conf,
ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
NGX_CONF_ERROR);
- for (i = 0; ngx_modules[i]; i++) {
- if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) {
+
+ /* create the main_conf, srv_conf and loc_conf in all http modules */
+
+ for (m = 0; ngx_modules[m]; m++) {
+ if (ngx_modules[m]->type != NGX_HTTP_MODULE_TYPE) {
continue;
}
- module = (ngx_http_module_t *) ngx_modules[i]->ctx;
+ module = (ngx_http_module_t *) ngx_modules[m]->ctx;
+
+ if (module->create_main_conf) {
+ ngx_test_null(ctx->main_conf[module->index],
+ module->create_main_conf(cf->pool),
+ NGX_CONF_ERROR);
+ }
+
+ if (module->create_srv_conf) {
+ 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[module->index],
@@ -130,6 +133,9 @@
}
}
+
+ /* parse inside the http{} block */
+
pcf = *cf;
cf->ctx = ctx;
cf->module_type = NGX_HTTP_MODULE_TYPE;
@@ -141,22 +147,71 @@
return rv;
-#if 0
- /* DEBUG STUFF */
- cscf = (ngx_http_core_srv_conf_t **) ngx_http_servers.elts;
- for (s = 0; s < ngx_http_servers.nelts; s++) {
- ngx_http_core_loc_conf_t **loc;
+ /* init http{} main_conf's, merge the server{}s' srv_conf's
+ and its location{}s' loc_conf's */
- ngx_log_debug(cf->log, "srv: %08x" _ cscf[s]);
- loc = (ngx_http_core_loc_conf_t **) cscf[s]->locations.elts;
- for (l = 0; l < cscf[s]->locations.nelts; l++) {
- ngx_log_debug(cf->log, "loc: %08x:%s, %08x:%s" _
- loc[l] _ loc[l]->name.data _
- &loc[l]->doc_root _ loc[l]->doc_root.data);
+ cmcf = ctx->main_conf[ngx_http_core_module_ctx.index];
+ cscfp = (ngx_http_core_srv_conf_t **)cmcf->servers.elts;
+
+ for (m = 0; ngx_modules[m]; m++) {
+ if (ngx_modules[m]->type != NGX_HTTP_MODULE_TYPE) {
+ continue;
+ }
+
+ module = (ngx_http_module_t *) ngx_modules[m]->ctx;
+ mi = module->index;
+
+ /* init http{} main_conf's */
+
+ if (module->init_main_conf) {
+ rv = module->init_main_conf(cf->pool, ctx->main_conf[mi]);
+ if (rv != NGX_CONF_OK) {
+ return rv;
+ }
+ }
+
+ for (s = 0; s < cmcf->servers.nelts; s++) {
+
+ /* merge the server{}s' srv_conf's */
+
+ if (module->merge_srv_conf) {
+ rv = module->merge_srv_conf(cf->pool,
+ ctx->srv_conf[mi],
+ cscfp[s]->ctx->srv_conf[mi]);
+ if (rv != NGX_CONF_OK) {
+ return rv;
+ }
+ }
+
+ if (module->merge_loc_conf) {
+
+ /* merge the server{}'s loc_conf */
+
+ rv = module->merge_loc_conf(cf->pool,
+ ctx->loc_conf[mi],
+ cscfp[s]->ctx->loc_conf[mi]);
+ if (rv != NGX_CONF_OK) {
+ return rv;
+ }
+
+ /* merge the locations{}' loc_conf's */
+
+ clcfp = (ngx_http_core_loc_conf_t **)cscfp[s]->locations.elts;
+
+ for (l = 0; l < cscfp[s]->locations.nelts; l++) {
+ rv = module->merge_loc_conf(cf->pool,
+ cscfp[s]->ctx->loc_conf[mi],
+ clcfp[l]->loc_conf[mi]);
+ if (rv != NGX_CONF_OK) {
+ return rv;
+ }
+ }
+ }
}
}
- /**/
-#endif
+
+
+ /* init list of the handlers */
ngx_init_array(ngx_http_translate_handlers,
cf->pool, 10, sizeof(ngx_http_handler_pt), NGX_CONF_ERROR);
@@ -172,12 +227,12 @@
NGX_CONF_ERROR);
/* "server" directives */
- cscf = (ngx_http_core_srv_conf_t **) ngx_http_servers.elts;
- for (s = 0; s < ngx_http_servers.nelts; s++) {
+ cscfp = (ngx_http_core_srv_conf_t **) cmcf->servers.elts;
+ for (s = 0; s < cmcf->servers.nelts; s++) {
/* "listen" directives */
- lscf = (ngx_http_listen_t *) cscf[s]->listen.elts;
- for (l = 0; l < cscf[s]->listen.nelts; l++) {
+ lscf = (ngx_http_listen_t *) cscfp[s]->listen.elts;
+ for (l = 0; l < cscfp[s]->listen.nelts; l++) {
port_found = 0;
@@ -202,8 +257,8 @@
/* "server_name" directives */
s_name = (ngx_http_server_name_t *)
- cscf[s]->server_names.elts;
- for (n = 0; n < cscf[s]->server_names.nelts; n++) {
+ cscfp[s]->server_names.elts;
+ for (n = 0; n < cscfp[s]->server_names.nelts; n++) {
/* add the server name and server core module
configuration to the address:port */
@@ -234,7 +289,7 @@
}
in_addr[a].flags |= NGX_HTTP_DEFAULT_SERVER;
- in_addr[a].core_srv_conf = cscf[s];
+ in_addr[a].core_srv_conf = cscfp[s];
}
addr_found = 1;
@@ -256,7 +311,7 @@
in_addr[a].addr = lscf[l].addr;
in_addr[a].flags = lscf[l].flags;
- in_addr[a].core_srv_conf = cscf[s];
+ in_addr[a].core_srv_conf = cscfp[s];
/* create the empty list of the server names that
can be served on this address:port */
@@ -282,7 +337,7 @@
inaddr->addr = lscf[l].addr;
inaddr->flags = lscf[l].flags;
- inaddr->core_srv_conf = cscf[s];
+ inaddr->core_srv_conf = cscfp[s];
/* create the empty list of the server names that
can be served on this address:port */
@@ -317,7 +372,7 @@
inaddr->addr = lscf[l].addr;
inaddr->flags = lscf[l].flags;
- inaddr->core_srv_conf = cscf[s];
+ inaddr->core_srv_conf = cscfp[s];
/* create the empty list of the server names that
can be served on this address:port */
@@ -407,12 +462,12 @@
ls->addr = offsetof(struct sockaddr_in, sin_addr);
ls->addr_text_max_len = INET_ADDRSTRLEN;
ls->backlog = -1;
- ls->post_accept_timeout = ngx_http_post_accept_timeout;
+ ls->post_accept_timeout = cmcf->post_accept_timeout;
ls->nonblocking = 1;
ls->handler = ngx_http_init_connection;
ls->log = cf->log;
- ls->pool_size = ngx_http_connection_pool_size;
+ ls->pool_size = cmcf->connection_pool_size;
ls->ctx = ctx;
if (in_port[p].addrs.nelts > 1) {
@@ -475,87 +530,3 @@
return NGX_CONF_OK;
}
-
-
-#if 0
-/* STUB */
-
-static struct sockaddr_in addr;
-static char addr_text[22];
-
-
-int ngx_http_init(ngx_pool_t *pool, ngx_log_t *log)
-{
- ngx_listen_t *ls;
-
- ngx_http_server.connection_pool_size = 16384;
- ngx_http_server.request_pool_size = 16384;
- ngx_http_server.header_timeout = 20000;
- ngx_http_server.header_buffer_size = 1024;
- ngx_http_server.discarded_buffer_size = 1500;
-
- ngx_http_server.lingering_timeout = 5000;
- ngx_http_server.lingering_time = 30;
-
-#if (WIN32)
- ngx_http_server.doc_root = "html";
-#else
- ngx_http_server.doc_root = "/home/is/dox/";
- ngx_http_server.doc_root = "/home/is/work/xml/site-1.0.0/html";
- ngx_http_server.doc_root = "/spool/test/lperltk";
- ngx_http_server.doc_root = "/home/is/dox/ora/lperltk";
-#endif
- ngx_http_server.doc_root_len = strlen(ngx_http_server.doc_root) + 1;
-
-
- ngx_http_config_modules(pool, ngx_modules);
-
-#if 0
- /* STUB */
- ngx_http_output_filter_set_stub(pool, ngx_http_modules);
- ngx_http_write_filter_set_stub(pool, ngx_http_modules);
- ngx_http_index_set_stub(pool, ngx_http_modules);
-
- ngx_http_init_modules(pool, ngx_http_modules);
-#endif
-
- ngx_http_init_filters(pool, ngx_modules);
-
- ls = ngx_push_array(&ngx_listening_sockets);
- ngx_memzero(ls, sizeof(ngx_listen_t));
-
- addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = inet_addr("0.0.0.0");
- addr.sin_port = htons(8000);
-
- ngx_snprintf(ngx_cpystrn(addr_text, inet_ntoa(addr.sin_addr), 16),
- 7, ":%d", ntohs(addr.sin_port));
-
- ls->family = AF_INET;
- ls->type = SOCK_STREAM;
- ls->protocol = IPPROTO_IP;
-
-#if (NGX_OVERLAPPED)
- ls->flags = WSA_FLAG_OVERLAPPED;
-#else
- ls->nonblocking = 1;
-#endif
-
- ls->sockaddr = (struct sockaddr *) &addr;
- ls->socklen = sizeof(struct sockaddr_in);
- ls->addr = offsetof(struct sockaddr_in, sin_addr);
- ls->addr_text.len = INET_ADDRSTRLEN;
- ls->addr_text.data = addr_text;
- ls->backlog = -1;
- ls->post_accept_timeout = 10000;
-
- ls->handler = ngx_http_init_connection;
- ls->server = &ngx_http_server;
- ls->log = log;
-
-
- return 1;
-}
-
-/**/
-#endif
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h
index 556a00b..2a695c7 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -12,190 +12,7 @@
#include <ngx_connection.h>
#include <ngx_conf_file.h>
-/* STUB */
-#include <ngx_event_timer.h>
-
-#define NGX_HTTP_VERSION_9 9
-#define NGX_HTTP_VERSION_10 1000
-#define NGX_HTTP_VERSION_11 1001
-
-#define NGX_HTTP_GET 1
-#define NGX_HTTP_HEAD 2
-#define NGX_HTTP_POST 3
-
-#define NGX_HTTP_CONN_CLOSE 0
-#define NGX_HTTP_CONN_KEEP_ALIVE 1
-
-
-#define NGX_HTTP_PARSE_HEADER_DONE 1
-#define NGX_HTTP_PARSE_INVALID_METHOD 10
-#define NGX_HTTP_PARSE_INVALID_REQUEST 11
-#define NGX_HTTP_PARSE_TOO_LONG_URI 12
-#define NGX_HTTP_PARSE_INVALID_09_METHOD 13
-#define NGX_HTTP_PARSE_INVALID_HEADER 14
-#define NGX_HTTP_PARSE_TOO_LONG_HEADER 15
-#define NGX_HTTP_PARSE_NO_HOST_HEADER 16
-#define NGX_HTTP_PARSE_INVALID_CL_HEADER 17
-
-
-#define NGX_HTTP_OK 200
-
-#define NGX_HTTP_SPECIAL_RESPONSE 300
-#define NGX_HTTP_MOVED_PERMANENTLY 301
-#define NGX_HTTP_MOVED_TEMPORARILY 302
-#define NGX_HTTP_NOT_MODIFIED 304
-
-#define NGX_HTTP_BAD_REQUEST 400
-#define NGX_HTTP_FORBIDDEN 403
-#define NGX_HTTP_NOT_FOUND 404
-#define NGX_HTTP_REQUEST_TIME_OUT 408
-#define NGX_HTTP_REQUEST_URI_TOO_LARGE 414
-
-#define NGX_HTTP_INTERNAL_SERVER_ERROR 500
-#define NGX_HTTP_NOT_IMPLEMENTED 501
-#define NGX_HTTP_BAD_GATEWAY 502
-#define NGX_HTTP_SERVICE_UNAVAILABLE 503
-#define NGX_HTTP_GATEWAY_TIME_OUT 504
-
-
-
-#define NGX_HTTP_STATIC_HANDLER 0
-#define NGX_HTTP_DIRECTORY_HANDLER 1
-
-
-typedef struct {
- ngx_str_t name;
- int offset;
-} ngx_http_header_t;
-
-
-typedef struct {
- size_t host_name_len;
- ssize_t content_length_n;
-
- ngx_table_elt_t *host;
- ngx_table_elt_t *connection;
- ngx_table_elt_t *if_modified_since;
- ngx_table_elt_t *content_length;
- ngx_table_elt_t *accept_encoding;
-
- ngx_table_elt_t *user_agent;
-
- ngx_table_t *headers;
-} ngx_http_headers_in_t;
-
-
-typedef struct {
- ngx_chain_t chain[4];
- ngx_hunk_t *header_out;
- ngx_hunk_t *hunk;
- ngx_hunk_t *file_hunk;
- ngx_file_t temp_file;
- ngx_path_t *temp_path;
- off_t offset;
- char *header_in_pos;
-} ngx_http_request_body_t;
-
-
-typedef struct {
- int status;
- ngx_str_t status_line;
-
- ngx_table_elt_t *server;
- ngx_table_elt_t *date;
- ngx_table_elt_t *content_type;
- ngx_table_elt_t *location;
- ngx_table_elt_t *last_modified;
-
- ngx_table_t *headers;
-
- off_t content_length;
- char *charset;
- char *etag;
- time_t date_time;
- time_t last_modified_time;
-} ngx_http_headers_out_t;
-
-
-typedef struct ngx_http_request_s ngx_http_request_t;
-
-struct ngx_http_request_s {
- ngx_connection_t *connection;
-
- void **ctx;
- void **srv_conf;
- void **loc_conf;
-
- ngx_file_t file;
-
- ngx_pool_t *pool;
- ngx_hunk_t *header_in;
- ngx_http_request_body_t *request_body;
-
- ngx_http_headers_in_t headers_in;
- ngx_http_headers_out_t headers_out;
-
- int (*handler)(ngx_http_request_t *r);
-
- time_t lingering_time;
-
- int method;
- int http_version;
- int http_major;
- int http_minor;
-
- ngx_str_t request_line;
- ngx_str_t uri;
- ngx_str_t args;
- ngx_str_t exten;
- ngx_http_request_t *main;
-
- u_int in_addr;
-
- int port;
- ngx_str_t port_name;
-
- int filter;
-
- char *discarded_buffer;
-
- ngx_str_t path;
- int path_err;
-
- unsigned proxy:1;
- unsigned cachable:1;
- unsigned pipeline:1;
- unsigned keepalive:1;
- unsigned lingering_close:1;
-
- unsigned header_read:1;
- unsigned header_timeout_set:1;
-
- unsigned logging:1;
-
- unsigned header_only:1;
- unsigned unusual_uri:1; /* URI is not started with '/' - "GET http://" */
- unsigned complex_uri:1; /* URI with "/." or with "//" (WIN32) */
- unsigned path_not_found:1;
-#ifdef NGX_EVENT
- unsigned write_level_event:1;
-#endif
-
- int state;
- char *uri_start;
- char *uri_end;
- char *uri_ext;
- char *args_start;
- char *request_start;
- char *request_end;
- char *header_name_start;
- char *header_name_end;
- char *header_start;
- char *header_end;
-#ifdef NGX_EVENT
- int (*state_handler)(ngx_http_request_t *r);
-#endif
-};
+#include <ngx_http_request.h>
typedef struct {
@@ -263,21 +80,12 @@
+extern ngx_module_t ngx_http_module;
+
extern int ngx_max_module;
-extern ngx_array_t ngx_http_servers;
-extern int ngx_http_post_accept_timeout;
-extern int ngx_http_connection_pool_size;
-extern int ngx_http_request_pool_size;
-extern int ngx_http_client_header_timeout;
-extern int ngx_http_client_header_buffer_size;
-extern int ngx_http_large_client_header;
-extern int ngx_http_discarded_buffer_size;
-
-extern int ngx_http_url_in_error_log;
-
extern ngx_array_t ngx_http_translate_handlers;
extern ngx_array_t ngx_http_index_handlers;
diff --git a/src/http/ngx_http_config.h b/src/http/ngx_http_config.h
index 370b7db..abd3bdb 100644
--- a/src/http/ngx_http_config.h
+++ b/src/http/ngx_http_config.h
@@ -7,9 +7,9 @@
typedef struct {
- void **main_conf;
- void **srv_conf;
- void **loc_conf;
+ void **main_conf;
+ void **srv_conf;
+ void **loc_conf;
} ngx_http_conf_ctx_t;
@@ -22,8 +22,11 @@
typedef struct {
int index;
+ void *(*create_main_conf)(ngx_pool_t *p);
+ char *(*init_main_conf)(ngx_pool_t *p, void *conf);
+
void *(*create_srv_conf)(ngx_pool_t *p);
- char *(*init_srv_conf)(ngx_pool_t *p, void *conf);
+ char *(*merge_srv_conf)(ngx_pool_t *p, void *prev, void *conf);
void *(*create_loc_conf)(ngx_pool_t *p);
char *(*merge_loc_conf)(ngx_pool_t *p, void *prev, void *conf);
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 19bafda..2b82c29 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -6,10 +6,13 @@
#include <ngx_string.h>
#include <ngx_conf_file.h>
+#include <nginx.h>
+
#include <ngx_http.h>
#include <ngx_http_config.h>
#include <ngx_http_core_module.h>
+
/* STUB for r->filter = NGX_HTTP_FILTER_NEED_IN_MEMORY; */
#include <ngx_http_output_filter.h>
@@ -21,8 +24,11 @@
static int ngx_http_core_init(ngx_pool_t *pool);
+static void *ngx_http_core_create_main_conf(ngx_pool_t *pool);
+static char *ngx_http_core_init_main_conf(ngx_pool_t *pool, void *conf);
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 char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool,
+ void *parent, void *child);
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);
@@ -46,29 +52,29 @@
{ngx_string("post_accept_timeout"),
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
- 0,
- addressof(ngx_http_post_accept_timeout),
+ NGX_HTTP_MAIN_CONF_OFFSET,
+ offsetof(ngx_http_core_main_conf_t, post_accept_timeout),
NULL},
{ngx_string("connection_pool_size"),
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
- 0,
- addressof(ngx_http_connection_pool_size),
+ NGX_HTTP_MAIN_CONF_OFFSET,
+ offsetof(ngx_http_core_main_conf_t, connection_pool_size),
NULL},
{ngx_string("request_pool_size"),
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
- 0,
- addressof(ngx_http_request_pool_size),
+ NGX_HTTP_MAIN_CONF_OFFSET,
+ offsetof(ngx_http_core_main_conf_t, request_pool_size),
NULL},
{ngx_string("client_header_timeout"),
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
- 0,
- addressof(ngx_http_client_header_timeout),
+ NGX_HTTP_MAIN_CONF_OFFSET,
+ offsetof(ngx_http_core_main_conf_t, client_header_timeout),
NULL},
{ngx_string("client_header_buffer_size"),
@@ -81,8 +87,8 @@
{ngx_string("large_client_header"),
NGX_HTTP_MAIN_CONF|NGX_CONF_FLAG,
ngx_conf_set_flag_slot,
- 0,
- addressof(ngx_http_large_client_header),
+ NGX_HTTP_MAIN_CONF_OFFSET,
+ offsetof(ngx_http_core_main_conf_t, large_client_header),
NULL},
{ngx_string("location"),
@@ -93,49 +99,50 @@
NULL},
{ngx_string("listen"),
- NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
ngx_set_listen,
NGX_HTTP_SRV_CONF_OFFSET,
0,
NULL},
{ngx_string("types"),
- NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
+ |NGX_CONF_BLOCK|NGX_CONF_NOARGS,
ngx_types_block,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL},
{ngx_string("root"),
- NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ 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_core_loc_conf_t, doc_root),
NULL},
{ngx_string("sendfile"),
- NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|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),
NULL},
{ngx_string("send_timeout"),
- NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_core_loc_conf_t, send_timeout),
NULL},
{ngx_string("lingering_time"),
- NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_core_loc_conf_t, lingering_time),
NULL},
{ngx_string("lingering_timeout"),
- NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
@@ -148,11 +155,14 @@
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_main_conf, /* create main configuration */
+ ngx_http_core_init_main_conf, /* init main configuration */
- ngx_http_core_create_loc_conf, /* create location config */
- ngx_http_core_merge_loc_conf /* merge location config */
+ ngx_http_core_create_srv_conf, /* create server configuration */
+ ngx_http_core_merge_srv_conf, /* merge server configuration */
+
+ ngx_http_core_create_loc_conf, /* create location configuration */
+ ngx_http_core_merge_loc_conf /* merge location configuration */
};
@@ -207,6 +217,7 @@
}
}
+/* DEBUG */
if (a == in_port->addrs.nelts) {
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
"addr not found");
@@ -257,12 +268,12 @@
int rc, i;
ngx_http_handler_pt *h;
ngx_http_module_t *module;
- ngx_http_core_loc_conf_t *lcf, **plcf;
+ ngx_http_core_loc_conf_t *lcf, **lcfp;
ngx_http_core_srv_conf_t *scf;
r->connection->unexpected_eof = 0;
- r->keepalive = 0;
+ r->keepalive = 1;
if (r->headers_in.content_length_n > 0) {
r->lingering_close = 1;
@@ -279,23 +290,23 @@
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;
+ lcfp = (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);
+ngx_log_debug(r->connection->log, "trans: %s" _ lcfp[i]->name.data);
#endif
- if (r->uri.len < plcf[i]->name.len) {
+ if (r->uri.len < lcfp[i]->name.len) {
continue;
}
- rc = ngx_rstrncmp(r->uri.data, plcf[i]->name.data, plcf[i]->name.len);
+ rc = ngx_rstrncmp(r->uri.data, lcfp[i]->name.data, lcfp[i]->name.len);
if (rc < 0) {
break;
}
if (rc == 0) {
- r->loc_conf = plcf[i]->loc_conf;
+ r->loc_conf = lcfp[i]->loc_conf;
}
}
@@ -587,7 +598,8 @@
r->uri.len = uri.len;
r->uri.data = uri.data;
- /* NEEDED ? */
+ /* BROKEN, NEEDED ? */
+ /* r->exten */
r->uri_start = uri.data;
r->uri_end = uri.data + uri.len;
/**/
@@ -611,28 +623,28 @@
static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy)
{
- int i, j;
- char *rv;
- ngx_http_module_t *module;
- ngx_conf_t pcf;
- ngx_http_conf_ctx_t *ctx, *tctx, *pctx;
- ngx_http_core_srv_conf_t *scf;
- ngx_http_core_loc_conf_t **plcf;
+ int i, j;
+ char *rv;
+ ngx_http_module_t *module;
+ ngx_conf_t pcf;
+ ngx_http_conf_ctx_t *ctx, *hctx, *pctx;
+ ngx_http_core_main_conf_t *cmcf;
+ ngx_http_core_srv_conf_t *cscf, **cscfp;
ngx_test_null(ctx,
ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)),
NGX_CONF_ERROR);
- tctx = (ngx_http_conf_ctx_t *) cf->ctx;
- ctx->main_conf = tctx->main_conf;
+ hctx = (ngx_http_conf_ctx_t *) cf->ctx;
+ ctx->main_conf = hctx->main_conf;
- /* server configuration */
+ /* the server{}'s srv_conf */
ngx_test_null(ctx->srv_conf,
ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
NGX_CONF_ERROR);
- /* server location configuration */
+ /* the server{}'s loc_conf */
ngx_test_null(ctx->loc_conf,
ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
@@ -658,6 +670,17 @@
}
}
+ /* create links of the srv_conf's */
+
+ cscf = ctx->srv_conf[ngx_http_core_module_ctx.index];
+ cscf->ctx = ctx;
+
+ cmcf = ctx->main_conf[ngx_http_core_module_ctx.index];
+ ngx_test_null(cscfp, ngx_push_array(&cmcf->servers), NGX_CONF_ERROR);
+ *cscfp = cscf;
+
+ /* parse inside server{} */
+
pcf = *cf;
pctx = cf->ctx;
cf->ctx = ctx;
@@ -665,50 +688,7 @@
rv = ngx_conf_parse(cf, NULL);
*cf = pcf;
- if (rv != NGX_CONF_OK)
- return rv;
-
-
- scf = ctx->srv_conf[ngx_http_core_module_ctx.index];
- scf->ctx = ctx;
-
- plcf = (ngx_http_core_loc_conf_t **)scf->locations.elts;
-
- for (i = 0; ngx_modules[i]; i++) {
- if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) {
- continue;
- }
-
- module = (ngx_http_module_t *) ngx_modules[i]->ctx;
-
- if (module->init_srv_conf) {
- if (module->init_srv_conf(cf->pool,
- ctx->srv_conf[module->index])
- == NGX_CONF_ERROR) {
- return NGX_CONF_ERROR;
- }
- }
-
- if (module->merge_loc_conf) {
- rv = module->merge_loc_conf(cf->pool,
- pctx->loc_conf[module->index],
- ctx->loc_conf[module->index]);
- if (rv != NGX_CONF_OK) {
- return rv;
- }
-
- for (j = 0; j < scf->locations.nelts; j++) {
- rv = module->merge_loc_conf(cf->pool,
- ctx->loc_conf[module->index],
- plcf[j]->loc_conf[module->index]);
- if (rv != NGX_CONF_OK) {
- return rv;
- }
- }
- }
- }
-
- return NGX_CONF_OK;
+ return rv;
}
@@ -720,14 +700,15 @@
ngx_http_module_t *module;
ngx_conf_t pcf;
ngx_http_conf_ctx_t *ctx, *pctx;
- ngx_http_core_srv_conf_t *scf;
- ngx_http_core_loc_conf_t *lcf, **plcf;
+ ngx_http_core_srv_conf_t *cscf;
+ ngx_http_core_loc_conf_t *clcf, **clcfp;
ngx_test_null(ctx,
ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)),
NGX_CONF_ERROR);
pctx = (ngx_http_conf_ctx_t *) cf->ctx;
+ ctx->main_conf = pctx->main_conf;
ctx->srv_conf = pctx->srv_conf;
ngx_test_null(ctx->loc_conf,
@@ -748,17 +729,15 @@
}
}
- lcf = (ngx_http_core_loc_conf_t *)
- ctx->loc_conf[ngx_http_core_module_ctx.index];
+ clcf = 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;
+ clcf->name.len = location[1].len;
+ clcf->name.data = location[1].data;
+ clcf->loc_conf = ctx->loc_conf;
- scf = (ngx_http_core_srv_conf_t *)
- ctx->srv_conf[ngx_http_core_module_ctx.index];
- ngx_test_null(plcf, ngx_push_array(&scf->locations), NGX_CONF_ERROR);
- *plcf = lcf;
+ cscf = ctx->srv_conf[ngx_http_core_module_ctx.index];
+ ngx_test_null(clcfp, ngx_push_array(&cscf->locations), NGX_CONF_ERROR);
+ *clcfp = clcf;
pcf = *cf;
cf->ctx = ctx;
@@ -821,43 +800,81 @@
}
-static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool)
+static void *ngx_http_core_create_main_conf(ngx_pool_t *pool)
{
- ngx_http_core_srv_conf_t *scf, **cf;
+ ngx_http_core_main_conf_t *cmcf;
- ngx_test_null(scf,
- ngx_pcalloc(pool, sizeof(ngx_http_core_srv_conf_t)),
+ ngx_test_null(cmcf,
+ ngx_palloc(pool, sizeof(ngx_http_core_main_conf_t)),
NGX_CONF_ERROR);
- ngx_init_array(scf->locations, pool, 5, sizeof(void *), NGX_CONF_ERROR);
- ngx_init_array(scf->listen, pool, 5, sizeof(ngx_http_listen_t),
- NGX_CONF_ERROR);
- ngx_init_array(scf->server_names, pool, 5, sizeof(ngx_http_server_name_t),
+ cmcf->post_accept_timeout = NGX_CONF_UNSET;
+ cmcf->connection_pool_size = NGX_CONF_UNSET;
+ cmcf->request_pool_size = NGX_CONF_UNSET;
+ cmcf->client_header_timeout = NGX_CONF_UNSET;
+ cmcf->client_header_buffer_size = NGX_CONF_UNSET;
+ cmcf->large_client_header = NGX_CONF_UNSET;
+
+ ngx_init_array(cmcf->servers, pool, 5, sizeof(ngx_http_core_srv_conf_t *),
NGX_CONF_ERROR);
- ngx_test_null(cf, ngx_push_array(&ngx_http_servers), NGX_CONF_ERROR);
- *cf = scf;
-
- return scf;
+ return cmcf;
}
-static char *ngx_http_core_init_srv_conf(ngx_pool_t *pool, void *conf)
+static char *ngx_http_core_init_main_conf(ngx_pool_t *pool, void *conf)
{
- ngx_http_core_srv_conf_t *scf = (ngx_http_core_srv_conf_t *) conf;
+ ngx_http_core_main_conf_t *cmcf = (ngx_http_core_main_conf_t *) conf;
+
+ ngx_conf_init_msec_value(cmcf->post_accept_timeout, 30000);
+ ngx_conf_init_size_value(cmcf->connection_pool_size, 16384);
+ ngx_conf_init_size_value(cmcf->request_pool_size, 16384);
+ ngx_conf_init_msec_value(cmcf->client_header_timeout, 60000);
+ ngx_conf_init_size_value(cmcf->client_header_buffer_size, 1024);
+ ngx_conf_init_value(cmcf->large_client_header, 1);
+
+ return NGX_CONF_OK;
+}
+
+
+static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool)
+{
+ ngx_http_core_srv_conf_t *cscf;
+
+ ngx_test_null(cscf,
+ ngx_pcalloc(pool, sizeof(ngx_http_core_srv_conf_t)),
+ NGX_CONF_ERROR);
+
+ ngx_init_array(cscf->locations, pool, 5, sizeof(void *), NGX_CONF_ERROR);
+ ngx_init_array(cscf->listen, pool, 5, sizeof(ngx_http_listen_t),
+ NGX_CONF_ERROR);
+ ngx_init_array(cscf->server_names, pool, 5, sizeof(ngx_http_server_name_t),
+ NGX_CONF_ERROR);
+
+ return cscf;
+}
+
+
+static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool,
+ void *parent, void *child)
+{
+ ngx_http_core_srv_conf_t *prev = (ngx_http_core_srv_conf_t *) parent;
+ ngx_http_core_srv_conf_t *conf = (ngx_http_core_srv_conf_t *) child;
ngx_http_listen_t *l;
ngx_http_server_name_t *n;
- if (scf->listen.nelts == 0) {
- ngx_test_null(l, ngx_push_array(&scf->listen), NGX_CONF_ERROR);
+ /* TODO: it does not merge, it init only */
+
+ if (conf->listen.nelts == 0) {
+ ngx_test_null(l, ngx_push_array(&conf->listen), NGX_CONF_ERROR);
l->addr = INADDR_ANY;
l->port = 8000;
l->family = AF_INET;
}
- if (scf->server_names.nelts == 0) {
- ngx_test_null(n, ngx_push_array(&scf->server_names), NGX_CONF_ERROR);
+ if (conf->server_names.nelts == 0) {
+ ngx_test_null(n, ngx_push_array(&conf->server_names), NGX_CONF_ERROR);
ngx_test_null(n->name.data, ngx_palloc(pool, NGX_MAXHOSTNAMELEN),
NGX_CONF_ERROR);
if (gethostname(n->name.data, NGX_MAXHOSTNAMELEN) == -1) {
@@ -959,15 +976,16 @@
}
}
- ngx_conf_merge(conf->sendfile, prev->sendfile, 0);
+ ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
- ngx_conf_msec_merge(conf->send_timeout, prev->send_timeout, 10000);
+ ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 10000);
- ngx_conf_size_merge(conf->discarded_buffer_size,
- prev->discarded_buffer_size, 1500);
-
- ngx_conf_msec_merge(conf->lingering_time, prev->lingering_time, 30000);
- ngx_conf_msec_merge(conf->lingering_timeout, prev->lingering_timeout, 5000);
+ ngx_conf_merge_size_value(conf->discarded_buffer_size,
+ prev->discarded_buffer_size, 1500);
+ ngx_conf_merge_msec_value(conf->lingering_time, prev->lingering_time,
+ 30000);
+ ngx_conf_merge_msec_value(conf->lingering_timeout, prev->lingering_timeout,
+ 5000);
return NGX_CONF_OK;
}
@@ -975,11 +993,12 @@
static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, char *conf)
{
+ ngx_http_core_srv_conf_t *scf = (ngx_http_core_srv_conf_t *) conf;
+
uint p;
char *addr;
ngx_str_t *args;
ngx_http_listen_t *ls;
- ngx_http_core_srv_conf_t *scf = (ngx_http_core_srv_conf_t *) conf;
/* TODO: check duplicate 'listen' directives */
@@ -1001,7 +1020,8 @@
ls->addr = inet_addr(addr);
if (ls->addr == INADDR_NONE) {
- return "bad addr";
+ /* TODO: gethostbyname() */
+ return "can not resolve host name";
}
break;
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
index d44a86c..c6c86f2 100644
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -18,17 +18,27 @@
typedef struct {
+ int post_accept_timeout;
+ int connection_pool_size;
int request_pool_size;
+ int client_header_timeout;
int client_header_buffer_size;
+ int large_client_header;
+ int url_in_error_log;
+
+ ngx_array_t servers; /* array of ngx_http_core_srv_conf_t */
} ngx_http_core_main_conf_t;
typedef struct {
- ngx_array_t locations; /* array of ngx_http_core_loc_conf_t */
+ ngx_array_t locations; /* array of ngx_http_core_loc_conf_t,
+ used in the translation handler
+ and in the merge phase */
ngx_array_t listen; /* 'listen', array of ngx_http_listen_t */
ngx_array_t server_names; /* 'server_name',
array of ngx_http_server_name_t */
+
ngx_http_conf_ctx_t *ctx; /* server ctx */
} ngx_http_core_srv_conf_t;
@@ -78,8 +88,7 @@
typedef struct {
ngx_str_t name; /* location name */
- void **loc_conf; /* pointer to modules loc_conf,
- used in translation handler */
+ void **loc_conf ; /* pointer to the modules' loc_conf */
int (*handler) (ngx_http_request_t *r);
diff --git a/src/http/ngx_http_event.c b/src/http/ngx_http_event.c
index 94aa622..1b9110f 100644
--- a/src/http/ngx_http_event.c
+++ b/src/http/ngx_http_event.c
@@ -137,15 +137,19 @@
static void ngx_http_init_request(ngx_event_t *rev)
{
- ngx_connection_t *c;
- ngx_http_request_t *r;
- ngx_http_conf_ctx_t *ctx;
+ ngx_connection_t *c;
+ ngx_http_request_t *r;
+ ngx_http_conf_ctx_t *ctx;
+ ngx_http_core_main_conf_t *cmcf;
- c = (ngx_connection_t *) rev->data;
+ c = rev->data;
+ ctx = c->ctx;
+
+ cmcf = ngx_http_get_module_main_conf(ctx, ngx_http_core_module_ctx);
if (c->buffer == NULL) {
c->buffer = ngx_create_temp_hunk(c->pool,
- ngx_http_client_header_buffer_size,
+ cmcf->client_header_buffer_size,
0, 0);
if (c->buffer == NULL) {
ngx_http_close_connection(c);
@@ -159,7 +163,7 @@
return;
}
- r->pool = ngx_create_pool(ngx_http_request_pool_size, c->log);
+ r->pool = ngx_create_pool(cmcf->request_pool_size, c->log);
if (r->pool == NULL) {
ngx_http_close_connection(c);
return;
@@ -179,7 +183,7 @@
return;
}
- ctx = (ngx_http_conf_ctx_t *) c->ctx;
+ r->main_conf = ctx->main_conf;
r->srv_conf = ctx->srv_conf;
r->loc_conf = ctx->loc_conf;
@@ -202,14 +206,15 @@
static void ngx_http_process_request_line(ngx_event_t *rev)
{
- int rc, offset;
- ssize_t n;
- ngx_connection_t *c;
- ngx_http_request_t *r;
- ngx_http_log_ctx_t *lcx;
+ int rc, offset;
+ ssize_t n;
+ ngx_connection_t *c;
+ ngx_http_request_t *r;
+ ngx_http_log_ctx_t *lcx;
+ ngx_http_core_main_conf_t *cmcf;
- c = (ngx_connection_t *) rev->data;
- r = (ngx_http_request_t *) c->data;
+ c = rev->data;
+ r = c->data;
ngx_log_debug(rev->log, "http process request line");
@@ -231,8 +236,10 @@
/* the request line has been parsed successfully */
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module_ctx);
+
if (r->http_version >= NGX_HTTP_VERSION_10
- && ngx_http_large_client_header == 0
+ && cmcf->large_client_header == 0
&& r->header_in->pos == r->header_in->end)
{
/* no space for "\r\n" at the end of the header */
@@ -259,12 +266,29 @@
ngx_cpystrn(r->uri.data, r->uri_start, r->uri.len + 1);
+#if 1 /* needed to log url on errors in proxy only ? */
+
+ /* copy unparsed URI */
+
+ r->unparsed_uri.len = r->uri_end - r->uri_start;
+ r->unparsed_uri.data = ngx_palloc(r->pool, r->unparsed_uri.len + 1);
+ if (r->unparsed_uri.data == NULL) {
+ ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
+ ngx_http_close_connection(c);
+ return;
+ }
+
+ ngx_cpystrn(r->unparsed_uri.data, r->uri_start,
+ r->unparsed_uri.len + 1);
+
+#endif
+
r->request_line.len = r->request_end - r->request_start;
/* if the large client headers are enabled then
we need to copy a request line */
- if (ngx_http_large_client_header) {
+ if (cmcf->large_client_header) {
r->request_line.data = ngx_palloc(r->pool, r->request_line.len + 1);
if (r->request_line.data == NULL) {
@@ -325,19 +349,6 @@
if (r->args.data[0] == '\0') { r->args.data = NULL; }
#endif
- lcx = c->log->data;
-
- if (ngx_http_url_in_error_log) {
- lcx->url = ngx_palloc(r->pool, r->uri_end - r->uri_start + 1);
- if (lcx->url == NULL) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- ngx_http_close_connection(c);
- return;
- }
-
- ngx_cpystrn(lcx->url, r->uri_start, r->uri_end - r->uri_start + 1);
- }
-
if (r->http_version == NGX_HTTP_VERSION_9) {
if (ngx_http_find_server_conf(r) == NGX_ERROR) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
@@ -350,10 +361,12 @@
return;
}
+ lcx = c->log->data;
lcx->action = "reading client request headers";
+ lcx->url = r->unparsed_uri.data;
r->headers_in.headers = ngx_create_table(r->pool, 10);
- if (ngx_http_large_client_header
+ if (cmcf->large_client_header
&& r->header_in->pos == r->header_in->last)
{
r->header_in->pos = r->header_in->last = r->header_in->start;
@@ -384,7 +397,9 @@
are enabled otherwise a request line had been already copied
to the start of the r->header_in hunk in ngx_http_set_keepalive() */
- if (ngx_http_large_client_header) {
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module_ctx);
+
+ if (cmcf->large_client_header) {
offset = r->request_start - r->header_in->start;
if (offset == 0) {
@@ -422,16 +437,17 @@
static void ngx_http_process_request_headers(ngx_event_t *rev)
{
- int rc, i, offset;
- size_t len;
- ssize_t n;
- ngx_table_elt_t *h;
- ngx_connection_t *c;
- ngx_http_request_t *r;
- ngx_http_log_ctx_t *ctx;
+ int rc, i, offset;
+ size_t len;
+ ssize_t n;
+ ngx_table_elt_t *h;
+ ngx_connection_t *c;
+ ngx_http_request_t *r;
+ ngx_http_log_ctx_t *ctx;
+ ngx_http_core_main_conf_t *cmcf;
- c = (ngx_connection_t *) rev->data;
- r = (ngx_http_request_t *) c->data;
+ c = rev->data;
+ r = c->data;
ngx_log_debug(rev->log, "http process request header line");
@@ -471,7 +487,9 @@
/* if the large client headers are enabled then
we need to copy the header name and value */
- if (ngx_http_large_client_header) {
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module_ctx);
+
+ if (cmcf->large_client_header) {
h->key.data = ngx_palloc(r->pool,
h->key.len + 1 + h->value.len + 1);
if (h->key.data == NULL) {
@@ -505,7 +523,7 @@
ngx_log_debug(r->connection->log, "HTTP header: '%s: %s'" _
h->key.data _ h->value.data);
- if (ngx_http_large_client_header
+ if (cmcf->large_client_header
&& r->header_in->pos == r->header_in->last)
{
r->header_in->pos = r->header_in->last = r->header_in->start;
@@ -574,7 +592,9 @@
/* if the large client headers are enabled then
we need to compact r->header_in hunk */
- if (ngx_http_large_client_header) {
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module_ctx);
+
+ if (cmcf->large_client_header) {
offset = r->header_name_start - r->header_in->start;
if (offset == 0) {
@@ -606,9 +626,10 @@
static ssize_t ngx_http_read_request_header(ngx_http_request_t *r)
{
- int event;
- ssize_t n;
- ngx_event_t *rev;
+ int event;
+ ssize_t n;
+ ngx_event_t *rev;
+ ngx_http_core_main_conf_t *cmcf;
n = r->header_in->last - r->header_in->pos;
@@ -629,7 +650,9 @@
rev->timer_set = 1;
}
- ngx_add_timer(rev, ngx_http_client_header_timeout);
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module_ctx);
+
+ ngx_add_timer(rev, cmcf->client_header_timeout);
r->header_timeout_set = 1;
}
@@ -724,7 +747,7 @@
{
int event;
ngx_event_t *wev;
- ngx_http_core_loc_conf_t *lcf;
+ ngx_http_core_loc_conf_t *clcf;
wev = r->connection->write;
wev->event_handler = ngx_http_writer;
@@ -733,10 +756,10 @@
return;
}
- lcf = (ngx_http_core_loc_conf_t *)
+ clcf = (ngx_http_core_loc_conf_t *)
ngx_http_get_module_loc_conf(r->main ? r->main : r,
ngx_http_core_module_ctx);
- ngx_add_timer(wev, lcf->send_timeout);
+ ngx_add_timer(wev, clcf->send_timeout);
wev->timer_set = 1;
if (ngx_event_flags & (NGX_HAVE_AIO_EVENT|NGX_HAVE_EDGE_EVENT)) {
@@ -747,7 +770,7 @@
#if (HAVE_LOWAT_EVENT) /* kqueue's NOTE_LOWAT */
if (ngx_event_flags & NGX_HAVE_LOWAT_EVENT) {
- wev->lowat = lcf->send_lowat;
+ wev->lowat = clcf->send_lowat;
}
#endif
@@ -823,9 +846,8 @@
if (r->keepalive != 0) {
ngx_http_set_keepalive(r);
- }
- if (r->lingering_close) {
+ } else if (r->lingering_close) {
ngx_http_set_lingering_close(r);
} else {
@@ -970,11 +992,12 @@
static void ngx_http_set_keepalive(ngx_http_request_t *r)
{
- int len, blocked;
- ngx_hunk_t *h;
- ngx_event_t *rev, *wev;
- ngx_connection_t *c;
- ngx_http_log_ctx_t *ctx;
+ int len, blocked;
+ ngx_hunk_t *h;
+ ngx_event_t *rev, *wev;
+ ngx_connection_t *c;
+ ngx_http_log_ctx_t *ctx;
+ ngx_http_core_main_conf_t *cmcf;
c = (ngx_connection_t *) r->connection;
rev = c->read;
@@ -1007,7 +1030,9 @@
This copy should be rare because clients that support
pipelined requests (Mozilla 1.x, Opera 6.x) are still rare */
- if (!ngx_http_large_client_header) {
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module_ctx);
+
+ if (!cmcf->large_client_header) {
len = h->last - h->pos;
ngx_memcpy(h->start, h->pos, len);
h->pos = h->start;
diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c
index 926a286..3ad260e 100644
--- a/src/http/ngx_http_header_filter.c
+++ b/src/http/ngx_http_header_filter.c
@@ -18,14 +18,17 @@
static int ngx_http_header_filter(ngx_http_request_t *r);
-ngx_http_module_t ngx_http_header_filter_module_ctx = {
- NULL, /* create server config */
- NULL, /* init server config */
+static ngx_http_module_t ngx_http_header_filter_module_ctx = {
+ NGX_HTTP_MODULE,
- NULL, /* create location config */
- NULL, /* merge location config */
+ NULL, /* create main configuration */
+ NULL, /* init main configuration */
- NULL /* init filters */
+ NULL, /* create server configuration */
+ NULL, /* merge server configuration */
+
+ NULL, /* create location configuration */
+ NULL, /* merge location configuration */
};
diff --git a/src/http/ngx_http_output_filter.c b/src/http/ngx_http_output_filter.c
index 738c383..53c32e1 100644
--- a/src/http/ngx_http_output_filter.c
+++ b/src/http/ngx_http_output_filter.c
@@ -23,7 +23,7 @@
static ngx_command_t ngx_http_output_filter_commands[] = {
{ngx_string("output_buffer"),
- NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_output_filter_conf_t, hunk_size),
@@ -36,11 +36,14 @@
static ngx_http_module_t ngx_http_output_filter_module_ctx = {
NGX_HTTP_MODULE,
- NULL, /* create server config */
- NULL, /* init server config */
+ NULL, /* create main configuration */
+ NULL, /* init main configuration */
- ngx_http_output_filter_create_conf, /* create location config */
- ngx_http_output_filter_merge_conf /* merge location config */
+ NULL, /* create server configuration */
+ NULL, /* merge server configuration */
+
+ ngx_http_output_filter_create_conf, /* create location configuration */
+ ngx_http_output_filter_merge_conf /* merge location configuration */
};
@@ -336,7 +339,7 @@
ngx_http_output_filter_conf_t *conf =
(ngx_http_output_filter_conf_t *) child;
- ngx_conf_size_merge(conf->hunk_size, prev->hunk_size, 32768);
+ ngx_conf_merge_size_value(conf->hunk_size, prev->hunk_size, 32768);
return NULL;
}
diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c
index 765da83..a7784a3 100644
--- a/src/http/ngx_http_parse.c
+++ b/src/http/ngx_http_parse.c
@@ -9,13 +9,24 @@
char *p;
enum {
sw_start = 0,
+ sw_G,
+ sw_GE,
+ sw_H,
+ sw_HE,
+ sw_HEA,
+ sw_P,
+ sw_PO,
+ sw_POS,
sw_space_after_method,
sw_spaces_before_uri,
sw_after_slash_in_uri,
sw_check_uri,
sw_uri,
sw_http_09,
- sw_http_version,
+ sw_http_H,
+ sw_http_HT,
+ sw_http_HTT,
+ sw_http_HTTP,
sw_first_major_digit,
sw_major_digit,
sw_first_minor_digit,
@@ -30,7 +41,7 @@
while (p < r->header_in->last && state < sw_done) {
ch = *p++;
- /* GCC 2.95.2 and VC 6.0 compile this switch as jump table */
+ /* gcc 2.95.2 and vc 6.0 compile this switch as an jump table */
switch (state) {
@@ -40,49 +51,100 @@
switch (ch) {
case 'G':
- if (p + 1 >= r->header_in->last) {
- return NGX_AGAIN;
- }
-
- if (*p != 'E' || *(p + 1) != 'T') {
- return NGX_HTTP_PARSE_INVALID_METHOD;
- }
-
- r->method = NGX_HTTP_GET;
- p += 2;
+ state = sw_G;
break;
-
case 'H':
- if (p + 2 >= r->header_in->last) {
- return NGX_AGAIN;
- }
-
- if (*p != 'E' || *(p + 1) != 'A' || *(p + 2) != 'D') {
- return NGX_HTTP_PARSE_INVALID_METHOD;
- }
-
- r->method = NGX_HTTP_HEAD;
- p += 3;
+ state = sw_H;
break;
-
case 'P':
- if (p + 2 >= r->header_in->last) {
- return NGX_AGAIN;
- }
-
- if (*p != 'O' || *(p + 1) != 'S' || *(p + 2) != 'T') {
- return NGX_HTTP_PARSE_INVALID_METHOD;
- }
-
- r->method = NGX_HTTP_POST;
- p += 3;
+ state = sw_P;
break;
-
default:
return NGX_HTTP_PARSE_INVALID_METHOD;
}
+ break;
- state = sw_space_after_method;
+ case sw_G:
+ switch (ch) {
+ case 'E':
+ state = sw_GE;
+ break;
+ default:
+ return NGX_HTTP_PARSE_INVALID_METHOD;
+ }
+ break;
+
+ case sw_GE:
+ switch (ch) {
+ case 'T':
+ r->method = NGX_HTTP_GET;
+ state = sw_space_after_method;
+ break;
+ default:
+ return NGX_HTTP_PARSE_INVALID_METHOD;
+ }
+ break;
+
+ case sw_H:
+ switch (ch) {
+ case 'E':
+ state = sw_HE;
+ break;
+ default:
+ return NGX_HTTP_PARSE_INVALID_METHOD;
+ }
+ break;
+
+ case sw_HE:
+ switch (ch) {
+ case 'A':
+ state = sw_HEA;
+ break;
+ default:
+ return NGX_HTTP_PARSE_INVALID_METHOD;
+ }
+ break;
+
+ case sw_HEA:
+ switch (ch) {
+ case 'D':
+ r->method = NGX_HTTP_HEAD;
+ state = sw_space_after_method;
+ break;
+ default:
+ return NGX_HTTP_PARSE_INVALID_METHOD;
+ }
+ break;
+
+ case sw_P:
+ switch (ch) {
+ case 'O':
+ state = sw_PO;
+ break;
+ default:
+ return NGX_HTTP_PARSE_INVALID_METHOD;
+ }
+ break;
+
+ case sw_PO:
+ switch (ch) {
+ case 'S':
+ state = sw_POS;
+ break;
+ default:
+ return NGX_HTTP_PARSE_INVALID_METHOD;
+ }
+ break;
+
+ case sw_POS:
+ switch (ch) {
+ case 'T':
+ r->method = NGX_HTTP_POST;
+ state = sw_space_after_method;
+ break;
+ default:
+ return NGX_HTTP_PARSE_INVALID_METHOD;
+ }
break;
/* single space after method */
@@ -214,27 +276,51 @@
state = sw_done;
break;
case 'H':
- state = sw_http_version;
+ state = sw_http_H;
break;
default:
return NGX_HTTP_PARSE_INVALID_REQUEST;
}
break;
- /* "TTP/" */
- case sw_http_version:
- if (p + 2 >= r->header_in->last) {
- r->state = sw_http_version;
- r->header_in->pos = p - 1;
- return NGX_AGAIN;
- }
-
- if (ch != 'T' || *p != 'T' || *(p + 1) != 'P' || *(p + 2) != '/') {
+ case sw_http_H:
+ switch (ch) {
+ case 'T':
+ state = sw_http_HT;
+ break;
+ default:
return NGX_HTTP_PARSE_INVALID_REQUEST;
}
+ break;
- p += 3;
- state = sw_first_major_digit;
+ case sw_http_HT:
+ switch (ch) {
+ case 'T':
+ state = sw_http_HTT;
+ break;
+ default:
+ return NGX_HTTP_PARSE_INVALID_REQUEST;
+ }
+ break;
+
+ case sw_http_HTT:
+ switch (ch) {
+ case 'P':
+ state = sw_http_HTTP;
+ break;
+ default:
+ return NGX_HTTP_PARSE_INVALID_REQUEST;
+ }
+ break;
+
+ case sw_http_HTTP:
+ switch (ch) {
+ case '/':
+ state = sw_first_major_digit;
+ break;
+ default:
+ return NGX_HTTP_PARSE_INVALID_REQUEST;
+ }
break;
/* first digit of major HTTP version */
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
new file mode 100644
index 0000000..c77fa28
--- /dev/null
+++ b/src/http/ngx_http_request.h
@@ -0,0 +1,205 @@
+#ifndef _NGX_HTTP_REQUEST_H_INCLUDED_
+#define _NGX_HTTP_REQUEST_H_INCLUDED_
+
+
+#if 0
+#include <ngx_config.h>
+
+#include <ngx_types.h>
+#include <ngx_string.h>
+#include <ngx_table.h>
+#include <ngx_hunk.h>
+#include <ngx_files.h>
+#include <ngx_connection.h>
+#include <ngx_conf_file.h>
+
+#endif
+
+
+#define NGX_HTTP_VERSION_9 9
+#define NGX_HTTP_VERSION_10 1000
+#define NGX_HTTP_VERSION_11 1001
+
+#define NGX_HTTP_GET 1
+#define NGX_HTTP_HEAD 2
+#define NGX_HTTP_POST 3
+
+#define NGX_HTTP_CONN_CLOSE 0
+#define NGX_HTTP_CONN_KEEP_ALIVE 1
+
+
+#define NGX_HTTP_PARSE_HEADER_DONE 1
+#define NGX_HTTP_PARSE_INVALID_METHOD 10
+#define NGX_HTTP_PARSE_INVALID_REQUEST 11
+#define NGX_HTTP_PARSE_TOO_LONG_URI 12
+#define NGX_HTTP_PARSE_INVALID_09_METHOD 13
+#define NGX_HTTP_PARSE_INVALID_HEADER 14
+#define NGX_HTTP_PARSE_TOO_LONG_HEADER 15
+#define NGX_HTTP_PARSE_NO_HOST_HEADER 16
+#define NGX_HTTP_PARSE_INVALID_CL_HEADER 17
+
+
+#define NGX_HTTP_OK 200
+
+#define NGX_HTTP_SPECIAL_RESPONSE 300
+#define NGX_HTTP_MOVED_PERMANENTLY 301
+#define NGX_HTTP_MOVED_TEMPORARILY 302
+#define NGX_HTTP_NOT_MODIFIED 304
+
+#define NGX_HTTP_BAD_REQUEST 400
+#define NGX_HTTP_FORBIDDEN 403
+#define NGX_HTTP_NOT_FOUND 404
+#define NGX_HTTP_REQUEST_TIME_OUT 408
+#define NGX_HTTP_REQUEST_URI_TOO_LARGE 414
+
+#define NGX_HTTP_INTERNAL_SERVER_ERROR 500
+#define NGX_HTTP_NOT_IMPLEMENTED 501
+#define NGX_HTTP_BAD_GATEWAY 502
+#define NGX_HTTP_SERVICE_UNAVAILABLE 503
+#define NGX_HTTP_GATEWAY_TIME_OUT 504
+
+
+
+#define NGX_HTTP_STATIC_HANDLER 0
+#define NGX_HTTP_DIRECTORY_HANDLER 1
+
+
+typedef struct {
+ ngx_str_t name;
+ int offset;
+} ngx_http_header_t;
+
+
+typedef struct {
+ size_t host_name_len;
+ ssize_t content_length_n;
+
+ ngx_table_elt_t *host;
+ ngx_table_elt_t *connection;
+ ngx_table_elt_t *if_modified_since;
+ ngx_table_elt_t *content_length;
+ ngx_table_elt_t *accept_encoding;
+
+ ngx_table_elt_t *user_agent;
+
+ ngx_table_t *headers;
+} ngx_http_headers_in_t;
+
+
+typedef struct {
+ ngx_chain_t chain[4];
+ ngx_hunk_t *header_out;
+ ngx_hunk_t *hunk;
+ ngx_hunk_t *file_hunk;
+ ngx_file_t temp_file;
+ ngx_path_t *temp_path;
+ off_t offset;
+ char *header_in_pos;
+} ngx_http_request_body_t;
+
+
+typedef struct {
+ int status;
+ ngx_str_t status_line;
+
+ ngx_table_elt_t *server;
+ ngx_table_elt_t *date;
+ ngx_table_elt_t *content_type;
+ ngx_table_elt_t *location;
+ ngx_table_elt_t *last_modified;
+
+ ngx_table_t *headers;
+
+ off_t content_length;
+ char *charset;
+ char *etag;
+ time_t date_time;
+ time_t last_modified_time;
+} ngx_http_headers_out_t;
+
+
+typedef struct ngx_http_request_s ngx_http_request_t;
+
+struct ngx_http_request_s {
+ ngx_connection_t *connection;
+
+ void **ctx;
+ void **main_conf;
+ void **srv_conf;
+ void **loc_conf;
+
+ ngx_file_t file;
+
+ ngx_pool_t *pool;
+ ngx_hunk_t *header_in;
+ ngx_http_request_body_t *request_body;
+
+ ngx_http_headers_in_t headers_in;
+ ngx_http_headers_out_t headers_out;
+
+ int (*handler)(ngx_http_request_t *r);
+
+ time_t lingering_time;
+
+ int method;
+ int http_version;
+ int http_major;
+ int http_minor;
+
+ ngx_str_t request_line;
+ ngx_str_t uri;
+ ngx_str_t args;
+ ngx_str_t exten;
+ ngx_str_t unparsed_uri;
+
+ ngx_http_request_t *main;
+
+ u_int in_addr;
+
+ int port;
+ ngx_str_t port_name;
+
+ int filter;
+
+ char *discarded_buffer;
+
+ ngx_str_t path;
+ int path_err;
+
+ unsigned proxy:1;
+ unsigned cachable:1;
+ unsigned pipeline:1;
+ unsigned keepalive:1;
+ unsigned lingering_close:1;
+
+ unsigned header_read:1;
+ unsigned header_timeout_set:1;
+
+ unsigned logging:1;
+
+ unsigned header_only:1;
+ unsigned unusual_uri:1; /* URI is not started with '/' - "GET http://" */
+ unsigned complex_uri:1; /* URI with "/." or with "//" (WIN32) */
+ unsigned path_not_found:1;
+#ifdef NGX_EVENT
+ unsigned write_level_event:1;
+#endif
+
+ int state;
+ char *uri_start;
+ char *uri_end;
+ char *uri_ext;
+ char *args_start;
+ char *request_start;
+ char *request_end;
+ char *header_name_start;
+ char *header_name_end;
+ char *header_start;
+ char *header_end;
+#ifdef NGX_EVENT
+ int (*state_handler)(ngx_http_request_t *r);
+#endif
+};
+
+
+#endif /* _NGX_HTTP_REQUEST_H_INCLUDED_ */
diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c
index 31303d4..81cf19c 100644
--- a/src/http/ngx_http_write_filter.c
+++ b/src/http/ngx_http_write_filter.c
@@ -35,11 +35,14 @@
ngx_http_module_t ngx_http_write_filter_module_ctx = {
NGX_HTTP_MODULE,
- NULL, /* create server config */
- NULL, /* init server config */
+ NULL, /* create main configuration */
+ NULL, /* init main configuration */
- ngx_http_write_filter_create_conf, /* create location config */
- ngx_http_write_filter_merge_conf /* merge location config */
+ NULL, /* create server configuration */
+ NULL, /* merge server configuration */
+
+ ngx_http_write_filter_create_conf, /* create location configuration */
+ ngx_http_write_filter_merge_conf /* merge location configuration */
};
@@ -61,9 +64,9 @@
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_ctx);
+ ctx = ngx_http_get_module_ctx(r->main ? r->main : r,
+ ngx_http_write_filter_module_ctx);
+
if (ctx == NULL) {
ngx_http_create_ctx(r, ctx, ngx_http_write_filter_module_ctx,
sizeof(ngx_http_write_filter_ctx_t), NGX_ERROR);
@@ -118,9 +121,8 @@
}
}
- conf = (ngx_http_write_filter_conf_t *)
- ngx_http_get_module_loc_conf(r->main ? r->main : r,
- ngx_http_write_filter_module_ctx);
+ conf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
+ ngx_http_write_filter_module_ctx);
#if (NGX_DEBUG_WRITE_FILTER)
ngx_log_debug(r->connection->log,
@@ -139,7 +141,11 @@
return NGX_AGAIN;
}
+#if 1
+ chain = ngx_write_chain(r->connection, ctx->out);
+#else
chain = ngx_write_chain(r->connection, ctx->out, flush);
+#endif
#if (NGX_DEBUG_WRITE_FILTER)
ngx_log_debug(r->connection->log, "write filter %x" _ chain);
@@ -177,12 +183,10 @@
static char *ngx_http_write_filter_merge_conf(ngx_pool_t *pool,
void *parent, void *child)
{
- ngx_http_write_filter_conf_t *prev =
- (ngx_http_write_filter_conf_t *) parent;
- ngx_http_write_filter_conf_t *conf =
- (ngx_http_write_filter_conf_t *) child;
+ ngx_http_write_filter_conf_t *prev = parent;
+ ngx_http_write_filter_conf_t *conf = child;
- ngx_conf_size_merge(conf->buffer_output, prev->buffer_output, 1460);
+ ngx_conf_merge_size_value(conf->buffer_output, prev->buffer_output, 1460);
return NULL;
}