Mercurial > hg > nginx
comparison src/http/ngx_http_core.c @ 41:59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 26 Dec 2002 16:26:23 +0000 |
parents | 83fa61cd3d2f |
children | cd035a94e0b6 |
comparison
equal
deleted
inserted
replaced
40:d5d4f3bba6f0 | 41:59e7c7f30d49 |
---|---|
5 #include <ngx_http.h> | 5 #include <ngx_http.h> |
6 #include <ngx_http_core.h> | 6 #include <ngx_http_core.h> |
7 #include <ngx_http_config.h> | 7 #include <ngx_http_config.h> |
8 | 8 |
9 /* STUB */ | 9 /* STUB */ |
10 #include <ngx_http_output_filter.h> | |
11 int ngx_http_static_handler(ngx_http_request_t *r); | 10 int ngx_http_static_handler(ngx_http_request_t *r); |
12 int ngx_http_index_handler(ngx_http_request_t *r); | 11 int ngx_http_index_handler(ngx_http_request_t *r); |
13 int ngx_http_proxy_handler(ngx_http_request_t *r); | 12 int ngx_http_proxy_handler(ngx_http_request_t *r); |
14 /**/ | 13 /**/ |
15 | 14 |
16 static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool); | 15 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); | 16 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); | 17 static int ngx_http_core_translate_handler(ngx_http_request_t *r); |
19 | 18 |
20 | 19 |
20 int (*ngx_http_top_header_filter) (ngx_http_request_t *r); | |
21 | |
22 int ngx_http_max_module; | |
23 | |
24 | |
21 static ngx_command_t ngx_http_core_commands[] = { | 25 static ngx_command_t ngx_http_core_commands[] = { |
22 | 26 |
23 {"send_timeout", ngx_conf_set_time_slot, | 27 {ngx_string("send_timeout"), |
24 offsetof(ngx_http_core_loc_conf_t, send_timeout), | 28 NGX_CONF_TAKE1, |
25 NGX_HTTP_LOC_CONF, NGX_CONF_TAKE1, | 29 ngx_conf_set_time_slot, |
26 "set timeout for sending response"}, | 30 NGX_HTTP_LOC_CONF, |
27 | 31 offsetof(ngx_http_core_loc_conf_t, send_timeout)}, |
28 {NULL} | 32 |
29 | 33 {ngx_string(""), 0, NULL, 0, 0} |
30 }; | 34 }; |
31 | 35 |
32 | 36 |
33 ngx_http_module_t ngx_http_core_module = { | 37 ngx_http_module_t ngx_http_core_module_ctx = { |
34 NGX_HTTP_MODULE, | 38 NGX_HTTP_MODULE, |
35 | 39 |
36 ngx_http_core_create_srv_conf, /* create server config */ | 40 ngx_http_core_create_srv_conf, /* create server config */ |
37 ngx_http_core_create_loc_conf, /* create location config */ | 41 ngx_http_core_create_loc_conf, /* create location config */ |
42 | |
43 ngx_http_core_translate_handler, /* translate handler */ | |
44 | |
45 NULL, /* output header filter */ | |
46 NULL, /* next output header filter */ | |
47 NULL, /* output body filter */ | |
48 NULL, /* next output body filter */ | |
49 }; | |
50 | |
51 | |
52 ngx_module_t ngx_http_core_module = { | |
53 &ngx_http_core_module_ctx, /* module context */ | |
38 ngx_http_core_commands, /* module directives */ | 54 ngx_http_core_commands, /* module directives */ |
39 | 55 NGX_HTTP_MODULE_TYPE, /* module type */ |
40 /* STUB */ NULL, /* init module */ | 56 NULL /* init module */ |
41 ngx_http_core_translate_handler, /* translate handler */ | |
42 | |
43 NULL /* init output body filter */ | |
44 }; | 57 }; |
45 | 58 |
46 | 59 |
47 int ngx_http_handler(ngx_http_request_t *r) | 60 int ngx_http_handler(ngx_http_request_t *r) |
48 { | 61 { |
49 int rc, i; | 62 int rc, i; |
63 ngx_http_module_t *module; | |
50 | 64 |
51 r->connection->unexpected_eof = 0; | 65 r->connection->unexpected_eof = 0; |
52 r->lingering_close = 1; | 66 r->lingering_close = 1; |
53 r->keepalive = 0; | 67 r->keepalive = 0; |
54 | 68 |
55 #if 1 | 69 #if 0 |
56 r->filter = NGX_HTTP_FILTER_NEED_IN_MEMORY; | 70 r->filter = NGX_HTTP_FILTER_NEED_IN_MEMORY; |
57 #endif | 71 #endif |
58 | 72 |
59 /* run translation phase */ | 73 /* run translation phase */ |
60 for (i = 0; ngx_http_modules[i]; i++) { | 74 for (i = 0; ngx_modules[i]; i++) { |
61 if (ngx_http_modules[i]->translate_handler) { | 75 if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) { |
62 rc = ngx_http_modules[i]->translate_handler(r); | 76 continue; |
63 if (rc == NGX_OK) | 77 } |
64 break; | 78 |
65 | 79 module = (ngx_http_module_t *) ngx_modules[i]->ctx; |
66 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) | 80 if (module->translate_handler == NULL) { |
67 return ngx_http_special_response(r, rc); | 81 continue; |
82 } | |
83 | |
84 rc = module->translate_handler(r); | |
85 if (rc == NGX_OK) { | |
86 break; | |
87 } | |
88 | |
89 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | |
90 return ngx_http_special_response(r, rc); | |
68 } | 91 } |
69 } | 92 } |
70 | 93 |
71 rc = r->handler(r); | 94 rc = r->handler(r); |
72 | 95 |
73 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) | 96 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
74 return ngx_http_special_response(r, rc); | 97 return ngx_http_special_response(r, rc); |
98 } | |
75 | 99 |
76 return rc; | 100 return rc; |
77 } | 101 } |
78 | 102 |
79 | 103 |
120 err = ngx_errno; | 144 err = ngx_errno; |
121 ngx_log_error(NGX_LOG_ERR, r->connection->log, err, | 145 ngx_log_error(NGX_LOG_ERR, r->connection->log, err, |
122 "ngx_http_core_translate_handler: " | 146 "ngx_http_core_translate_handler: " |
123 ngx_file_type_n " %s failed", r->file.name.data); | 147 ngx_file_type_n " %s failed", r->file.name.data); |
124 | 148 |
125 if (err == ERROR_FILE_NOT_FOUND) | 149 if (err == ERROR_FILE_NOT_FOUND) { |
126 return NGX_HTTP_NOT_FOUND; | 150 return NGX_HTTP_NOT_FOUND; |
127 else if (err == ERROR_PATH_NOT_FOUND) | 151 } else if (err == ERROR_PATH_NOT_FOUND) { |
128 return NGX_HTTP_NOT_FOUND; | 152 return NGX_HTTP_NOT_FOUND; |
129 else | 153 } else { |
130 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 154 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
155 } | |
131 } | 156 } |
132 | 157 |
133 #else | 158 #else |
134 | 159 |
135 if (r->file.fd == NGX_INVALID_FILE) | 160 if (r->file.fd == NGX_INVALID_FILE) { |
136 r->file.fd = ngx_open_file(r->file.name.data, NGX_FILE_RDONLY); | 161 r->file.fd = ngx_open_file(r->file.name.data, NGX_FILE_RDONLY); |
162 } | |
137 | 163 |
138 if (r->file.fd == NGX_INVALID_FILE) { | 164 if (r->file.fd == NGX_INVALID_FILE) { |
139 err = ngx_errno; | 165 err = ngx_errno; |
140 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, | 166 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, |
141 "ngx_http_core_handler: " | 167 "ngx_http_core_handler: " |
142 ngx_open_file_n " %s failed", r->file.name.data); | 168 ngx_open_file_n " %s failed", r->file.name.data); |
143 | 169 |
144 if (err == NGX_ENOENT) | 170 if (err == NGX_ENOENT) { |
145 return NGX_HTTP_NOT_FOUND; | 171 return NGX_HTTP_NOT_FOUND; |
146 else | 172 } else { |
147 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 173 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
174 } | |
148 } | 175 } |
149 | 176 |
150 if (!r->file.info_valid) { | 177 if (!r->file.info_valid) { |
151 if (ngx_stat_fd(r->file.fd, &r->file.info) == NGX_FILE_ERROR) { | 178 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, | 179 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, |
153 "ngx_http_core_handler: " | 180 "ngx_http_core_handler: " |
154 ngx_stat_fd_n " %s failed", r->file.name.data); | 181 ngx_stat_fd_n " %s failed", r->file.name.data); |
155 | 182 |
156 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) | 183 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) { |
157 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, | 184 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, |
158 "ngx_http_core_handler: " | 185 "ngx_http_core_handler: " |
159 ngx_close_file_n " %s failed", r->file.name.data); | 186 ngx_close_file_n " %s failed", r->file.name.data); |
187 } | |
160 | 188 |
161 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 189 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
162 } | 190 } |
163 | 191 |
164 r->file.info_valid = 1; | 192 r->file.info_valid = 1; |
167 | 195 |
168 if (ngx_is_dir(r->file.info)) { | 196 if (ngx_is_dir(r->file.info)) { |
169 ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data); | 197 ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data); |
170 | 198 |
171 #if !(WIN9X) | 199 #if !(WIN9X) |
172 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) | 200 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) { |
173 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, | 201 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, |
174 "ngx_http_core_handler: " | 202 "ngx_http_core_handler: " |
175 ngx_close_file_n " %s failed", r->file.name.data); | 203 ngx_close_file_n " %s failed", r->file.name.data); |
204 } | |
176 #endif | 205 #endif |
177 | 206 |
178 /* BROKEN: need to include server name */ | 207 /* BROKEN: need to include server name */ |
179 | 208 |
180 ngx_test_null(h, ngx_push_table(r->headers_out.headers), | 209 ngx_test_null(h, ngx_push_table(r->headers_out.headers), |