comparison src/http/ngx_http_special_response.c @ 103:6dfda4cf5200

nginx-0.0.1-2003-06-11-19:28:34 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 11 Jun 2003 15:28:34 +0000
parents a059e1aa65d4
children cb77c084acdb
comparison
equal deleted inserted replaced
102:7e86d028d8f0 103:6dfda4cf5200
7 7
8 static char error_tail[] = 8 static char error_tail[] =
9 "<hr><center>" NGINX_VER "</center>" CRLF 9 "<hr><center>" NGINX_VER "</center>" CRLF
10 "</body>" CRLF 10 "</body>" CRLF
11 "</html>" CRLF 11 "</html>" CRLF
12 ;
13
14
15 static char msie_stub[] =
16 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
17 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
18 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
19 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
20 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
21 "<!-- The padding to disable MSIE's friendly error page -->" CRLF
12 ; 22 ;
13 23
14 24
15 static char error_302_page[] = 25 static char error_302_page[] =
16 "<html>" CRLF 26 "<html>" CRLF
132 }; 142 };
133 143
134 144
135 int ngx_http_special_response_handler(ngx_http_request_t *r, int error) 145 int ngx_http_special_response_handler(ngx_http_request_t *r, int error)
136 { 146 {
137 int err; 147 int err, rc;
138 ngx_hunk_t *message, *tail; 148 ngx_hunk_t *h;
139 149
140 r->headers_out.status = error; 150 r->headers_out.status = error;
141 151
142 if (error < NGX_HTTP_BAD_REQUEST) { 152 if (error < NGX_HTTP_BAD_REQUEST) {
143 /* 3XX */ 153 /* 3XX */
170 } 180 }
171 } 181 }
172 182
173 if (error_pages[err].len) { 183 if (error_pages[err].len) {
174 r->headers_out.content_length = error_pages[err].len 184 r->headers_out.content_length = error_pages[err].len
175 + sizeof(error_tail); 185 + sizeof(error_tail) - 1
186 + sizeof(msie_stub) - 1;
176 187
177 ngx_test_null(r->headers_out.content_type, 188 ngx_test_null(r->headers_out.content_type,
178 ngx_push_table(r->headers_out.headers), 189 ngx_push_table(r->headers_out.headers),
179 NGX_HTTP_INTERNAL_SERVER_ERROR); 190 NGX_HTTP_INTERNAL_SERVER_ERROR);
180 191
185 196
186 } else { 197 } else {
187 r->headers_out.content_length = -1; 198 r->headers_out.content_length = -1;
188 } 199 }
189 200
190 if (ngx_http_send_header(r) == NGX_ERROR) { 201 rc = ngx_http_send_header(r);
202 if (rc == NGX_ERROR) {
191 return NGX_ERROR; 203 return NGX_ERROR;
204 }
205
206 if (r->header_only) {
207 if (rc == NGX_AGAIN) {
208 ngx_http_set_write_handler(r);
209 return NGX_AGAIN;
210 }
211
212 return NGX_OK;
192 } 213 }
193 214
194 if (error_pages[err].len == 0) { 215 if (error_pages[err].len == 0) {
195 return NGX_OK; 216 return NGX_OK;
196 } 217 }
197 218
198 ngx_test_null(message, ngx_pcalloc(r->pool, sizeof(ngx_hunk_t)), NGX_ERROR); 219 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR);
199 220
200 message->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY; 221 h->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY;
201 message->pos = error_pages[err].data; 222 h->pos = error_pages[err].data;
202 message->last = error_pages[err].data + error_pages[err].len; 223 h->last = error_pages[err].data + error_pages[err].len;
203 224
204 if (ngx_http_output_filter(r, message) == NGX_ERROR) { 225 if (ngx_http_output_filter(r, h) == NGX_ERROR) {
205 return NGX_ERROR; 226 return NGX_ERROR;
206 } 227 }
207 228
208 ngx_test_null(tail, ngx_pcalloc(r->pool, sizeof(ngx_hunk_t)), NGX_ERROR); 229 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR);
209 230
210 tail->type = NGX_HUNK_MEMORY|NGX_HUNK_LAST|NGX_HUNK_IN_MEMORY; 231 h->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY;
211 tail->pos = error_tail; 232 h->pos = error_tail;
212 tail->last = error_tail + sizeof(error_tail); 233 h->last = error_tail + sizeof(error_tail) - 1;
213 234
214 return ngx_http_output_filter(r, tail); 235 if (1) {
236 if (ngx_http_output_filter(r, h) == NGX_ERROR) {
237 return NGX_ERROR;
238 }
239
240 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR);
241
242 h->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY;
243 h->pos = msie_stub;
244 h->last = msie_stub + sizeof(msie_stub) - 1;
245 }
246
247 h->type |= NGX_HUNK_LAST;
248
249 rc = ngx_http_output_filter(r, h);
250
251 if (r->main == NULL) {
252 if (rc == NGX_AGAIN) {
253 ngx_http_set_write_handler(r);
254 return NGX_AGAIN;
255 }
256 }
257
258 return NGX_OK;
259
215 } 260 }