Mercurial > hg > nginx-quic
comparison src/http/modules/ngx_http_static_handler.c @ 87:5f6d848dcbef
nginx-0.0.1-2003-05-13-20:02:32 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 13 May 2003 16:02:32 +0000 |
parents | 17ab1af8c3dd |
children | 674d333f4296 |
comparison
equal
deleted
inserted
replaced
86:3973260705cc | 87:5f6d848dcbef |
---|---|
1 | 1 |
2 #include <ngx_config.h> | 2 #include <ngx_config.h> |
3 | 3 #include <ngx_core.h> |
4 #include <ngx_string.h> | 4 #include <ngx_string.h> |
5 #include <ngx_file.h> | 5 #include <ngx_file.h> |
6 #include <ngx_hunk.h> | 6 #include <ngx_hunk.h> |
7 #include <ngx_http.h> | 7 #include <ngx_http.h> |
8 #include <ngx_http_config.h> | 8 #include <ngx_http_config.h> |
12 ngx_http_module_t ngx_http_static_module; | 12 ngx_http_module_t ngx_http_static_module; |
13 | 13 |
14 | 14 |
15 int ngx_http_static_handler(ngx_http_request_t *r) | 15 int ngx_http_static_handler(ngx_http_request_t *r) |
16 { | 16 { |
17 int rc; | 17 int rc; |
18 ngx_err_t err; | 18 ngx_err_t err; |
19 ngx_hunk_t *h; | 19 ngx_hunk_t *h; |
20 ngx_http_log_ctx_t *ctx; | 20 ngx_http_log_ctx_t *ctx; |
21 | 21 |
22 #if 0 | 22 #if 0 |
23 ngx_http_event_static_handler_loc_conf_t *cf; | 23 ngx_http_event_static_handler_loc_conf_t *cf; |
24 | 24 |
38 err = ngx_errno; | 38 err = ngx_errno; |
39 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, | 39 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, |
40 "ngx_http_static_handler: " | 40 "ngx_http_static_handler: " |
41 ngx_open_file_n " %s failed", r->file.name.data); | 41 ngx_open_file_n " %s failed", r->file.name.data); |
42 | 42 |
43 if (err == NGX_ENOENT) { | 43 if (err == NGX_ENOENT || err == NGX_ENOTDIR) { |
44 return NGX_HTTP_NOT_FOUND; | |
45 | |
46 } else if (err == NGX_ENOTDIR) { | |
47 return NGX_HTTP_NOT_FOUND; | 44 return NGX_HTTP_NOT_FOUND; |
48 | 45 |
49 } else { | 46 } else { |
50 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 47 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
51 } | 48 } |
124 NGX_HTTP_INTERNAL_SERVER_ERROR); | 121 NGX_HTTP_INTERNAL_SERVER_ERROR); |
125 | 122 |
126 ngx_test_null(h->file, ngx_pcalloc(r->pool, sizeof(ngx_file_t)), | 123 ngx_test_null(h->file, ngx_pcalloc(r->pool, sizeof(ngx_file_t)), |
127 NGX_HTTP_INTERNAL_SERVER_ERROR); | 124 NGX_HTTP_INTERNAL_SERVER_ERROR); |
128 | 125 |
129 rc = ngx_http_send_header(r); | 126 ngx_http_send_header(r); |
130 if (r->header_only) | 127 if (r->header_only) |
131 return rc; | 128 return NGX_OK; |
132 | 129 |
133 #if 1 | |
134 | 130 |
135 h->type = NGX_HUNK_FILE|NGX_HUNK_LAST; | 131 h->type = NGX_HUNK_FILE|NGX_HUNK_LAST; |
136 h->file_pos = 0; | 132 h->file_pos = 0; |
137 h->file_last = ngx_file_size(r->file.info); | 133 h->file_last = ngx_file_size(r->file.info); |
138 | 134 |
139 h->file->fd = r->file.fd; | 135 h->file->fd = r->file.fd; |
140 h->file->log = r->connection->log; | 136 h->file->log = r->connection->log; |
141 | 137 |
142 rc = ngx_http_output_filter(r, h); | 138 rc = ngx_http_output_filter(r, h); |
143 | 139 |
144 ngx_log_debug(r->connection->log, "0 output_filter: %d" _ rc); | 140 if (r->main == NULL) { |
141 if (rc == NGX_AGAIN) { | |
142 ngx_http_set_write_handler(r); | |
145 | 143 |
146 #else | 144 } else { |
147 | 145 ngx_http_finalize_request(r, 0); |
148 #define BLK 10000 | |
149 | |
150 { | |
151 int i, s; | |
152 s = ngx_file_size(r->file.info); | |
153 | |
154 for (i = 0; i < s; i += BLK) { | |
155 ngx_test_null(h, ngx_pcalloc(r->pool, sizeof(ngx_hunk_t)), | |
156 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
157 | |
158 ngx_test_null(h->file, ngx_pcalloc(r->pool, sizeof(ngx_file_t)), | |
159 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
160 | |
161 h->type = NGX_HUNK_FILE; | |
162 if (s - i <= BLK) { | |
163 h->type |= NGX_HUNK_LAST; | |
164 } | 146 } |
165 | |
166 h->pos.file = i; | |
167 h->last.file = i + BLK; | |
168 if (h->last.file > s) { | |
169 h->last.file = s; | |
170 } | |
171 | |
172 h->file->fd = r->file.fd; | |
173 h->file->log = r->connection->log; | |
174 | |
175 rc = ngx_http_output_filter(r, h); | |
176 | |
177 ngx_log_debug(r->connection->log, "0 output_filter: %d" _ rc); | |
178 } | |
179 } | 147 } |
180 | 148 |
181 #endif | 149 return NGX_OK; |
182 | |
183 return rc; | |
184 } | 150 } |