Mercurial > hg > nginx
comparison src/http/modules/ngx_http_static_handler.c @ 186:c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 16 Nov 2003 21:49:42 +0000 |
parents | d5f50cefc322 |
children | 02a715e85df1 |
comparison
equal
deleted
inserted
replaced
185:d5f50cefc322 | 186:c1f3a3c7c5db |
---|---|
93 * there is no way to open a file or a directory in Win9X with | 93 * there is no way to open a file or a directory in Win9X with |
94 * one syscall because Win9X has no FILE_FLAG_BACKUP_SEMANTICS flag | 94 * one syscall because Win9X has no FILE_FLAG_BACKUP_SEMANTICS flag |
95 * so we need to check its type before the opening | 95 * so we need to check its type before the opening |
96 */ | 96 */ |
97 | 97 |
98 if (ngx_file_type(r->file.name.data, &r->file.info) == NGX_FILE_ERROR) { | 98 if (ngx_file_info(r->file.name.data, &r->file.info) == NGX_FILE_ERROR) { |
99 err = ngx_errno; | 99 err = ngx_errno; |
100 ngx_log_error(NGX_LOG_ERR, r->connection->log, err, | 100 ngx_log_error(NGX_LOG_ERR, r->connection->log, err, |
101 ngx_file_type_n " \"%s\" failed", r->file.name.data); | 101 ngx_file_info_n " \"%s\" failed", r->file.name.data); |
102 | 102 |
103 if (err == NGX_ENOENT || err == NGX_ENOTDIR) { | 103 if (err == NGX_ENOENT || err == NGX_ENOTDIR) { |
104 return NGX_HTTP_NOT_FOUND; | 104 return NGX_HTTP_NOT_FOUND; |
105 | 105 |
106 } else if (err == NGX_EACCES) { | 106 } else if (err == NGX_EACCES) { |
109 } else { | 109 } else { |
110 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 110 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 if (ngx_is_dir(r->file.info)) { | 114 if (ngx_is_dir(&r->file.info)) { |
115 ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data); | 115 ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data); |
116 | 116 |
117 if (!(r->headers_out.location = | 117 if (!(r->headers_out.location = |
118 ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) | 118 ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) |
119 { | 119 { |
161 } | 161 } |
162 | 162 |
163 ngx_log_debug(r->connection->log, "FILE: %d" _ r->file.fd); | 163 ngx_log_debug(r->connection->log, "FILE: %d" _ r->file.fd); |
164 | 164 |
165 if (!r->file.info_valid) { | 165 if (!r->file.info_valid) { |
166 if (ngx_stat_fd(r->file.fd, &r->file.info) == NGX_FILE_ERROR) { | 166 if (ngx_fd_info(r->file.fd, &r->file.info) == NGX_FILE_ERROR) { |
167 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, | 167 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, |
168 ngx_stat_fd_n " \"%s\" failed", r->file.name.data); | 168 ngx_fd_info_n " \"%s\" failed", r->file.name.data); |
169 | 169 |
170 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) { | 170 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) { |
171 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno, | 171 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno, |
172 ngx_close_file_n " \"%s\" failed", | 172 ngx_close_file_n " \"%s\" failed", |
173 r->file.name.data); | 173 r->file.name.data); |
179 } | 179 } |
180 | 180 |
181 r->file.info_valid = 1; | 181 r->file.info_valid = 1; |
182 } | 182 } |
183 | 183 |
184 if (ngx_is_dir((&r->file.info))) { | 184 if (ngx_is_dir(&r->file.info)) { |
185 ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data); | 185 ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data); |
186 | 186 |
187 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) { | 187 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) { |
188 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno, | 188 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno, |
189 ngx_close_file_n " \"%s\" failed", r->file.name.data); | 189 ngx_close_file_n " \"%s\" failed", r->file.name.data); |
208 return NGX_HTTP_MOVED_PERMANENTLY; | 208 return NGX_HTTP_MOVED_PERMANENTLY; |
209 } | 209 } |
210 | 210 |
211 #if !(WIN32) /* the not regular files are probably Unix specific */ | 211 #if !(WIN32) /* the not regular files are probably Unix specific */ |
212 | 212 |
213 if (!ngx_is_file((&r->file.info))) { | 213 if (!ngx_is_file(&r->file.info)) { |
214 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, | 214 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, |
215 "%s is not a regular file", r->file.name.data); | 215 "%s is not a regular file", r->file.name.data); |
216 | 216 |
217 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) | 217 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) |
218 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno, | 218 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno, |
270 return rc; | 270 return rc; |
271 } | 271 } |
272 } | 272 } |
273 | 273 |
274 if (!r->file.info_valid) { | 274 if (!r->file.info_valid) { |
275 if (ngx_stat_fd(r->file.fd, &r->file.info) == NGX_FILE_ERROR) { | 275 if (ngx_fd_info(r->file.fd, &r->file.info) == NGX_FILE_ERROR) { |
276 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, | 276 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, |
277 ngx_stat_fd_n " %s failed", r->file.name.data); | 277 ngx_fd_info_n " %s failed", r->file.name.data); |
278 | 278 |
279 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) | 279 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) |
280 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno, | 280 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno, |
281 ngx_close_file_n " %s failed", r->file.name.data); | 281 ngx_close_file_n " %s failed", r->file.name.data); |
282 | 282 |
285 | 285 |
286 r->file.info_valid = 1; | 286 r->file.info_valid = 1; |
287 } | 287 } |
288 | 288 |
289 r->headers_out.status = NGX_HTTP_OK; | 289 r->headers_out.status = NGX_HTTP_OK; |
290 r->headers_out.content_length_n = ngx_file_size((&r->file.info)); | 290 r->headers_out.content_length_n = ngx_file_size(&r->file.info); |
291 r->headers_out.last_modified_time = ngx_file_mtime((&r->file.info)); | 291 r->headers_out.last_modified_time = ngx_file_mtime(&r->file.info); |
292 | 292 |
293 if (!(r->headers_out.content_type = | 293 if (!(r->headers_out.content_type = |
294 ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) | 294 ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) |
295 { | 295 { |
296 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 296 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
342 } | 342 } |
343 | 343 |
344 h->type = r->main ? NGX_HUNK_FILE : NGX_HUNK_FILE|NGX_HUNK_LAST; | 344 h->type = r->main ? NGX_HUNK_FILE : NGX_HUNK_FILE|NGX_HUNK_LAST; |
345 | 345 |
346 h->file_pos = 0; | 346 h->file_pos = 0; |
347 h->file_last = ngx_file_size((&r->file.info)); | 347 h->file_last = ngx_file_size(&r->file.info); |
348 | 348 |
349 h->file->fd = r->file.fd; | 349 h->file->fd = r->file.fd; |
350 h->file->log = r->connection->log; | 350 h->file->log = r->connection->log; |
351 | 351 |
352 out.hunk = h; | 352 out.hunk = h; |