comparison src/http/ngx_http_special_response.c @ 176:c0552e5ab567

nginx-0.0.1-2003-11-09-23:03:38 import; separate building
author Igor Sysoev <igor@sysoev.ru>
date Sun, 09 Nov 2003 20:03:38 +0000
parents 894a01c6aea3
children 9f3a78b06c48
comparison
equal deleted inserted replaced
175:e92c2c647c57 176:c0552e5ab567
166 }; 166 };
167 167
168 168
169 int ngx_http_special_response_handler(ngx_http_request_t *r, int error) 169 int ngx_http_special_response_handler(ngx_http_request_t *r, int error)
170 { 170 {
171 int err, rc; 171 int err, rc, i;
172 ngx_hunk_t *h; 172 ngx_hunk_t *h;
173 ngx_chain_t *out, **ll, *cl; 173 ngx_chain_t *out, **ll, *cl;
174 ngx_http_err_page_t *err_page;
174 ngx_http_core_loc_conf_t *clcf; 175 ngx_http_core_loc_conf_t *clcf;
175 176
176 rc = ngx_http_discard_body(r); 177 rc = ngx_http_discard_body(r);
177 178
178 if (rc != NGX_OK) { 179 if (rc != NGX_OK) {
179 return rc; 180 return rc;
180 } 181 }
181 182
182 r->headers_out.status = error; 183 r->headers_out.status = error;
183
184 if (error < NGX_HTTP_BAD_REQUEST) {
185 /* 3XX */
186 err = error - NGX_HTTP_MOVED_PERMANENTLY;
187
188 } else if (error < NGX_HTTP_INTERNAL_SERVER_ERROR) {
189 /* 4XX */
190 err = error - NGX_HTTP_BAD_REQUEST + 3;
191
192 } else {
193 /* 5XX */
194 err = error - NGX_HTTP_INTERNAL_SERVER_ERROR + 3 + 17;
195 }
196 184
197 if (r->keepalive != 0) { 185 if (r->keepalive != 0) {
198 switch (error) { 186 switch (error) {
199 case NGX_HTTP_BAD_REQUEST: 187 case NGX_HTTP_BAD_REQUEST:
200 case NGX_HTTP_REQUEST_ENTITY_TOO_LARGE: 188 case NGX_HTTP_REQUEST_ENTITY_TOO_LARGE:
211 case NGX_HTTP_INTERNAL_SERVER_ERROR: 199 case NGX_HTTP_INTERNAL_SERVER_ERROR:
212 r->lingering_close = 0; 200 r->lingering_close = 0;
213 } 201 }
214 } 202 }
215 203
204 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
205
206 if (!r->error_page && clcf->error_pages) {
207 err_page = clcf->error_pages->elts;
208 for (i = 0; i < clcf->error_pages->nelts; i++) {
209 if (err_page[i].code == error) {
210 r->error_page = 1;
211 return ngx_http_internal_redirect(r, &err_page[i].uri, NULL);
212 }
213 }
214 }
215
216 if (error < NGX_HTTP_BAD_REQUEST) {
217 /* 3XX */
218 err = error - NGX_HTTP_MOVED_PERMANENTLY;
219
220 } else if (error < NGX_HTTP_INTERNAL_SERVER_ERROR) {
221 /* 4XX */
222 err = error - NGX_HTTP_BAD_REQUEST + 3;
223
224 } else {
225 /* 5XX */
226 err = error - NGX_HTTP_INTERNAL_SERVER_ERROR + 3 + 17;
227 }
228
216 if (error_pages[err].len) { 229 if (error_pages[err].len) {
217 r->headers_out.content_length_n = error_pages[err].len 230 r->headers_out.content_length_n = error_pages[err].len
218 + sizeof(error_tail) - 1 231 + sizeof(error_tail) - 1
219 + sizeof(msie_stub) - 1; 232 + sizeof(msie_stub) - 1;
220 233
269 h->pos = error_tail; 282 h->pos = error_tail;
270 h->last = error_tail + sizeof(error_tail) - 1; 283 h->last = error_tail + sizeof(error_tail) - 1;
271 284
272 ngx_alloc_link_and_set_hunk(cl, h, r->pool, NGX_ERROR); 285 ngx_alloc_link_and_set_hunk(cl, h, r->pool, NGX_ERROR);
273 ngx_chain_add_link(out, ll, cl); 286 ngx_chain_add_link(out, ll, cl);
274
275 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
276 287
277 if (clcf->msie_padding 288 if (clcf->msie_padding
278 && r->http_version >= NGX_HTTP_VERSION_10 289 && r->http_version >= NGX_HTTP_VERSION_10
279 && error >= NGX_HTTP_BAD_REQUEST 290 && error >= NGX_HTTP_BAD_REQUEST
280 && error != NGX_HTTP_REQUEST_URI_TOO_LARGE 291 && error != NGX_HTTP_REQUEST_URI_TOO_LARGE