diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2002-12-15 06:25:09 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2002-12-15 06:25:09 +0000 |
| commit | 42feecbdb694e114e034f0be67d19bba4165c363 (patch) | |
| tree | aea7c9c7c12f3cfef321901ddf92846815f1b876 /src/http/modules | |
| parent | 3add464b545b5dd29d07873b84f90fb77021d0c4 (diff) | |
| download | nginx-42feecbdb694e114e034f0be67d19bba4165c363.tar.gz nginx-42feecbdb694e114e034f0be67d19bba4165c363.tar.bz2 | |
nginx-0.0.1-2002-12-15-09:25:09 import
Diffstat (limited to 'src/http/modules')
| -rw-r--r-- | src/http/modules/ngx_http_event_proxy_handler.c | 8 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_index_handler.c | 34 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_log_handler.c | 79 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_static_handler.c | 145 |
4 files changed, 165 insertions, 101 deletions
diff --git a/src/http/modules/ngx_http_event_proxy_handler.c b/src/http/modules/ngx_http_event_proxy_handler.c index af3546863..d7d61785f 100644 --- a/src/http/modules/ngx_http_event_proxy_handler.c +++ b/src/http/modules/ngx_http_event_proxy_handler.c @@ -309,7 +309,9 @@ static int ngx_http_proxy_read_response_header(ngx_event_t *ev) if (n == 0) { ngx_log_debug(c->log, "CLOSE proxy"); - ngx_del_event(ev, NGX_READ_EVENT); +#if 0 + ngx_del_event(ev, NGX_READ_EVENT, NGX_CLOSE_EVENT); +#endif ngx_event_close_connection(ev); p->hunk_n = 0; @@ -439,7 +441,9 @@ static int ngx_http_proxy_read_response_body(ngx_event_t *ev) if (n == 0) { ngx_log_debug(c->log, "CLOSE proxy"); - ngx_del_event(ev, NGX_READ_EVENT); +#if 0 + ngx_del_event(ev, NGX_READ_EVENT, NGX_CLOSE_EVENT); +#endif ngx_event_close_connection(ev); p->hunk_n = 0; diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c index b6e0adb85..194879503 100644 --- a/src/http/modules/ngx_http_index_handler.c +++ b/src/http/modules/ngx_http_index_handler.c @@ -16,7 +16,16 @@ static void *ngx_http_index_merge_conf(ngx_pool_t *p, static char *ngx_http_index_set_index(ngx_pool_t *p, void *conf, ngx_str_t *value); -static ngx_command_t ngx_http_index_commands[]; + +static ngx_command_t ngx_http_index_commands[] = { + + {"index", ngx_http_index_set_index, NULL, + NGX_HTTP_LOC_CONF, NGX_CONF_ITERATE, + "set index files"}, + + {NULL} + +}; ngx_http_module_t ngx_http_index_module = { @@ -33,17 +42,6 @@ ngx_http_module_t ngx_http_index_module = { }; -static ngx_command_t ngx_http_index_commands[] = { - - {"index", ngx_http_index_set_index, NULL, - NGX_HTTP_LOC_CONF, NGX_CONF_ITERATE, - "set index files"}, - - {NULL} - -}; - - int ngx_http_index_handler(ngx_http_request_t *r) { int i; @@ -71,10 +69,14 @@ int ngx_http_index_handler(ngx_http_request_t *r) ngx_memcpy(file, index[i].data, index[i].len + 1); fd = ngx_open_file(name, NGX_FILE_RDONLY); - if (fd == -1) { + if (fd == NGX_INVALID_FILE) { err = ngx_errno; if (err == NGX_ENOENT) continue; +#if (WIN32) + if (err == ERROR_PATH_NOT_FOUND) + continue; +#endif ngx_log_error(NGX_LOG_ERR, r->connection->log, err, ngx_open_file_n " %s failed", name); @@ -82,9 +84,9 @@ int ngx_http_index_handler(ngx_http_request_t *r) return NGX_HTTP_INTERNAL_SERVER_ERROR; } - r->filename.len = r->server->doc_root_len + r->uri.len + index[i].len; - r->filename.data = name; - r->fd = fd; + r->file.name.len = r->server->doc_root_len + r->uri.len + index[i].len; + r->file.name.data = name; + r->file.fd = fd; loc.len = r->uri.len + index[i].len; return ngx_http_internal_redirect(r, loc); diff --git a/src/http/modules/ngx_http_log_handler.c b/src/http/modules/ngx_http_log_handler.c new file mode 100644 index 000000000..56ea8419e --- /dev/null +++ b/src/http/modules/ngx_http_log_handler.c @@ -0,0 +1,79 @@ + +#include <ngx_config.h> +#include <ngx_core.h> +#include <ngx_string.h> +#include <ngx_alloc.h> +#include <ngx_time.h> +#include <ngx_http.h> + + +ngx_http_module_t ngx_http_log_module; + + +static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; + + +int ngx_http_log_handler(ngx_http_request_t *r) +{ + size_t len; + char *line, *p; + ngx_tm_t tm; + +#if (WIN32) + len = 2 + 22 + 3 + 20 + 5 + 20 + 2; +#else + len = 2 + 22 + 3 + 20 + 5 + 20 + 1; +#endif + + len += r->connection->addr_text.len; + len += r->request_line.len; + + + ngx_test_null(line, ngx_palloc(r->pool, len), NGX_ERROR); + p = line; + + ngx_memcpy(p, r->connection->addr_text.data, r->connection->addr_text.len); + p += r->connection->addr_text.len; + + *p++ = ' '; + + ngx_localtime(&tm); + + *p++ = '['; + p += ngx_snprintf(p, 21, "%02d/%s/%d:%02d:%02d:%02d", + tm.ngx_tm_mday, months[tm.ngx_tm_mon], + tm.ngx_tm_year + 1900, + tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec); + + *p++ = ']'; + + *p++ = ' '; + + *p++ = '"'; + ngx_memcpy(p, r->request_line.data, r->request_line.len); + p += r->request_line.len; + *p++ = '"'; + + *p++ = ' '; + + p += ngx_snprintf(p, 4, "%d", r->headers_out.status); + + *p++ = ' '; + + p += ngx_snprintf(p, 21, QD_FMT, r->connection->sent); + + *p++ = ' '; + + p += ngx_snprintf(p, 21, "%u", r->connection->number); + +#if (WIN32) + *p++ = CR; *p++ = LF; +#else + *p++ = LF; +#endif + + write(1, line, len); + + return NGX_OK; +} diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c index cded5f017..56f24cd07 100644 --- a/src/http/modules/ngx_http_static_handler.c +++ b/src/http/modules/ngx_http_static_handler.c @@ -24,51 +24,84 @@ void ngx_http_static_init() int ngx_http_static_handler(ngx_http_request_t *r) { - int rc; + int rc; + ngx_err_t err; ngx_hunk_t *h; ngx_http_log_ctx_t *ctx; -/* +#if 0 ngx_http_event_static_handler_loc_conf_t *cf; cf = (ngx_http_event_static_handler_loc_conf_t *) ngx_get_module_loc_conf(r, &ngx_http_event_static_handler_module); -*/ +#endif ngx_http_discard_body(r); ctx = r->connection->log->data; ctx->action = "sending response"; - if (r->fd != -1) - r->fd = ngx_open_file(r->filename.data, NGX_FILE_RDONLY); + if (r->file.fd == NGX_INVALID_FILE) + r->file.fd = ngx_open_file(r->file.name.data, NGX_FILE_RDONLY); - if (r->fd == -1) { + if (r->file.fd == NGX_INVALID_FILE) { + err = ngx_errno; ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, "ngx_http_static_handler: " - ngx_open_file_n " %s failed", r->filename.data); + ngx_open_file_n " %s failed", r->file.name.data); + + if (err == NGX_ENOENT) + return NGX_HTTP_NOT_FOUND; +#if (WIN32) + else if (err == ERROR_PATH_NOT_FOUND) + return NGX_HTTP_NOT_FOUND; +#endif + else + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + + if (!r->file.info_valid) { + if (ngx_stat_fd(r->file.fd, &r->file.info) == NGX_FILE_ERROR) { + ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, + "ngx_http_static_handler: " + ngx_stat_fd_n " %s failed", r->file.name.data); + + if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) + ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, + "ngx_http_static_handler: " + ngx_close_file_n " %s failed", r->file.name.data); - return NGX_HTTP_INTERNAL_SERVER_ERROR; + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + + r->file.info_valid = 1; } - if (ngx_stat_fd(r->fd, &r->fileinfo) == -1) { +#if !(WIN32) /* it's probably Unix specific */ + + if (!ngx_is_file(r->file.info)) { ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, "ngx_http_static_handler: " - ngx_stat_fd_n " %s failed", r->filename.data); + "%s is not regular file", r->file.name.data); + + if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) + ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, + "ngx_http_static_handler: " + ngx_close_file_n " %s failed", r->file.name.data); - /* close fd */ - return NGX_HTTP_INTERNAL_SERVER_ERROR; + return NGX_HTTP_NOT_FOUND; } +#endif + r->headers_out.status = NGX_HTTP_OK; - r->headers_out.content_length = ngx_file_size(r->fileinfo); -/* - r->headers_out.last_modified = ngx_file_mtime(r->fileinfo); -*/ + r->headers_out.content_length = ngx_file_size(r->file.info); + r->headers_out.last_modified_time = ngx_file_mtime(r->file.info); ngx_test_null(r->headers_out.content_type, ngx_push_table(r->headers_out.headers), NGX_HTTP_INTERNAL_SERVER_ERROR); + r->headers_out.content_type->key.len = 12; r->headers_out.content_type->key.data = "Content-Type"; @@ -90,83 +123,29 @@ int ngx_http_static_handler(ngx_http_request_t *r) r->headers_out.content_type->value.len = 25; r->headers_out.content_type->value.data = "text/html; charset=koi8-r"; } + /**/ - /* STUB */ - rc = ngx_http_header_filter(r); -/* - rc = ngx_send_http_header(r); -*/ - if (r->header_only) - return rc; - - /* TODO: NGX_HTTP_INTERNAL_SERVER_ERROR is too late */ - - /* STUB */ + /* we need to allocate them before header would be sent */ ngx_test_null(h, ngx_pcalloc(r->pool, sizeof(ngx_hunk_t)), NGX_HTTP_INTERNAL_SERVER_ERROR); - h->type = NGX_HUNK_FILE|NGX_HUNK_LAST; - h->pos.file = 0; - h->last.file = ngx_file_size(r->fileinfo); - - /* STUB */ ngx_test_null(h->file, ngx_pcalloc(r->pool, sizeof(ngx_file_t)), NGX_HTTP_INTERNAL_SERVER_ERROR); - h->file->fd = r->fd; - h->file->log = r->connection->log; - - rc = ngx_http_output_filter(r, h); - ngx_log_debug(r->connection->log, "0 output_filter: %d" _ rc); - return rc; -} - -#if 0 - -static void *ngx_create_index_config() -{ - ngx_http_index_handler_loc_conf_t *cf; - - ngx_check_null(cf, ngx_alloc(p, sizeof(ngx_http_index_handler_loc_conf)), - NULL); - cf->indices = ngx_create_array(p, sizeof(ngx_http_index_t), 5); - if (cf->indices == NULL) - return NULL; - - cf->max_index_len = 0; - - return cf; -} - -static void *ngx_merge_index_config() -{ - if (p->indices->nelts > 0) { - - copy and check dups + rc = ngx_http_send_header(r); + if (r->header_only) + return rc; - if (c->max_index_len < c->max_index_len) - c->max_index_len < c->max_index_len); - } -} + h->type = NGX_HUNK_FILE|NGX_HUNK_LAST; + h->pos.file = 0; + h->last.file = ngx_file_size(r->file.info); -static void *ngx_set_index() -{ - if (*conf == NULL) { - cf = ngx_create_index_conf(); - if (cf == NULL) - return "can not create config"; - } + h->file->fd = r->file.fd; + h->file->log = r->connection->log; - while (args) { - index = ngx_push_array(cf->indices); - index->name = arg; - index->len = ngx_strlen(arg) + 1; + rc = ngx_http_output_filter(r, h); - if (cf->max_index_len < index->len) - cf->max_index_len = index->len; - } + ngx_log_debug(r->connection->log, "0 output_filter: %d" _ rc); - *conf = cf; + return rc; } - -#endif |
