summaryrefslogtreecommitdiffhomepage
path: root/src/http/modules
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2002-09-11 15:18:33 +0000
committerIgor Sysoev <igor@sysoev.ru>2002-09-11 15:18:33 +0000
commite0268b95c6dea75f88d3874213b1aa0cd0aba692 (patch)
tree49f871f82639d76c81618bff00546591bfef37d9 /src/http/modules
parent96f8377fd89b8735027ccfebea8ad9e77f40f51c (diff)
downloadnginx-e0268b95c6dea75f88d3874213b1aa0cd0aba692.tar.gz
nginx-e0268b95c6dea75f88d3874213b1aa0cd0aba692.tar.bz2
nginx-0.0.1-2002-09-11-19:18:33 import
Diffstat (limited to 'src/http/modules')
-rw-r--r--src/http/modules/ngx_http_header_filter.c82
-rw-r--r--src/http/modules/ngx_http_index_handler.c159
-rw-r--r--src/http/modules/ngx_http_index_handler.h26
-rw-r--r--src/http/modules/ngx_http_static_handler.c9
4 files changed, 114 insertions, 162 deletions
diff --git a/src/http/modules/ngx_http_header_filter.c b/src/http/modules/ngx_http_header_filter.c
deleted file mode 100644
index 9cb1f4c30..000000000
--- a/src/http/modules/ngx_http_header_filter.c
+++ /dev/null
@@ -1,82 +0,0 @@
-
-#include <nginx.h>
-
-#include <ngx_config.h>
-#include <ngx_core.h>
-#include <ngx_string.h>
-#include <ngx_hunk.h>
-#include <ngx_http.h>
-
-
-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_chain_t *ch;
-
- ngx_test_null(h, ngx_create_temp_hunk(r->pool, 1024, 0, 64),
- NGX_ERROR);
-
- status = r->headers_out->status - NGX_HTTP_OK;
-
- ngx_memcpy(h->last.mem, "HTTP/1.0 ", 9);
- h->last.mem += 9;
- ngx_memcpy(h->last.mem, http_codes[status].line, http_codes[status].len);
- h->last.mem += http_codes[status].len;
- *(h->last.mem++) = CR; *(h->last.mem++) = LF;
-
-/*
- memcpy(h->last.mem, "Date: ", 6);
- h->last.mem += 6;
- h->last.mem += ngx_http_get_time(h->last.mem, time(NULL));
- *(h->last.mem++) = CR; *(h->last.mem++) = LF;
-*/
-
- /* 2^64 is 20 characters */
- if (r->headers_out->content_length)
- h->last.mem += ngx_snprintf(h->last.mem, 49, "Content-Length: %d" CRLF,
- r->headers_out->content_length);
-
- /* check */
-
- memcpy(h->last.mem, "Server: ", 8);
- h->last.mem += 8;
- if (r->headers_out->server) {
- h->last.mem = ngx_cpystrn(h->last.mem, r->headers_out->server,
- h->end - h->last.mem);
-
- /* check space */
-
- } else {
- ngx_memcpy(h->last.mem, NGINX_VER, sizeof(NGINX_VER));
- h->last.mem += sizeof(NGINX_VER);
- }
- *(h->last.mem++) = CR; *(h->last.mem++) = LF;
-
- /* end of HTTP header */
- *(h->last.mem++) = CR; *(h->last.mem++) = LF;
-
- ngx_test_null(ch, ngx_palloc(r->pool, sizeof(ngx_chain_t)),
- /* STUB */
- -1);
-/*
- NGX_HTTP_FILTER_ERROR);
-*/
-
- ch->hunk = h;
- ch->next = NULL;
-
- return ngx_http_write_filter(r, ch);
-}
diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c
index 2d3f3663d..a356ac1a6 100644
--- a/src/http/modules/ngx_http_index_handler.c
+++ b/src/http/modules/ngx_http_index_handler.c
@@ -1,23 +1,53 @@
#include <ngx_config.h>
+#include <ngx_core.h>
+#include <ngx_errno.h>
+#include <ngx_string.h>
+#include <ngx_files.h>
+#include <ngx_config_command.h>
+#include <ngx_http.h>
+#include <ngx_http_config.h>
+#include <ngx_http_index_handler.h>
-#include <ngx_strings.h>
-#include <ngx_open.h>
-#include <ngx_stat.h>
-#include <ngx_http.h>
+static void *ngx_http_index_create_conf(ngx_pool_t *pool);
+static char *ngx_http_index_set_index(ngx_pool_t *p, void *conf, char *value);
+
+static ngx_command_t ngx_http_index_commands[];
+
+
+ngx_http_module_t ngx_http_index_module = {
+ NGX_HTTP_MODULE,
+ NULL, /* create server config */
+ ngx_http_index_create_conf, /* create location config */
+ ngx_http_index_commands, /* module directives */
+ NULL, /* init module */
+ NULL, /* init output body filter */
+};
+
+
+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 index_len, err, i;
- char *name, *loc, *file
- ngx_file_t fd;
+ int index_len, i;
+ char *name, *loc, *file;
+ ngx_err_t err;
+ ngx_fd_t fd;
- ngx_http_index_t *index;
- ngx_http_index_handler_loc_conf_t *cf;
+ ngx_http_index_file_t *index;
+ ngx_http_index_conf_t *cf;
- cf = (ngx_http_index_handler_loc_conf_t *)
- ngx_get_module_loc_conf(r, &ngx_http_index_handler_module);
+ cf = (ngx_http_index_conf_t *)
+ ngx_get_module_loc_conf(r, ngx_http_index_module);
index_len = (*(r->uri_end - 1) == '/') ? cf->max_index_len : 0;
@@ -29,96 +59,73 @@ int ngx_http_index_handler(ngx_http_request_t *r)
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);
- /* URI without / on the end - check directory */
- if (index_len == 0) {
+ index = (ngx_http_index_file_t *) cf->indices->elts;
+ for (i = 0; i < cf->indices->nelts; i++) {
+ ngx_memcpy(file, index[i].name, index[i].len);
- if (ngx_stat(name, &r->stat) == -1) {
+ fd = ngx_open_file(name, NGX_FILE_RDONLY);
+ if (fd == -1) {
err = ngx_errno;
- ngx_log_error(GX_LOG_ERR, r->connection->log, err,
- "ngx_http_handler: " ngx_stat_n " %s failed", name);
-
if (err == NGX_ENOENT)
- return NGX_HTTP_NOT_FOUND;
- else
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
+ continue;
- if (ngx_is_dir(r->stat)) {
- *file++ = '/';
- *file = '\0';
- r->headers_out->location = loc;
- return NGX_HTTP_MOVED_PERMANENTLY;
- }
-
- r->file = name;
- r->stat_valid = 1;
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, err,
+ ngx_open_file_n " %s failed", name);
- return NGX_OK;
- }
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
- /* look for index file */
- index = (ngx_http_index_t *) cf->indices->elts;
- for (i = 0; i < cf->indices->nelts; i++) {
- ngx_memcpy(file, index[i].name; index[i].len);
+ r->filename = name;
+ r->fd = fd;
- fd = ngx_open(name, O_RDONLY);
- if (fd != -1) {
- r->file = name;
- r->fd = fd;
- return NGX_OK;
- }
+ return ngx_http_internal_redirect(r, loc);
}
- return NGX_HTTP_FORBIDDEN;
+ return NGX_DECLINED;
}
-/*
-
-static void *ngx_create_index_config()
+static void *ngx_http_index_create_conf(ngx_pool_t *pool)
{
- ngx_http_index_handler_loc_conf_t *cf;
-
- ngx_check_null(cf, ngx_alloc(p, sizeof(ngx_http_index_handler_loc_conf)),
- NULL);
+ ngx_http_index_conf_t *conf;
- cf->indices = ngx_create_array(p, sizeof(ngx_http_index_t), 5);
- if (cf->indices == NULL)
- return NULL;
+ ngx_test_null(conf, ngx_pcalloc(pool, sizeof(ngx_http_index_conf_t)), NULL);
- cf->max_index_len = 0;
+ ngx_test_null(conf->indices,
+ ngx_create_array(pool, sizeof(ngx_http_index_file_t), 3),
+ NULL);
- return cf;
+ return conf;
}
-static void *ngx_merge_index_config()
+static void *ngx_http_index_merge_conf(ngx_pool_t *p, void *parent, void *child)
{
- if (p->indices->nelts > 0) {
+ ngx_http_index_conf_t *prev = (ngx_http_index_conf_t *) parent;
+ ngx_http_index_conf_t *conf = (ngx_http_index_conf_t *) child;
+ ngx_http_index_file_t *index;
- copy and check dups
+ if (conf->max_index_len == 0) {
+ if (prev->max_index_len != 0)
+ return prev;
- if (c->max_index_len < c->max_index_len)
- c->max_index_len < c->max_index_len);
+ ngx_test_null(index, ngx_push_array(conf->indices), NULL);
+ index->name = NGX_HTTP_INDEX;
+ conf->max_index_len = index->len = sizeof(NGX_HTTP_INDEX);
}
+
+ return conf;
}
-static void *ngx_set_index()
+static char *ngx_http_index_set_index(ngx_pool_t *p, void *conf, char *value)
{
- if (*conf == NULL) {
- cf = ngx_create_index_conf();
- if (cf == NULL)
- return "can not create config";
- }
+ ngx_http_index_conf_t *cf = (ngx_http_index_conf_t *) conf;
+ ngx_http_index_file_t *index;
- while (args) {
- index = ngx_push_array(cf->indices);
- index->name = arg;
- index->len = ngx_strlen(arg) + 1;
+ ngx_test_null(index, ngx_push_array(cf->indices), NULL);
+ index->name = value;
+ index->len = strlen(value);
- if (cf->max_index_len < index->len)
- cf->max_index_len = index->len;
- }
+ if (cf->max_index_len < index->len)
+ cf->max_index_len = index->len;
- *conf = cf;
+ return NULL;
}
-
-*/
diff --git a/src/http/modules/ngx_http_index_handler.h b/src/http/modules/ngx_http_index_handler.h
new file mode 100644
index 000000000..721bf2520
--- /dev/null
+++ b/src/http/modules/ngx_http_index_handler.h
@@ -0,0 +1,26 @@
+#ifndef _NGX_HTTP_INDEX_HANDLER_H_INCLUDED_
+#define _NGX_HTTP_INDEX_HANDLER_H_INCLUDED_
+
+
+#include <ngx_config.h>
+#include <ngx_array.h>
+#include <ngx_http.h>
+
+
+#define NGX_HTTP_INDEX "index.html"
+
+typedef struct {
+ ngx_array_t *indices;
+ size_t max_index_len;
+} ngx_http_index_conf_t;
+
+typedef struct {
+ char *name;
+ size_t len;
+} ngx_http_index_file_t;
+
+
+extern ngx_http_module_t ngx_http_index_module;
+
+
+#endif /* _NGX_HTTP_INDEX_HANDLER_H_INCLUDED_ */
diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c
index 0900a42cf..cbe430cf2 100644
--- a/src/http/modules/ngx_http_static_handler.c
+++ b/src/http/modules/ngx_http_static_handler.c
@@ -45,16 +45,17 @@ int ngx_http_static_handler(ngx_http_request_t *r)
ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno,
"ngx_http_static_handler: "
ngx_open_file_n " %s failed", r->filename);
- /* STUB */
- return -1;
+
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
if (ngx_stat_fd(r->fd, &r->fileinfo) == -1) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno,
"ngx_http_static_handler: "
ngx_stat_fd_n " %s failed", r->filename);
- /* STUB */
- return -1;
+
+ /* close fd */
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
r->headers_out->status = NGX_HTTP_OK;