~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Nginx/http/ngx_http_special_response.c

Version: ~ [ nginx-0.8.20 ] ~ [ nginx-0.7.62 ] ~ [ nginx-0.6.39 ] ~

  1 
  2 /*
  3  * Copyright (C) Igor Sysoev
  4  */
  5 
  6 
  7 #include <ngx_config.h>
  8 #include <ngx_core.h>
  9 #include <ngx_http.h>
 10 #include <nginx.h>
 11 
 12 
 13 static ngx_int_t ngx_http_send_error_page(ngx_http_request_t *r,
 14     ngx_http_err_page_t *err_page);
 15 static ngx_int_t ngx_http_send_special_response(ngx_http_request_t *r,
 16     ngx_http_core_loc_conf_t *clcf, ngx_uint_t err);
 17 static ngx_int_t ngx_http_send_refresh(ngx_http_request_t *r);
 18 
 19 
 20 static u_char ngx_http_error_full_tail[] =
 21 "<hr><center>" NGINX_VER "</center>" CRLF
 22 "</body>" CRLF
 23 "</html>" CRLF
 24 ;
 25 
 26 
 27 static u_char ngx_http_error_tail[] =
 28 "<hr><center>nginx</center>" CRLF
 29 "</body>" CRLF
 30 "</html>" CRLF
 31 ;
 32 
 33 
 34 static u_char ngx_http_msie_stub[] =
 35 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
 36 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
 37 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
 38 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
 39 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
 40 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
 41 ;
 42 
 43 
 44 static u_char ngx_http_msie_refresh_head[] =
 45 "<html><head><meta http-equiv=\"Refresh\" content=\"0; URL=";
 46 
 47 
 48 static u_char ngx_http_msie_refresh_tail[] =
 49 "\"></head><body></body></html>" CRLF;
 50 
 51 
 52 static char ngx_http_error_301_page[] =
 53 "<html>" CRLF
 54 "<head><title>301 Moved Permanently</title></head>" CRLF
 55 "<body bgcolor=\"white\">" CRLF
 56 "<center><h1>301 Moved Permanently</h1></center>" CRLF
 57 ;
 58 
 59 
 60 static char ngx_http_error_302_page[] =
 61 "<html>" CRLF
 62 "<head><title>302 Found</title></head>" CRLF
 63 "<body bgcolor=\"white\">" CRLF
 64 "<center><h1>302 Found</h1></center>" CRLF
 65 ;
 66 
 67 
 68 static char ngx_http_error_400_page[] =
 69 "<html>" CRLF
 70 "<head><title>400 Bad Request</title></head>" CRLF
 71 "<body bgcolor=\"white\">" CRLF
 72 "<center><h1>400 Bad Request</h1></center>" CRLF
 73 ;
 74 
 75 
 76 static char ngx_http_error_401_page[] =
 77 "<html>" CRLF
 78 "<head><title>401 Authorization Required</title></head>" CRLF
 79 "<body bgcolor=\"white\">" CRLF
 80 "<center><h1>401 Authorization Required</h1></center>" CRLF
 81 ;
 82 
 83 
 84 static char ngx_http_error_402_page[] =
 85 "<html>" CRLF
 86 "<head><title>402 Payment Required</title></head>" CRLF
 87 "<body bgcolor=\"white\">" CRLF
 88 "<center><h1>402 Payment Required</h1></center>" CRLF
 89 ;
 90 
 91 
 92 static char ngx_http_error_403_page[] =
 93 "<html>" CRLF
 94 "<head><title>403 Forbidden</title></head>" CRLF
 95 "<body bgcolor=\"white\">" CRLF
 96 "<center><h1>403 Forbidden</h1></center>" CRLF
 97 ;
 98 
 99 
