diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2002-08-16 15:27:03 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2002-08-16 15:27:03 +0000 |
| commit | e0af1b89dcd100462a3195534b2f78a838ca85b5 (patch) | |
| tree | 9c9eb63c71b13cc9159209e39eb099c54c6cb6b1 /src/http | |
| parent | 0c331d9f666b4f9be91009b7caea457e58a80779 (diff) | |
| download | nginx-e0af1b89dcd100462a3195534b2f78a838ca85b5.tar.gz nginx-e0af1b89dcd100462a3195534b2f78a838ca85b5.tar.bz2 | |
nginx-0.0.1-2002-08-16-19:27:03 import
Diffstat (limited to 'src/http')
| -rw-r--r-- | src/http/modules/ngx_http_header_filter.c | 13 | ||||
| -rw-r--r-- | src/http/ngx_http.c | 45 | ||||
| -rw-r--r-- | src/http/ngx_http.h | 24 | ||||
| -rw-r--r-- | src/http/ngx_http_event.c | 72 |
4 files changed, 149 insertions, 5 deletions
diff --git a/src/http/modules/ngx_http_header_filter.c b/src/http/modules/ngx_http_header_filter.c index 1742b8bfc..d24765446 100644 --- a/src/http/modules/ngx_http_header_filter.c +++ b/src/http/modules/ngx_http_header_filter.c @@ -12,11 +12,11 @@ static line http_codes[] = { - int ngx_http_header_filter(ngx_http_request_t *r) { int status; - ngx_hunk_t *h; + ngx_hunk_t *h; + ngx_chain_t *ch; ngx_test_null(h, ngx_get_hunk(r->pool, 1024, 0, 64), NGX_HTTP_FILTER_ERROR); @@ -51,5 +51,12 @@ int ngx_http_header_filter(ngx_http_request_t *r) h->pos.mem += sizeof(NGINX_VER); } *(h->pos.mem++) = CR; *(h->pos.mem++) = LF; - + + ngx_test_null(ch, ngx_palloc(r->pool, sizeof(ngx_chain_t)), + NGX_HTTP_FILTER_ERROR); + + ch->hunk = in->hunk; + ch->next = NULL; + + return ngx_http_write_filter(r, ch); } diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c new file mode 100644 index 000000000..c3343fa49 --- /dev/null +++ b/src/http/ngx_http.c @@ -0,0 +1,45 @@ + +#include <ngx_http.h> + + +/* STUB */ + +static struct sockaddr_in addr; +static char addr_text[22]; + +static ngx_http_server_t ngx_http_server; + +int ngx_http_init(ngx_pool_t *pool) +{ + ngx_listen_t *ls; + + ngx_http_server.handler = ngx_http_init_connection; + + ngx_http_server.buff_size = 1024; + + ngx_http_server.doc_root = "/home/is/work/xml/site-1.0.0/html"; + ngx_http_server.doc_root_len = strlen(server.doc_root); + + ls = ngx_push_array(ngx_listening_sockets); + ngx_memzero(ls, sizeof(nxg_listen_t)); + + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = inet_addr(optarg) + 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 = 0; + ls->addr = &addr; + ls->addr_len = sizeof(sockaddr_in); + ls->text = &addr_text; + ls->backlog = -1; + ls->nonblocking = 1; + + return 1; +} + +/* */ diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h index 6fa0f7829..e05dcc857 100644 --- a/src/http/ngx_http.h +++ b/src/http/ngx_http.h @@ -19,7 +19,15 @@ #define NGX_HTTP_CONN_CLOSE 0 #define NGX_HTTP_CONN_KEEP_ALIVE 1 -#define NGX_HTTP_OK 200 +#define NGX_OK 0 + +#define NGX_HTTP_OK 200 +#define NGX_HTTP_NOT_FOUND 404 +#define NGX_HTTP_INTERNAL_SERVER_ERROR 503 + + +#define NGX_HTTP_STATIC_HANDLER 0 +#define NGX_HTTP_DIRECTORY_HANDLER 1 typedef struct { @@ -30,6 +38,11 @@ typedef struct { #define ngx_get_module_ctx(r, module) (module)->ctx typedef struct { + char *doc_root; + int doc_root_len; +} ngx_http_server_t; + +typedef struct { char *buff; char *pos; char *last; @@ -50,6 +63,12 @@ typedef struct { typedef struct ngx_http_request_s ngx_http_request_t; struct ngx_http_request_s { + char *filename; + char *location; + + int filename_len; + int (*handler)(ngx_http_request_t *r); + int method; int http_version; @@ -59,7 +78,8 @@ struct ngx_http_request_s { char *uri; ngx_http_request_t *main; - ngx_connection_t *connection; + ngx_connection_t *connection; + ngx_http_server_t *server; ngx_buff_t *buff; ngx_pool_t *pool; diff --git a/src/http/ngx_http_event.c b/src/http/ngx_http_event.c index 24cbb5663..9e63f9261 100644 --- a/src/http/ngx_http_event.c +++ b/src/http/ngx_http_event.c @@ -180,6 +180,78 @@ static int ngx_process_http_request_header(ngx_http_request_t *r) static int ngx_process_http_request(ngx_http_request_t *r) { + int err; + char *name, *loc, *file; + + ngx_log_debug(r->connection->log, "HTTP request"); + + if (*(r->uri_end - 1) == '/') { + r->handler = NGX_HTTP_DIRECTORY_HANDLER; + return NGX_OK; + } + + /* 20 bytes is spare space for some index name, i.e. index.html */ + r->filename_len = r->uri_end - r->uri_start + r->server->doc_root_len + 20; + + ngx_test_null(r->filename, + ngx_palloc(r->pool, r->filename_len), + ngx_http_error(r, NGX_HTTP_INTERNAL_SERVER_ERROR)); + + r->location = ngx_cpystrn(r->filename, r->server->doc_root, + r->server->doc_root_len); + file = ngx_cpystrn(r->location, r->uri_start, + r->uri_end - r->uri_start + 1); + + ngx_log_debug(r->connection->log, "HTTP filename: '%s'" _ r->filename); + +} +#if 0 + + if (ngx_stat(r->filename, &r->stat) == -1) { + err = ngx_errno; + ngx_log_error(GX_LOG_ERR, r->connection->log, err, + "ngx_process_http_request: " + ngx_stat_n " %s failed", r->filename); + + if (err == NGX_ENOENT) + return ngx_http_error(r, NGX_HTTP_NOT_FOUND); + else + return ngx_http_error(r, NGX_HTTP_INTERNAL_SERVER_ERROR); + } + + if (ngx_is_dir(r->stat)) { + *file++ = '/'; + *file = '\0'; + r->headers_out->location = r->location; + return ngx_http_redirect(r, NGX_HTTP_MOVED_PERMANENTLY); + } + + r->stat_valid = 1; + r->handler = NGX_HTTP_STATIC_HANDLER; + return NGX_OK; +} + +static int ngx_http_handler(ngx_http_request_t *r, int handler) +{ + if (handler == NGX_HTTP_STATIC_HANDLER) + return ngx_http_static_handler(r); + + elsif (handler == NGX_HTTP_DIRECTORY_HANDLER) + return ngx_http_index_handler(r); + + return ngx_http_error(r, NGX_HTTP_INTERNAL_SERVER_ERROR); +} +#endif + +static int ngx_http_redirect(ngx_http_request_t *r, int redirect) +{ + /* STUB */ + return -1; +} + +static int ngx_http_error(ngx_http_request_t *r, int error) +{ + /* STUB */ return -1; } |
