Mercurial > hg > nginx
comparison src/http/ngx_http_core.c @ 26:53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 15 Dec 2002 06:25:09 +0000 |
parents | 77c7629a2627 |
children | a117a7fdf042 |
comparison
equal
deleted
inserted
replaced
25:a8b156554dfe | 26:53cb81681040 |
---|---|
16 static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool); | 16 static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool); |
17 static void *ngx_http_core_create_loc_conf(ngx_pool_t *pool); | 17 static void *ngx_http_core_create_loc_conf(ngx_pool_t *pool); |
18 static int ngx_http_core_translate_handler(ngx_http_request_t *r); | 18 static int ngx_http_core_translate_handler(ngx_http_request_t *r); |
19 | 19 |
20 | 20 |
21 static ngx_command_t ngx_http_core_commands[]; | |
22 | |
23 | |
24 ngx_http_module_t ngx_http_core_module = { | |
25 NGX_HTTP_MODULE, | |
26 | |
27 ngx_http_core_create_srv_conf, /* create server config */ | |
28 ngx_http_core_create_loc_conf, /* create location config */ | |
29 ngx_http_core_commands, /* module directives */ | |
30 | |
31 /* STUB */ NULL, /* init module */ | |
32 ngx_http_core_translate_handler, /* translate handler */ | |
33 | |
34 NULL /* init output body filter */ | |
35 }; | |
36 | |
37 | |
38 static ngx_command_t ngx_http_core_commands[] = { | 21 static ngx_command_t ngx_http_core_commands[] = { |
39 | 22 |
40 {"send_timeout", ngx_conf_set_time_slot, | 23 {"send_timeout", ngx_conf_set_time_slot, |
41 offsetof(ngx_http_core_loc_conf_t, send_timeout), | 24 offsetof(ngx_http_core_loc_conf_t, send_timeout), |
42 NGX_HTTP_LOC_CONF, NGX_CONF_TAKE1, | 25 NGX_HTTP_LOC_CONF, NGX_CONF_TAKE1, |
43 "set timeout for sending response"}, | 26 "set timeout for sending response"}, |
44 | 27 |
45 {NULL} | 28 {NULL} |
46 | 29 |
30 }; | |
31 | |
32 | |
33 ngx_http_module_t ngx_http_core_module = { | |
34 NGX_HTTP_MODULE, | |
35 | |
36 ngx_http_core_create_srv_conf, /* create server config */ | |
37 ngx_http_core_create_loc_conf, /* create location config */ | |
38 ngx_http_core_commands, /* module directives */ | |
39 | |
40 /* STUB */ NULL, /* init module */ | |
41 ngx_http_core_translate_handler, /* translate handler */ | |
42 | |
43 NULL /* init output body filter */ | |
47 }; | 44 }; |
48 | 45 |
49 | 46 |
50 int ngx_http_handler(ngx_http_request_t *r) | 47 int ngx_http_handler(ngx_http_request_t *r) |
51 { | 48 { |
93 /* STUB */ r->handler = ngx_http_index_handler; | 90 /* STUB */ r->handler = ngx_http_index_handler; |
94 | 91 |
95 return NGX_OK; | 92 return NGX_OK; |
96 } | 93 } |
97 | 94 |
98 r->filename.len = r->server->doc_root_len + r->uri.len + 2; | 95 r->file.name.len = r->server->doc_root_len + r->uri.len + 2; |
99 | 96 |
100 ngx_test_null(r->filename.data, | 97 ngx_test_null(r->file.name.data, |
101 ngx_palloc(r->pool, r->filename.len + 1), | 98 ngx_palloc(r->pool, r->file.name.len + 1), |
102 NGX_HTTP_INTERNAL_SERVER_ERROR); | 99 NGX_HTTP_INTERNAL_SERVER_ERROR); |
103 | 100 |
104 loc = ngx_cpystrn(r->filename.data, r->server->doc_root, | 101 loc = ngx_cpystrn(r->file.name.data, r->server->doc_root, |
105 r->server->doc_root_len); | 102 r->server->doc_root_len); |
106 last = ngx_cpystrn(loc, r->uri.data, r->uri.len + 1); | 103 last = ngx_cpystrn(loc, r->uri.data, r->uri.len + 1); |
107 | 104 |
108 ngx_log_debug(r->connection->log, "HTTP filename: '%s'" _ r->filename.data); | 105 ngx_log_debug(r->connection->log, "HTTP filename: '%s'" _ |
109 | 106 r->file.name.data); |
110 if (ngx_file_type(r->filename.data, &r->fileinfo) == -1) { | 107 |
108 #if (WIN32) | |
109 | |
110 /* There is no way to open file or directory in Win32 with | |
111 one syscall: CreateFile() returns ERROR_ACCESS_DENIED on directory, | |
112 so we need to check its type before opening */ | |
113 | |
114 #if 0 /* OLD: ngx_file_type() is to be removed */ | |
115 if (ngx_file_type(r->file.name.data, &r->file.info) == -1) { | |
116 #endif | |
117 | |
118 r->file.info.dwFileAttributes = GetFileAttributes(r->file.name.data); | |
119 if (r->file.info.dwFileAttributes == INVALID_FILE_ATTRIBUTES) { | |
111 err = ngx_errno; | 120 err = ngx_errno; |
112 ngx_log_error(NGX_LOG_ERR, r->connection->log, err, | 121 ngx_log_error(NGX_LOG_ERR, r->connection->log, err, |
113 ngx_file_type_n " %s failed", r->filename.data); | 122 "ngx_http_core_translate_handler: " |
123 ngx_file_type_n " %s failed", r->file.name.data); | |
124 | |
125 if (err == ERROR_FILE_NOT_FOUND) | |
126 return NGX_HTTP_NOT_FOUND; | |
127 else if (err == ERROR_PATH_NOT_FOUND) | |
128 return NGX_HTTP_NOT_FOUND; | |
129 else | |
130 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
131 } | |
132 | |
133 #else | |
134 | |
135 if (r->file.fd == NGX_INVALID_FILE) | |
136 r->file.fd = ngx_open_file(r->file.name.data, NGX_FILE_RDONLY); | |
137 | |
138 if (r->file.fd == NGX_INVALID_FILE) { | |
139 err = ngx_errno; | |
140 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, | |
141 "ngx_http_static_handler: " | |
142 ngx_open_file_n " %s failed", r->file.name.data); | |
114 | 143 |
115 if (err == NGX_ENOENT) | 144 if (err == NGX_ENOENT) |
116 return NGX_HTTP_NOT_FOUND; | 145 return NGX_HTTP_NOT_FOUND; |
117 else | 146 else |
118 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 147 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
119 } | 148 } |
120 | 149 |
121 if (ngx_is_dir(r->fileinfo)) { | 150 if (!r->file.info_valid) { |
122 ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->filename.data); | 151 if (ngx_stat_fd(r->file.fd, &r->file.info) == NGX_FILE_ERROR) { |
152 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, | |
153 "ngx_http_static_handler: " | |
154 ngx_stat_fd_n " %s failed", r->file.name.data); | |
155 | |
156 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) | |
157 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, | |
158 "ngx_http_static_handler: " | |
159 ngx_close_file_n " %s failed", r->file.name.data); | |
160 | |
161 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
162 } | |
163 | |
164 r->file.info_valid = 1; | |
165 } | |
166 #endif | |
167 | |
168 if (ngx_is_dir(r->file.info)) { | |
169 ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data); | |
170 | |
171 #if !(WIN32) | |
172 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) | |
173 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, | |
174 "ngx_http_static_handler: " | |
175 ngx_close_file_n " %s failed", r->file.name.data); | |
176 #endif | |
123 | 177 |
124 /* BROKEN: need to include server name */ | 178 /* BROKEN: need to include server name */ |
125 | 179 |
126 ngx_test_null(h, ngx_push_table(r->headers_out.headers), | 180 ngx_test_null(h, ngx_push_table(r->headers_out.headers), |
127 NGX_HTTP_INTERNAL_SERVER_ERROR); | 181 NGX_HTTP_INTERNAL_SERVER_ERROR); |
142 | 196 |
143 return NGX_OK; | 197 return NGX_OK; |
144 } | 198 } |
145 | 199 |
146 | 200 |
201 int ngx_http_send_header(ngx_http_request_t *r) | |
202 { | |
203 return (*ngx_http_top_header_filter)(r); | |
204 } | |
205 | |
147 | 206 |
148 int ngx_http_redirect(ngx_http_request_t *r, int redirect) | 207 int ngx_http_redirect(ngx_http_request_t *r, int redirect) |
149 { | 208 { |
150 /* STUB */ | 209 /* STUB */ |
151 | 210 |
160 /* STUB */ | 219 /* STUB */ |
161 ngx_log_debug(r->connection->log, "http error: %d" _ error); | 220 ngx_log_debug(r->connection->log, "http error: %d" _ error); |
162 | 221 |
163 /* log request */ | 222 /* log request */ |
164 | 223 |
224 ngx_http_special_response(r, error); | |
165 return ngx_http_close_request(r); | 225 return ngx_http_close_request(r); |
166 } | 226 } |
167 | 227 |
168 | 228 |
169 int ngx_http_close_request(ngx_http_request_t *r) | 229 int ngx_http_close_request(ngx_http_request_t *r) |
170 { | 230 { |
171 ngx_assert((r->fd != -1), /* void */; , r->connection->log, | 231 ngx_log_debug(r->connection->log, "CLOSE#: %d" _ r->file.fd); |
172 "file already closed"); | 232 |
173 | 233 ngx_http_log_handler(r); |
174 if (r->fd != -1) { | 234 |
175 if (ngx_close_file(r->fd) == -1) | 235 ngx_assert((r->file.fd != NGX_INVALID_FILE), /* void */ ; , |
236 r->connection->log, "file already closed"); | |
237 | |
238 if (r->file.fd != NGX_INVALID_FILE) { | |
239 /* STUB WIN32 */ | |
240 #if (WIN32) | |
241 if (ngx_close_file(r->file.fd) == 0) | |
242 #else | |
243 if (ngx_close_file(r->file.fd) == -1) | |
244 #endif | |
176 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, | 245 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, |
177 ngx_close_file_n " failed"); | 246 ngx_close_file_n " failed"); |
178 } | 247 } |
179 | 248 |
180 /* | 249 /* |