100 static char ngx_http_error_404_page[] =
101 "<html>" CRLF
102 "<head><title>404 Not Found</title></head>" CRLF
103 "<body bgcolor=\"white\">" CRLF
104 "<center><h1>404 Not Found</h1></center>" CRLF
105 ;
106 
107 
108 static char ngx_http_error_405_page[] =
109 "<html>" CRLF
110 "<head><title>405 Not Allowed</title></head>" CRLF
111 "<body bgcolor=\"white\">" CRLF
112 "<center><h1>405 Not Allowed</h1></center>" CRLF
113 ;
114 
115 
116 static char ngx_http_error_406_page[] =
117 "<html>" CRLF
118 "<head><title>406 Not Acceptable</title></head>" CRLF
119 "<body bgcolor=\"white\">" CRLF
120 "<center><h1>406 Not Acceptable</h1></center>" CRLF
121 ;
122 
123 
124 static char ngx_http_error_408_page[] =
125 "<html>" CRLF
126 "<head><title>408 Request Time-out</title></head>" CRLF
127 "<body bgcolor=\"white\">" CRLF
128 "<center><h1>408 Request Time-out</h1></center>" CRLF
129 ;
130 
131 
132 static char ngx_http_error_409_page[] =
133 "<html>" CRLF
134 "<head><title>409 Conflict</title></head>" CRLF
135 "<body bgcolor=\"white\">" CRLF
136 "<center><h1>409 Conflict</h1></center>" CRLF
137 ;
138 
139 
140 static char ngx_http_error_410_page[] =
141 "<html>" CRLF
142 "<head><title>410 Gone</title></head>" CRLF
143 "<body bgcolor=\"white\">" CRLF
144 "<center><h1>410 Gone</h1></center>" CRLF
145 ;
146 
147 
148 static char ngx_http_error_411_page[] =
149 "<html>" CRLF
150 "<head><title>411 Length Required</title></head>" CRLF
151 "<body bgcolor=\"white\">" CRLF
152 "<center><h1>411 Length Required</h1></center>" CRLF
153 ;
154 
155 
156 static char ngx_http_error_412_page[] =
157 "<html>" CRLF
158 "<head><title>412 Precondition Failed</title></head>" CRLF
159 "<body bgcolor=\"white\">" CRLF
160 "<center><h1>412 Precondition Failed</h1></center>" CRLF
161 ;
162 
163 
164 static char ngx_http_error_413_page[] =
165 "<html>" CRLF
166 "<head><title>413 Request Entity Too Large</title></head>" CRLF
167 "<body bgcolor=\"white\">" CRLF
168 "<center><h1>413 Request Entity Too Large</h1></center>" CRLF
169 ;
170 
171 
172 static char ngx_http_error_414_page[] =
173 "<html>" CRLF
174 "<head><title>414 Request-URI Too Large</title></head>" CRLF
175 "<body bgcolor=\"white\">" CRLF
176 "<center><h1>414 Request-URI Too Large</h1></center>" CRLF
177 ;
178 
179 
180 static char ngx_http_error_415_page[] =
181 "<html>" CRLF
182 "<head><title>415 Unsupported Media Type</title></head>" CRLF
183 "<body bgcolor=\"white\">" CRLF
184 "<center><h1>415 Unsupported Media Type</h1></center>" CRLF
185 ;
186 
187 
188 static char ngx_http_error_416_page[] =
189 "<html>" CRLF
190 "<head><title>416 Requested Range Not Satisfiable</title></head>" CRLF
191 "<body bgcolor=\"white\">" CRLF
192 "<center><h1>416 Requested Range Not Satisfiable</h1></center>" CRLF
193 ;
194 
195 
196 static char ngx_http_error_495_page[] =
197 "<html>" CRLF
198 "<head><title>400 The SSL certificate error</title></head>"
199 CRLF
200 "<body bgcolor=\"white\">" CRLF
201 "<center><h1>400 Bad Request</h1></center>" CRLF
202 "<center>The SSL certificate error</center>" CRLF
203 ;
204 
205 
206 static char ngx_http_error_496_page[] =
207 "<html>" CRLF
208 "<head><title>400 No required SSL certificate was sent</title></head>"
209 CRLF
210 "<body bgcolor=\"white\">" CRLF
211 "<center><h1>400 Bad Request</h1></center>" CRLF
212 "<center>No required SSL certificate was sent</center>" CRLF
213 ;
214 
215 
216 static char ngx_http_error_497_page[] =
217 "<html>" CRLF
218 "<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>"
219 CRLF
220 "<body bgcolor=\"white\">" CRLF
221 "<center><h1>400 Bad Request</h1></center>" CRLF
222 "<center>The plain HTTP request was sent to HTTPS port</center>" CRLF
223 ;
224 
225 
226 static char ngx_http_error_500_page[] =
227 "<html>" CRLF
228 "<head><title>500 Internal Server Error</title></head>" CRLF
229 "<body bgcolor=\"white\">" CRLF
230 "<center><h1>500 Internal Server Error</h1></center>" CRLF
231 ;
232 
233 
234 static char ngx_http_error_501_page[] =
235 "<html>" CRLF
236 "<head><title>501 Method Not Implemented</title></head>" CRLF
237 "<body bgcolor=\"white\">" CRLF
238 "<center><h1>501 Method Not Implemented</h1></center>" CRLF
239 ;
240 
241 
242 static char ngx_http_error_502_page[] =
243 "<html>" CRLF
244 "<head><title>502 Bad Gateway</title></head>" CRLF
245 "<body bgcolor=\"white\">" CRLF
246 "<center><h1>502 Bad Gateway</h1></center>" CRLF
247 ;
248 
249 
250 static char ngx_http_error_503_page[] =
251 "<html>" CRLF
252 "<head><title>503 Service Temporarily Unavailable</title></head>" CRLF
253 "<body bgcolor=\"white\">" CRLF
254 "<center><h1>503 Service Temporarily Unavailable</h1></center>" CRLF
255 ;
256 
257 
258 static char ngx_http_error_504_page[] =
259 "<html>" CRLF
260 "<head><title>504 Gateway Time-out</title></head>" CRLF
261 "<body bgcolor=\"white\">" CRLF
262 "<center><h1>504 Gateway Time-out</h1></center>" CRLF
263 ;
264 
265 
266 static char ngx_http_error_507_page[] =
267 "<html>" CRLF
268 "<head><title>507 Insufficient Storage</title></head>" CRLF
269 "<body bgcolor=\"white\">" CRLF
270 "<center><h1>507 Insufficient Storage</h1></center>" CRLF
271 ;
272 
273 
274 static ngx_str_t ngx_http_error_pages[] = {
275 
276     ngx_null_string,                     /* 201, 204 */
277 
278 #define NGX_HTTP_LAST_LEVEL_200  202
279 #define NGX_HTTP_LEVEL_200       (NGX_HTTP_LAST_LEVEL_200 - 201)
280 
281     /* ngx_null_string, */               /* 300 */
282     ngx_string(ngx_http_error_301_page),
283     ngx_string(ngx_http_error_302_page),
284     ngx_null_string,                     /* 303 */
285 
286 #define NGX_HTTP_LAST_LEVEL_300  304
287 #define NGX_HTTP_LEVEL_300       (NGX_HTTP_LAST_LEVEL_300 - 301)
288 
289     ngx_string(ngx_http_error_400_page),
290     ngx_string(ngx_http_error_401_page),
291     ngx_string(ngx_http_error_402_page),
292     ngx_string(ngx_http_error_403_page),
293     ngx_string(ngx_http_error_404_page),
294     ngx_string(ngx_http_error_405_page),
295     ngx_string(ngx_http_error_406_page),
296     ngx_null_string,                     /* 407 */
297     ngx_string(ngx_http_error_408_page),
298     ngx_string(ngx_http_error_409_page),
299     ngx_string(ngx_http_error_410_page),
300     ngx_string(ngx_http_error_411_page),
301     ngx_string(ngx_http_error_412_page),
302     ngx_string(ngx_http_error_413_page),
303     ngx_string(ngx_http_error_414_page),
304     ngx_string(ngx_http_error_415_page),
305     ngx_string(ngx_http_error_416_page),
306 
307 #define NGX_HTTP_LAST_LEVEL_400  417
308 #define NGX_HTTP_LEVEL_400       (NGX_HTTP_LAST_LEVEL_400 - 400)
309 
310     ngx_string(ngx_http_error_495_page), /* 495, https certificate error */
311     ngx_string(ngx_http_error_496_page), /* 496, https no certificate */
312     ngx_string(ngx_http_error_497_page), /* 497, http to https */
313     ngx_string(ngx_http_error_404_page), /* 498, canceled */
314     ngx_null_string,                     /* 499, client has closed connection */
315 
316     ngx_string(ngx_http_error_500_page),
317     ngx_string(ngx_http_error_501_page),
318     ngx_string(ngx_http_error_502_page),
319     ngx_string(ngx_http_error_503_page),
320     ngx_string(ngx_http_error_504_page),
321     ngx_null_string,                     /* 505 */
322     ngx_null_string,                     /* 506 */
323     ngx_string(ngx_http_error_507_page)
324 
325 #define NGX_HTTP_LAST_LEVEL_500  508
326 
327 };
328 
329 
330 static ngx_str_t  ngx_http_get_name = { 3, (u_char *) "GET " };
331 
332 
333 ngx_int_t
334 ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
335 {
336     ngx_uint_t                 i, err;
337     ngx_http_err_page_t       *err_page;
338     ngx_http_core_loc_conf_t  *clcf;
339 
340     ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
341                    "http special response: %d, \"%V?%V\"",
342                    error, &r->uri, &r->args);
343 
344     r->err_status = error;
345 
346     if (r->keepalive) {
347         switch (error) {
348             case NGX_HTTP_BAD_REQUEST:
349             case NGX_HTTP_REQUEST_ENTITY_TOO_LARGE:
350             case NGX_HTTP_REQUEST_URI_TOO_LARGE:
351             case NGX_HTTP_TO_HTTPS:
352             case NGX_HTTPS_CERT_ERROR:
353             case NGX_HTTPS_NO_CERT:
354             case NGX_HTTP_INTERNAL_SERVER_ERROR:
355                 r->keepalive = 0;
356         }
357     }
358 
359     if (r->lingering_close == 1) {
360         switch (error) {
361             case NGX_HTTP_BAD_REQUEST:
362             case NGX_HTTP_TO_HTTPS:
363             case NGX_HTTPS_CERT_ERROR:
364             case NGX_HTTPS_NO_CERT:
365                 r->lingering_close = 0;
366         }
367     }
368 
369     r->headers_out.content_type.len = 0;
370 
371     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
372 
373     if (!r->error_page && clcf->error_pages && r->uri_changes != 0) {
374 
375         if (clcf->recursive_error_pages == 0) {
376             r->error_page = 1;
377         }
378 
379         err_page = clcf->error_pages->elts;
380 
381         for (i = 0; i < clcf->error_pages->nelts; i++) {
382             if (err_page[i].status == error) {
383                 return ngx_http_send_error_page(r, &err_page[i]);
384             }
385         }
386     }
387 
388     r->expect_tested = 1;
389 
390     if (ngx_http_discard_request_body(r) != NGX_OK) {
391         error = NGX_HTTP_INTERNAL_SERVER_ERROR;
392     }
393 
394     if (clcf->msie_refresh
395         && r->headers_in.msie
396         && (error == NGX_HTTP_MOVED_PERMANENTLY
397             || error == NGX_HTTP_MOVED_TEMPORARILY))
398     {
399         return ngx_http_send_refresh(r);
400     }
401 
402     if (error == NGX_HTTP_CREATED) {
403         /* 201 */
404         err = 0;
405         r->header_only = 1;
406 
407     } else if (error == NGX_HTTP_NO_CONTENT) {
408         /* 204 */
409         err = 0;
410 
411     } else if (error >= NGX_HTTP_MOVED_PERMANENTLY
412                && error < NGX_HTTP_LAST_LEVEL_300)
413     {
414         /* 3XX */
415         err = error - NGX_HTTP_MOVED_PERMANENTLY + NGX_HTTP_LEVEL_200;
416 
417     } else if (error >= NGX_HTTP_BAD_REQUEST
418                && error < NGX_HTTP_LAST_LEVEL_400)
419     {
420         /* 4XX */
421         err = error - NGX_HTTP_BAD_REQUEST + NGX_HTTP_LEVEL_200
422                                            + NGX_HTTP_LEVEL_300;
423 
424     } else if (error >= NGX_HTTP_OWN_CODES
425                && error < NGX_HTTP_LAST_LEVEL_500)
426     {
427         /* 49X, 5XX */
428         err = error - NGX_HTTP_OWN_CODES + NGX_HTTP_LEVEL_200
429                                          + NGX_HTTP_LEVEL_300
430                                          + NGX_HTTP_LEVEL_400;
431         switch (error) {
432             case NGX_HTTP_TO_HTTPS:
433             case NGX_HTTPS_CERT_ERROR:
434             case NGX_HTTPS_NO_CERT:
435                 r->err_status = NGX_HTTP_BAD_REQUEST;
436                 break;
437         }
438 
439     } else {
440         /* unknown code, zero body */
441         err = 0;
442     }
443 
444     return ngx_http_send_special_response(r, clcf, err);
445 }
446 
447 
448 ngx_int_t
449 ngx_http_filter_finalize_request(ngx_http_request_t *r, ngx_module_t *m,
450     ngx_int_t error)
451 {
452     void       *ctx;
453     ngx_int_t   rc;
454 
455     ngx_http_clean_header(r);
456 
457     ctx = NULL;
458 
459     if (m) {
460         ctx = r->ctx[m->ctx_index];
461     }
462 
463     /* clear the modules contexts */
464     ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
465 
466     if (m) {
467         r->ctx[m->ctx_index] = ctx;
468     }
469 
470     r->filter_finalize = 1;
471 
472     rc = ngx_http_special_response_handler(r, error);
473 
474     /* NGX_ERROR resets any pending data */
475 
476     switch (rc) {
477 
478     case NGX_OK:
479     case NGX_DONE:
480         return NGX_ERROR;
481 
482     default:
483         return rc;
484     }
485 }
486 
487 
488 void
489 ngx_http_clean_header(ngx_http_request_t *r)
490 {
491     ngx_memzero(&r->headers_out.status,
492                 sizeof(ngx_http_headers_out_t)
493                     - offsetof(ngx_http_headers_out_t, status));
494 
495     r->headers_out.headers.part.nelts = 0;
496     r->headers_out.headers.part.next = NULL;
497     r->headers_out.headers.last = &r->headers_out.headers.part;
498 
499     r->headers_out.content_length_n = -1;
500     r->headers_out.last_modified_time = -1;
501 }
502 
503 
504 static ngx_int_t
505 ngx_http_send_error_page(ngx_http_request_t *r, ngx_http_err_page_t *err_page)
506 {
507     ngx_int_t                  overwrite;
508     ngx_str_t                  uri, args;
509     ngx_table_elt_t           *location;
510     ngx_http_core_loc_conf_t  *clcf;
511 
512     overwrite = err_page->overwrite;
513 
514     if (overwrite && overwrite != NGX_HTTP_OK) {
515         r->expect_tested = 1;
516     }
517 
518     r->err_status = overwrite;
519 
520     r->zero_in_uri = 0;
521 
522     if (ngx_http_complex_value(r, &err_page->value, &uri) != NGX_OK) {
523         return NGX_ERROR;
524     }
525 
526     if (uri.data[0] == '/') {
527 
528         if (err_page->value.lengths) {
529             ngx_http_split_args(r, &uri, &args);
530 
531         } else {
532             args = err_page->args;
533         }
534 
535         if (r->method != NGX_HTTP_HEAD) {
536             r->method = NGX_HTTP_GET;
537             r->method_name = ngx_http_get_name;
538         }
539 
540         return ngx_http_internal_redirect(r, &uri, &args);
541     }
542 
543     if (uri.data[0] == '@') {
544         return ngx_http_named_location(r, &uri);
545     }
546 
547     location = ngx_list_push(&r->headers_out.headers);
548 
549     if (location == NULL) {
550         return NGX_ERROR;
551     }
552 
553     r->err_status = NGX_HTTP_MOVED_TEMPORARILY;
554 
555     location->hash = 1;
556     location->key.len = sizeof("Location") - 1;
557     location->key.data = (u_char *) "Location";
558     location->value = uri;
559 
560     r->headers_out.location = location;
561 
562     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
563 
564     if (clcf->msie_refresh && r->headers_in.msie) {
565         return ngx_http_send_refresh(r);
566     }
567 
568     return ngx_http_send_special_response(r, clcf, NGX_HTTP_MOVED_TEMPORARILY
569                                                    - NGX_HTTP_MOVED_PERMANENTLY
570                                                    + NGX_HTTP_LEVEL_200);
571 }
572 
573 
574 static ngx_int_t
575 ngx_http_send_special_response(ngx_http_request_t *r,
576     ngx_http_core_loc_conf_t *clcf, ngx_uint_t err)
577 {
578     u_char       *tail;
579     size_t        len;
580     ngx_int_t     rc;
581     ngx_buf_t    *b;
582     ngx_uint_t    msie_padding;
583     ngx_chain_t   out[3];
584 
585     if (clcf->server_tokens) {
586         len = sizeof(ngx_http_error_full_tail) - 1;
587         tail = ngx_http_error_full_tail;
588 
589     } else {
590         len = sizeof(ngx_http_error_tail) - 1;
591         tail = ngx_http_error_tail;
592     }
593 
594     msie_padding = 0;
595 
596     if (!r->zero_body) {
597         if (ngx_http_error_pages[err].len) {
598             r->headers_out.content_length_n = ngx_http_error_pages[err].len
599                                               + len;
600             if (clcf->msie_padding
601                 && r->headers_in.msie
602                 && r->http_version >= NGX_HTTP_VERSION_10
603                 && err >= NGX_HTTP_LEVEL_300)
604             {
605                 r->headers_out.content_length_n +=
606                                                 sizeof(ngx_http_msie_stub) - 1;
607                 msie_padding = 1;
608             }
609 
610             r->headers_out.content_type_len = sizeof("text/html") - 1;
611             r->headers_out.content_type.len = sizeof("text/html") - 1;
612             r->headers_out.content_type.data = (u_char *) "text/html";
613             r->headers_out.content_type_lowcase = NULL;
614 
615         } else {
616             r->headers_out.content_length_n = -1;
617         }
618 
619     } else {
620         r->headers_out.content_length_n = 0;
621         err = 0;
622     }
623 
624     if (r->headers_out.content_length) {
625         r->headers_out.content_length->hash = 0;
626         r->headers_out.content_length = NULL;
627     }
628 
629     ngx_http_clear_accept_ranges(r);
630     ngx_http_clear_last_modified(r);
631 
632     rc = ngx_http_send_header(r);
633 
634     if (rc == NGX_ERROR || r->header_only) {
635         return rc;
636     }
637 
638     if (ngx_http_error_pages[err].len == 0) {
639         return NGX_OK;
640     }
641 
642     b = ngx_calloc_buf(r->pool);
643     if (b == NULL) {
644         return NGX_ERROR;
645     }
646 
647     b->memory = 1;
648     b->pos = ngx_http_error_pages[err].data;
649     b->last = ngx_http_error_pages[err].data + ngx_http_error_pages[err].len;
650 
651     out[0].buf = b;
652     out[0].next = &out[1];
653 
654     b = ngx_calloc_buf(r->pool);
655     if (b == NULL) {
656         return NGX_ERROR;
657     }
658 
659     b->memory = 1;
660 
661     b->pos = tail;
662     b->last = tail + len;
663 
664     out[1].buf = b;
665     out[1].next = NULL;
666 
667     if (msie_padding) {
668         b = ngx_calloc_buf(r->pool);
669         if (b == NULL) {
670             return NGX_ERROR;
671         }
672 
673         b->memory = 1;
674         b->pos = ngx_http_msie_stub;
675         b->last = ngx_http_msie_stub + sizeof(ngx_http_msie_stub) - 1;
676 
677         out[1].next = &out[2];
678         out[2].buf = b;
679         out[2].next = NULL;
680     }
681 
682     if (r == r->main) {
683         b->last_buf = 1;
684     }
685 
686     b->last_in_chain = 1;
687 
688     return ngx_http_output_filter(r, &out[0]);
689 }
690 
691 
692 static ngx_int_t
693 ngx_http_send_refresh(ngx_http_request_t *r)
694 {
695     u_char       *p, *location;
696     size_t        len, size;
697     uintptr_t     escape;
698     ngx_int_t     rc;
699     ngx_buf_t    *b;
700     ngx_chain_t   out;
701 
702     len = r->headers_out.location->value.len;
703     location = r->headers_out.location->value.data;
704 
705     escape = 2 * ngx_escape_uri(NULL, location, len, NGX_ESCAPE_REFRESH);
706 
707     size = sizeof(ngx_http_msie_refresh_head) - 1
708            + escape + len
709            + sizeof(ngx_http_msie_refresh_tail) - 1;
710 
711     r->err_status = NGX_HTTP_OK;
712 
713     r->headers_out.content_type_len = sizeof("text/html") - 1;
714     r->headers_out.content_type.len = sizeof("text/html") - 1;
715     r->headers_out.content_type.data = (u_char *) "text/html";
716     r->headers_out.content_type_lowcase = NULL;
717 
718     r->headers_out.location->hash = 0;
719     r->headers_out.location = NULL;
720 
721     r->headers_out.content_length_n = size;
722 
723     if (r->headers_out.content_length) {
724         r->headers_out.content_length->hash = 0;
725         r->headers_out.content_length = NULL;
726     }
727 
728     ngx_http_clear_accept_ranges(r);
729     ngx_http_clear_last_modified(r);
730 
731     rc = ngx_http_send_header(r);
732 
733     if (rc == NGX_ERROR || r->header_only) {
734         return rc;
735     }
736 
737     b = ngx_create_temp_buf(r->pool, size);
738     if (b == NULL) {
739         return NGX_ERROR;
740     }
741 
742     p = ngx_cpymem(b->pos, ngx_http_msie_refresh_head,
743                    sizeof(ngx_http_msie_refresh_head) - 1);
744 
745     if (escape == 0) {
746         p = ngx_cpymem(p, location, len);
747 
748     } else {
749         p = (u_char *) ngx_escape_uri(p, location, len, NGX_ESCAPE_REFRESH);
750     }
751 
752     b->last = ngx_cpymem(p, ngx_http_msie_refresh_tail,
753                          sizeof(ngx_http_msie_refresh_tail) - 1);
754 
755     b->last_buf = 1;
756     b->last_in_chain = 1;
757 
758     out.buf = b;
759     out.next = NULL;
760 
761     return ngx_http_output_filter(r, &out);
762 }
763 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.