comparison src/http/modules/ngx_http_static_handler.c @ 3:34a521b1a148

nginx-0.0.1-2002-08-20-18:48:28 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 20 Aug 2002 14:48:28 +0000
parents d220029ac7f3
children 708f8bb772ec
comparison
equal deleted inserted replaced
2:ffffe1499bce 3:34a521b1a148
1 1
2 #include <ngx_config.h> 2 #include <ngx_config.h>
3 #include <ngx_string.h>
4 #include <ngx_file.h>
5 #include <ngx_hunk.h>
6 #include <ngx_http.h>
3 7
4 #include <ngx_strings.h> 8 ngx_http_module_t ngx_http_static_module;
5 #include <ngx_open.h>
6 #include <ngx_stat.h>
7 9
8 #include <ngx_http.h> 10
11 #if 0
12 /* STUB */
13 static ngx_http_static_ctx_t module_ctx;
14
15 void ngx_http_static_init()
16 {
17 module_ctx.out = NULL;
18
19 ngx_http_static_module.ctx = &module_ctx;
20 }
21 /* */
22 #endif
23
9 24
10 int ngx_http_static_handler(ngx_http_request_t *r) 25 int ngx_http_static_handler(ngx_http_request_t *r)
11 { 26 {
12 int index_len, err, i; 27 int rc;
13 char *name, *loc, *file 28 ngx_hunk_t *h;
14 ngx_file_t fd; 29 ngx_chain_t *ch;
15 30
16 ngx_http_header_out_t out; 31 /*
17 ngx_http_event_static_handler_loc_conf_t *cf; 32 ngx_http_event_static_handler_loc_conf_t *cf;
18 33
19 cf = (ngx_http_event_static_handler_loc_conf_t *) 34 cf = (ngx_http_event_static_handler_loc_conf_t *)
20 ngx_get_module_loc_conf(r, &ngx_http_event_static_handler_module); 35 ngx_get_module_loc_conf(r, &ngx_http_event_static_handler_module);
21 36
22 ngx_assert(r->fd, return NGX_HTTP_INTERNAL_SERVER_ERROR, 37 */
23 r->connection->log, "ngx_http_static_handler: no file");
24 38
25 out.status = NGX_HTTP_OK; 39 r->fd = ngx_open_file(r->filename, NGX_FILE_RDONLY);
26 out.content_length = r->stat.sb_size; 40 if (r->fd == -1) {
27 out.last_modified = r->stat.sb_mtime; 41 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno,
42 "ngx_http_static_handler: "
43 ngx_open_file_n " %s failed", r->filename);
44 /* STUB */
45 return -1;
46 }
28 47
29 /* */ 48 if (ngx_stat_fd(r->fd, &r->file_info) == -1) {
30 out.content_type = "text/html"; 49 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno,
50 "ngx_http_static_handler: "
51 ngx_stat_fd_n " %s failed", r->filename);
52 /* STUB */
53 return -1;
54 }
31 55
32 rc = ngx_send_http_header(&out); 56 r->headers_out->status = NGX_HTTP_OK;
57 r->headers_out->content_length = ngx_file_size(r->file_info);
58 /*
59 r->headers_out->last_modified = ngx_file_mtime(r->file_info);
60 */
61
62 /* STUB */
63 r->headers_out->content_type = "text/html";
64
65 /* STUB */
66 rc = ngx_http_header_filter(r);
67 /*
68 rc = ngx_send_http_header(r->headers_out);
69 */
33 if (r->header_only) 70 if (r->header_only)
34 return rc; 71 return rc;
35 72
36 /* NGX_HTTP_INTERNAL_SERVER_ERROR is too late */ 73 /* TODO: NGX_HTTP_INTERNAL_SERVER_ERROR is too late */
37 74
75 /* STUB */
76 ngx_test_null(h, ngx_get_hunk(r->pool, 1024, 0, 64),
77 /* STUB */
78 -1);
79 /*
38 ngx_test_null(h, ngx_create_hunk(r->pool), NGX_HTTP_INTERNAL_SERVER_ERROR); 80 ngx_test_null(h, ngx_create_hunk(r->pool), NGX_HTTP_INTERNAL_SERVER_ERROR);
39 h->type = NGX_HUNK_FILE | NGX_HUNK_LAST; 81 */
82 h->type = NGX_HUNK_FILE|NGX_HUNK_LAST;
40 h->fd = r->fd; 83 h->fd = r->fd;
41 h->pos.file = 0; 84 h->pos.file = 0;
42 h->end.file = r->stat.sb_size; 85 h->last.file = ngx_file_size(r->file_info);
43 86
87 /* STUB */
88 ngx_test_null(ch, ngx_palloc(r->pool, sizeof(ngx_chain_t)),
89 /* STUB */
90 -1);
91 /*
92 NGX_HTTP_FILTER_ERROR);
93 */
94
95 /*
44 ngx_test_null(ch, ngx_create_chain(r->pool), 96 ngx_test_null(ch, ngx_create_chain(r->pool),
45 NGX_HTTP_INTERNAL_SERVER_ERROR); 97 NGX_HTTP_INTERNAL_SERVER_ERROR);
98 */
46 ch->hunk = h; 99 ch->hunk = h;
47 ch->next = NULL; 100 ch->next = NULL;
48 101
49 return ngx_http_filter(ch); 102 /* STUB */
103 rc = ngx_http_write_filter(r, ch);
104 ngx_log_debug(r->connection->log, "write_filter: %d" _ rc);
105 return rc;
106 /*
107 return ngx_http_filter(r, ch);
108 */
50 } 109 }
51 110
52 /* 111 #if 0
53 112
54 static void *ngx_create_index_config() 113 static void *ngx_create_index_config()
55 { 114 {
56 ngx_http_index_handler_loc_conf_t *cf; 115 ngx_http_index_handler_loc_conf_t *cf;
57 116
96 } 155 }
97 156
98 *conf = cf; 157 *conf = cf;
99 } 158 }
100 159
101 */ 160 #endif