comparison src/http/modules/ngx_http_static_handler.c @ 183:4c698194c56d

nginx-0.0.1-2003-11-13-19:16:33 import
author Igor Sysoev <igor@sysoev.ru>
date Thu, 13 Nov 2003 16:16:33 +0000
parents 4db54fdbcbe7
children d5f50cefc322
comparison
equal deleted inserted replaced
182:3c49eaf3f522 183:4c698194c56d
85 85
86 ngx_log_debug(r->connection->log, "HTTP filename: '%s'" _ r->file.name.data); 86 ngx_log_debug(r->connection->log, "HTTP filename: '%s'" _ r->file.name.data);
87 87
88 #if (WIN9X) 88 #if (WIN9X)
89 89
90 /* 90 if (ngx_win32_version < NGX_WIN_NT) {
91 * There is no way to open a file or a directory in Win9X with 91
92 * one syscall: Win9X has no FILE_FLAG_BACKUP_SEMANTICS flag. 92 /*
93 * So we need to check its type before the opening 93 * There is no way to open a file or a directory in Win9X with
94 */ 94 * one syscall: Win9X has no FILE_FLAG_BACKUP_SEMANTICS flag.
95 95 * So we need to check its type before the opening.
96 r->file.info.dwFileAttributes = GetFileAttributes(r->file.name.data); 96 */
97 if (r->file.info.dwFileAttributes == INVALID_FILE_ATTRIBUTES) { 97
98 err = ngx_errno; 98 r->file.info.dwFileAttributes = GetFileAttributes(r->file.name.data);
99 ngx_log_error(NGX_LOG_ERR, r->connection->log, err, 99 if (r->file.info.dwFileAttributes == INVALID_FILE_ATTRIBUTES) {
100 ngx_file_type_n " \"%s\" failed", r->file.name.data); 100 err = ngx_errno;
101 101 ngx_log_error(NGX_LOG_ERR, r->connection->log, err,
102 if (err == NGX_ENOENT || err == NGX_ENOTDIR) { 102 ngx_file_type_n " \"%s\" failed", r->file.name.data);
103 return NGX_HTTP_NOT_FOUND; 103
104 104 if (err == NGX_ENOENT || err == NGX_ENOTDIR) {
105 } else if (err == NGX_EACCES) { 105 return NGX_HTTP_NOT_FOUND;
106 return NGX_HTTP_FORBIDDEN; 106
107 107 } else if (err == NGX_EACCES) {
108 } else { 108 return NGX_HTTP_FORBIDDEN;
109 return NGX_HTTP_INTERNAL_SERVER_ERROR; 109
110 } 110 } else {
111 } 111 return NGX_HTTP_INTERNAL_SERVER_ERROR;
112 112 }
113 #else 113 }
114
115 if (ngx_is_dir(r->file.info)) {
116 ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data);
117
118 if (!(r->headers_out.location =
119 ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
120 {
121 return NGX_HTTP_INTERNAL_SERVER_ERROR;
122 }
123
124 *last++ = '/';
125 *last = '\0';
126 r->headers_out.location->key.len = 8;
127 r->headers_out.location->key.data = "Location" ;
128 r->headers_out.location->value.len = last - location;
129 r->headers_out.location->value.data = location;
130
131 return NGX_HTTP_MOVED_PERMANENTLY;
132 }
133 }
134
135 #endif
114 136
115 if (r->file.fd == NGX_INVALID_FILE) { 137 if (r->file.fd == NGX_INVALID_FILE) {
116 r->file.fd = ngx_open_file(r->file.name.data, 138 r->file.fd = ngx_open_file(r->file.name.data,
117 NGX_FILE_RDONLY, NGX_FILE_OPEN); 139 NGX_FILE_RDONLY, NGX_FILE_OPEN);
118 } 140 }
161 } 183 }
162 184
163 if (ngx_is_dir(r->file.info)) { 185 if (ngx_is_dir(r->file.info)) {
164 ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data); 186 ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data);
165 187
166 #if !(WIN9X)
167 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) { 188 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) {
168 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno, 189 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
169 ngx_close_file_n " \"%s\" failed", r->file.name.data); 190 ngx_close_file_n " \"%s\" failed", r->file.name.data);
170 } 191 }
171 192
172 r->file.fd = NGX_INVALID_FILE; 193 r->file.fd = NGX_INVALID_FILE;
173 r->file.info_valid = 0; 194 r->file.info_valid = 0;
174 #endif
175 195
176 if (!(r->headers_out.location = 196 if (!(r->headers_out.location =
177 ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) 197 ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
178 { 198 {
179 return NGX_HTTP_INTERNAL_SERVER_ERROR; 199 return NGX_HTTP_INTERNAL_SERVER_ERROR;
200 ngx_close_file_n " %s failed", r->file.name.data); 220 ngx_close_file_n " %s failed", r->file.name.data);
201 221
202 return NGX_HTTP_NOT_FOUND; 222 return NGX_HTTP_NOT_FOUND;
203 } 223 }
204 224
205 #endif
206 #endif 225 #endif
207 226
208 r->content_handler = ngx_http_static_handler; 227 r->content_handler = ngx_http_static_handler;
209 228
210 return NGX_OK; 229 return NGX_OK;