comparison src/http/modules/ngx_http_static_handler.c @ 160:e7e094d34162

nginx-0.0.1-2003-10-27-11:53:49 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 27 Oct 2003 08:53:49 +0000
parents c71aeb75c071
children 894a01c6aea3
comparison
equal deleted inserted replaced
159:981e4af2a425 160:e7e094d34162
86 #if (WIN9X) 86 #if (WIN9X)
87 87
88 /* 88 /*
89 * There is no way to open a file or a directory in Win9X with 89 * There is no way to open a file or a directory in Win9X with
90 * one syscall: Win9X has no FILE_FLAG_BACKUP_SEMANTICS flag. 90 * one syscall: Win9X has no FILE_FLAG_BACKUP_SEMANTICS flag.
91 * so we need to check its type before the opening 91 * So we need to check its type before the opening
92 */ 92 */
93 93
94 r->file.info.dwFileAttributes = GetFileAttributes(r->file.name.data); 94 r->file.info.dwFileAttributes = GetFileAttributes(r->file.name.data);
95 if (r->file.info.dwFileAttributes == INVALID_FILE_ATTRIBUTES) { 95 if (r->file.info.dwFileAttributes == INVALID_FILE_ATTRIBUTES) {
96 err = ngx_errno; 96 err = ngx_errno;
149 return NGX_HTTP_INTERNAL_SERVER_ERROR; 149 return NGX_HTTP_INTERNAL_SERVER_ERROR;
150 } 150 }
151 151
152 r->file.info_valid = 1; 152 r->file.info_valid = 1;
153 } 153 }
154
155 #if !(WIN32) /* the not regular files are probably Unix specific */
156
157 if (!ngx_is_file(r->file.info)) {
158 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
159 "%s is not a regular file", r->file.name.data);
160
161 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR)
162 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
163 ngx_close_file_n " %s failed", r->file.name.data);
164
165 return NGX_HTTP_NOT_FOUND;
166 }
167
168 #endif
154 #endif 169 #endif
155 170
156 if (ngx_is_dir(r->file.info)) { 171 if (ngx_is_dir(r->file.info)) {
157 ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data); 172 ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data);
158 173
161 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno, 176 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
162 ngx_close_file_n " \"%s\" failed", r->file.name.data); 177 ngx_close_file_n " \"%s\" failed", r->file.name.data);
163 } 178 }
164 179
165 r->file.fd = NGX_INVALID_FILE; 180 r->file.fd = NGX_INVALID_FILE;
181 r->file.info_valid = 0;
166 #endif 182 #endif
167 183
168 ngx_test_null(h, ngx_push_table(r->headers_out.headers), 184 ngx_test_null(h, ngx_push_table(r->headers_out.headers),
169 NGX_HTTP_INTERNAL_SERVER_ERROR); 185 NGX_HTTP_INTERNAL_SERVER_ERROR);
170 186
201 if (rc != NGX_OK) { 217 if (rc != NGX_OK) {
202 return rc; 218 return rc;
203 } 219 }
204 220
205 ctx = r->connection->log->data; 221 ctx = r->connection->log->data;
206 ctx->action = "sending response"; 222 ctx->action = "sending response to client";
207 223
208 if (r->file.fd == NGX_INVALID_FILE) { 224 if (r->file.fd == NGX_INVALID_FILE) {
209 r->file.fd = ngx_open_file(r->file.name.data, 225 r->file.fd = ngx_open_file(r->file.name.data,
210 NGX_FILE_RDONLY, NGX_FILE_OPEN); 226 NGX_FILE_RDONLY, NGX_FILE_OPEN);
211 227
239 return NGX_HTTP_INTERNAL_SERVER_ERROR; 255 return NGX_HTTP_INTERNAL_SERVER_ERROR;
240 } 256 }
241 257
242 r->file.info_valid = 1; 258 r->file.info_valid = 1;
243 } 259 }
244
245 #if !(WIN32) /* the not regular files are probably Unix specific */
246
247 if (!ngx_is_file(r->file.info)) {
248 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
249 "%s is not regular file", r->file.name.data);
250
251 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR)
252 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
253 ngx_close_file_n " %s failed", r->file.name.data);
254
255 return NGX_HTTP_NOT_FOUND;
256 }
257
258 #endif
259 260
260 r->headers_out.status = NGX_HTTP_OK; 261 r->headers_out.status = NGX_HTTP_OK;
261 r->headers_out.content_length_n = ngx_file_size(r->file.info); 262 r->headers_out.content_length_n = ngx_file_size(r->file.info);
262 r->headers_out.last_modified_time = ngx_file_mtime(r->file.info); 263 r->headers_out.last_modified_time = ngx_file_mtime(r->file.info);
263 264