Mercurial > hg > nginx-quic
changeset 336:ca9a7f8c86da
nginx-0.0.3-2004-05-18-19:29:08 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 18 May 2004 15:29:08 +0000 |
parents | d4241d7787fe |
children | 4feff829a849 |
files | auto/modules auto/sources src/core/ngx_conf_file.c src/core/ngx_conf_file.h src/core/ngx_cycle.c src/core/ngx_cycle.h src/http/modules/ngx_http_chunked_filter.c src/http/modules/proxy/ngx_http_proxy_handler.c src/http/modules/proxy/ngx_http_proxy_handler.h src/http/modules/proxy/ngx_http_proxy_header.c src/os/unix/ngx_files.h src/os/win32/ngx_files.h |
diffstat | 12 files changed, 140 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/auto/modules +++ b/auto/modules @@ -77,6 +77,9 @@ if [ $HTTP_PROXY = YES ]; then HTTP_SRCS="$HTTP_SRCS $HTTP_PROXY_SRCS" fi +if [ -r $OBJS/auto ]; then + . $OBJS/auto +fi modules="$CORE_MODULES $EVENT_MODULES $HTTP_MODULES $HTTP_FILTER_MODULES \ $HTTP_HEADERS_FILTER_MODULE \
--- a/auto/sources +++ b/auto/sources @@ -1,5 +1,5 @@ -CORE_MODULES="ngx_core_module ngx_errlog_module" +CORE_MODULES="ngx_core_module ngx_errlog_module ngx_conf_module" CORE_INCS="src/core"
--- a/src/core/ngx_conf_file.c +++ b/src/core/ngx_conf_file.c @@ -3,7 +3,34 @@ #include <ngx_core.h> -/* Ten fixed arguments */ +static char *ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); + + +static ngx_command_t ngx_conf_commands[] = { + + { ngx_string("include"), + NGX_ANY_CONF|NGX_CONF_TAKE1, + ngx_conf_include, + 0, + 0, + NULL }, + + ngx_null_command +}; + + +ngx_module_t ngx_conf_module = { + NGX_MODULE, + NULL, /* module context */ + ngx_conf_commands, /* module directives */ + NGX_CONF_MODULE, /* module type */ + NULL, /* init module */ + NULL /* init child */ +}; + + + +/* The ten fixed arguments */ static int argument_number[] = { NGX_CONF_NOARGS, @@ -513,6 +540,27 @@ ngx_log_debug(cf->log, "FOUND %d:'%s'" _ } +static char *ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +{ + ngx_str_t *value, file; + + value = cf->args->elts; + + file.len = cf->cycle->root.len + value[1].len; + if (!(file.data = ngx_palloc(cf->pool, file.len + 1))) { + return NGX_CONF_ERROR; + } + + ngx_cpystrn(ngx_cpymem(file.data, cf->cycle->root.data, + cf->cycle->root.len), + value[1].data, value[1].len + 1); + + ngx_log_error(NGX_LOG_INFO, cf->log, 0, "include %s", file.data); + + return ngx_conf_parse(cf, &file); +} + + ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name) { ngx_uint_t i;
--- a/src/core/ngx_conf_file.h +++ b/src/core/ngx_conf_file.h @@ -37,7 +37,9 @@ #define NGX_CONF_2MORE 0x00001000 #define NGX_DIRECT_CONF 0x00010000 + #define NGX_MAIN_CONF 0x01000000 +#define NGX_ANY_CONF 0x0F000000
--- a/src/core/ngx_cycle.c +++ b/src/core/ngx_cycle.c @@ -24,6 +24,7 @@ static ngx_connection_t dumb; ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) { void *rv; + u_char *root; ngx_uint_t i, n, failed; ngx_log_t *log; ngx_conf_t conf; @@ -33,6 +34,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t ngx_open_file_t *file; ngx_listening_t *ls, *nls; ngx_core_module_t *module; + char cwd[NGX_MAX_PATH + 1]; log = old_cycle->log; @@ -51,6 +53,42 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t cycle->conf_file = old_cycle->conf_file; + for (i = cycle->conf_file.len; i > 0; i--) { + if (cycle->conf_file.data[i] == '/') { + break; + } + } + + if (i == 0 && cycle->conf_file.data[i] != '/') { + if (ngx_getcwd(cwd, NGX_MAX_PATH) == 0) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, + ngx_getcwd_n " failed"); + ngx_destroy_pool(pool); + return NULL; + } + + for ( /* void */; i < NGX_MAX_PATH && cwd[i]; i++) /* void */; + cwd[i] = '/'; + cwd[i + 1] = '\0'; + + root = (u_char *) cwd; + + } else { + root = cycle->conf_file.data; + } + + cycle->root.len = ++i; + cycle->root.data = ngx_palloc(pool, ++i); + if (cycle->root.data == NULL) { + ngx_destroy_pool(pool); + return NULL; + } + + ngx_cpystrn(cycle->root.data, root, i); + + ngx_log_error(NGX_LOG_INFO, log, 0, "root: %s", cycle->root.data); + + n = old_cycle->pathes.nelts ? old_cycle->pathes.nelts : 10; if (!(cycle->pathes.elts = ngx_pcalloc(pool, n * sizeof(ngx_path_t *)))) { ngx_destroy_pool(pool);
--- a/src/core/ngx_cycle.h +++ b/src/core/ngx_cycle.h @@ -25,6 +25,7 @@ struct ngx_cycle_s { ngx_cycle_t *old_cycle; ngx_str_t conf_file; + ngx_str_t root; };
--- a/src/http/modules/ngx_http_chunked_filter.c +++ b/src/http/modules/ngx_http_chunked_filter.c @@ -66,12 +66,16 @@ static int ngx_http_chunked_body_filter( } ngx_test_null(out, ngx_alloc_chain_link(r->pool), NGX_ERROR); + out->hunk = NULL; ll = &out->next; size = 0; cl = in; for ( ;; ) { + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http chunk: %d", ngx_hunk_size(cl->hunk)); + size += ngx_hunk_size(cl->hunk); ngx_test_null(tl, ngx_alloc_chain_link(r->pool), NGX_ERROR); @@ -86,25 +90,41 @@ static int ngx_http_chunked_body_filter( cl = cl->next; } - ngx_test_null(chunk, ngx_palloc(r->pool, 11), NGX_ERROR); - len = ngx_snprintf((char *) chunk, 11, SIZE_T_X_FMT CRLF, size); + if (size) { + ngx_test_null(chunk, ngx_palloc(r->pool, 11), NGX_ERROR); + len = ngx_snprintf((char *) chunk, 11, SIZE_T_X_FMT CRLF, size); - ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); - h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; - h->pos = chunk; - h->last = chunk + len; + ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); + h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; + h->pos = chunk; + h->last = chunk + len; - out->hunk = h; - - ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); + out->hunk = h; + } if (cl->hunk->type & NGX_HUNK_LAST) { - cl->hunk->type &= ~NGX_HUNK_LAST; + + ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY|NGX_HUNK_LAST; h->pos = (u_char *) CRLF "0" CRLF CRLF; h->last = h->pos + 7; + cl->hunk->type &= ~NGX_HUNK_LAST; + + if (size == 0) { + out->hunk = h; + out->next = NULL; + + return ngx_http_next_body_filter(r, out); + } + } else { + if (size == 0) { + *ll = NULL; + return ngx_http_next_body_filter(r, out->next); + } + + ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY; h->pos = (u_char *) CRLF; h->last = h->pos + 2;
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c +++ b/src/http/modules/proxy/ngx_http_proxy_handler.c @@ -278,6 +278,7 @@ ngx_http_header_t ngx_http_proxy_headers offsetof(ngx_http_proxy_headers_in_t, location) }, { ngx_string("Accept-Ranges"), offsetof(ngx_http_proxy_headers_in_t, accept_ranges) }, + { ngx_string("X-Pad"), offsetof(ngx_http_proxy_headers_in_t, x_pad) }, { ngx_null_string, 0 } };
--- a/src/http/modules/proxy/ngx_http_proxy_handler.h +++ b/src/http/modules/proxy/ngx_http_proxy_handler.h @@ -123,6 +123,7 @@ typedef struct { ngx_table_elt_t *last_modified; ngx_table_elt_t *location; ngx_table_elt_t *accept_ranges; + ngx_table_elt_t *x_pad; off_t content_length_n; } ngx_http_proxy_headers_in_t;
--- a/src/http/modules/proxy/ngx_http_proxy_header.c +++ b/src/http/modules/proxy/ngx_http_proxy_header.c @@ -26,6 +26,10 @@ int ngx_http_proxy_copy_header(ngx_http_ continue; } + if (&h[i] == headers_in->x_pad) { + continue; + } + if (p->accel) { if (&h[i] == headers_in->date || &h[i] == headers_in->accept_ranges) {
--- a/src/os/unix/ngx_files.h +++ b/src/os/unix/ngx_files.h @@ -63,6 +63,11 @@ ssize_t ngx_write_chain_to_file(ngx_file #define ngx_file_uniq(sb) (sb)->st_ino + +#define ngx_getcwd(buf, size) (getcwd(buf, size) != NULL) +#define ngx_getcwd_n "getcwd()" +#define NGX_MAX_PATH PATH_MAX + #define NGX_DIR_MASK_LEN 0
--- a/src/os/win32/ngx_files.h +++ b/src/os/win32/ngx_files.h @@ -94,6 +94,11 @@ int ngx_file_info(u_char *filename, ngx_ - 116444736000000000) / 10000000) +#define ngx_getcwd(buf, size) GetCurrentDirectory(size, buf) +#define ngx_getcwd_n "GetCurrentDirectory()" +#define NGX_MAX_PATH MAX_PATH + + #define NGX_DIR_MASK (u_char *) "/*" #define NGX_DIR_MASK_LEN 2