diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2002-08-15 17:20:26 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2002-08-15 17:20:26 +0000 |
| commit | 0c331d9f666b4f9be91009b7caea457e58a80779 (patch) | |
| tree | d48221581b361ee5b0ccad46e4df49caa41b1bba /src/http/modules | |
| parent | 6de5c2cb63f8aee4bcbec3c363a72fd8e4a4e64d (diff) | |
| download | nginx-0c331d9f666b4f9be91009b7caea457e58a80779.tar.gz nginx-0c331d9f666b4f9be91009b7caea457e58a80779.tar.bz2 | |
nginx-0.0.1-2002-08-15-21:20:26 import
Diffstat (limited to 'src/http/modules')
| -rw-r--r-- | src/http/modules/ngx_http_header_filter.c | 55 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_index_handler.c | 11 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_static_handler.c | 101 |
3 files changed, 162 insertions, 5 deletions
diff --git a/src/http/modules/ngx_http_header_filter.c b/src/http/modules/ngx_http_header_filter.c new file mode 100644 index 000000000..1742b8bfc --- /dev/null +++ b/src/http/modules/ngx_http_header_filter.c @@ -0,0 +1,55 @@ + + +typedef struct { + int len; + char *line; +} line; + + +static line http_codes[] = { + { 6, "200 OK" } +}; + + + + +int ngx_http_header_filter(ngx_http_request_t *r) +{ + int status; + ngx_hunk_t *h; + + ngx_test_null(h, ngx_get_hunk(r->pool, 1024, 0, 64), NGX_HTTP_FILTER_ERROR); + + status = r->headers_out->status - GX_HTTP_OK; + + ngx_memcpy(h->pos.mem, "HTTP/1.0 ", 9); + h->pos.mem += 9; + ngx_memcpy(h->pos.mem, http_codes[status].line, http_codes[status].len); + h->pos.mem += http_codes[status].len; + *(h->pos.mem++) = CR; *(h->pos.mem++) = LF; + + memcpy(h->pos.mem, "Date: ", 6); + h->pos.mem += 6; + h->pos.mem += ngx_http_get_time(h->pos.mem, time()); + *(h->pos.mem++) = CR; *(h->pos.mem++) = LF; + + /* 2^64 is 20 characters */ + if (r->headers_out->content_length) + h->pos.mem += ngx_snprintf(h->pos.mem, 49, "Content-Length: %d" CRLF, + r->headers_out->content_length); + + /* check */ + + memcpy(h->pos.mem, "Server: ", 8); + h->pos.mem += 8; + if (r->headers_out->server) { + h->pos.mem = ngx_cpystrn(h->pos.mem, r->headers_out->server, + h->last.mem - h->pos.mem); + check space + } else { + ngx_memcpy(h->pos.mem, NGINX_VER, sizeof(NGINX_VER)); + h->pos.mem += sizeof(NGINX_VER); + } + *(h->pos.mem++) = CR; *(h->pos.mem++) = LF; + +} diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c index 498dda664..2d3f3663d 100644 --- a/src/http/modules/ngx_http_index_handler.c +++ b/src/http/modules/ngx_http_index_handler.c @@ -20,10 +20,11 @@ int ngx_http_index_handler(ngx_http_request_t *r) ngx_get_module_loc_conf(r, &ngx_http_index_handler_module); index_len = (*(r->uri_end - 1) == '/') ? cf->max_index_len : 0; - name = ngx_palloc(r->pool, r->uri_end - r->uri_start + index_len - + r->server->doc_root_len); - if (name == NULL) - return NGX_ERROR; + + ngx_test_null(name, + ngx_palloc(r->pool, r->uri_end - r->uri_start + index_len + + r->server->doc_root_len), + NGX_HTTP_INTERNAL_SERVER_ERROR); loc = ngx_cpystrn(name, r->server->doc_root, r->server->doc_root_len); file = ngx_cpystrn(loc, r->uri_start, r->uri_end - r->uri_start + 1); @@ -39,7 +40,7 @@ int ngx_http_index_handler(ngx_http_request_t *r) if (err == NGX_ENOENT) return NGX_HTTP_NOT_FOUND; else - return NGX_ERROR; + return NGX_HTTP_INTERNAL_SERVER_ERROR; } if (ngx_is_dir(r->stat)) { diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c new file mode 100644 index 000000000..f2053c443 --- /dev/null +++ b/src/http/modules/ngx_http_static_handler.c @@ -0,0 +1,101 @@ + +#include <ngx_config.h> + +#include <ngx_strings.h> +#include <ngx_open.h> +#include <ngx_stat.h> + +#include <ngx_http.h> + +int ngx_http_static_handler(ngx_http_request_t *r) +{ + int index_len, err, i; + char *name, *loc, *file + ngx_file_t fd; + + ngx_http_header_out_t out; + 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); + + ngx_assert(r->fd, return NGX_HTTP_INTERNAL_SERVER_ERROR, + r->connection->log, "ngx_http_static_handler: no file"); + + out.status = NGX_HTTP_OK; + out.content_length = r->stat.sb_size; + out.last_modified = r->stat.sb_mtime; + + /* */ + out.content_type = "text/html"; + + rc = ngx_send_http_header(&out); + if (r->header_only) + return rc; + + /* NGX_HTTP_INTERNAL_SERVER_ERROR is too late */ + + ngx_test_null(h, ngx_create_hunk(r->pool), NGX_HTTP_INTERNAL_SERVER_ERROR); + h->type = NGX_HUNK_FILE | NGX_HUNK_LAST; + h->fd = r->fd; + h->pos.file = 0; + h->end.file = r->stat.sb_size; + + ngx_test_null(ch, ngx_create_chain(r->pool), + NGX_HTTP_INTERNAL_SERVER_ERROR); + ch->hunk = h; + ch->next = NULL; + + return ngx_http_filter(ch); +} + +/* + +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 + + if (c->max_index_len < c->max_index_len) + c->max_index_len < c->max_index_len); + } +} + +static void *ngx_set_index() +{ + if (*conf == NULL) { + cf = ngx_create_index_conf(); + if (cf == NULL) + return "can not create config"; + } + + while (args) { + index = ngx_push_array(cf->indices); + index->name = arg; + index->len = ngx_strlen(arg) + 1; + + if (cf->max_index_len < index->len) + cf->max_index_len = index->len; + } + + *conf = cf; +} + +*/ |
