comparison src/http/ngx_http_special_response.c @ 153:c71aeb75c071

nginx-0.0.1-2003-10-21-20:49:56 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 21 Oct 2003 16:49:56 +0000
parents 5afee0074707
children 46eb23d9471d
comparison
equal deleted inserted replaced
152:fb48bf4fea1c 153:c71aeb75c071
150 }; 150 };
151 151
152 152
153 int ngx_http_special_response_handler(ngx_http_request_t *r, int error) 153 int ngx_http_special_response_handler(ngx_http_request_t *r, int error)
154 { 154 {
155 int err, rc; 155 int err, rc;
156 ngx_hunk_t *h; 156 ngx_hunk_t *h;
157 ngx_chain_t *out, **le, *ce;
157 158
158 r->headers_out.status = error; 159 r->headers_out.status = error;
159 160
160 if (error < NGX_HTTP_BAD_REQUEST) { 161 if (error < NGX_HTTP_BAD_REQUEST) {
161 /* 3XX */ 162 /* 3XX */
187 r->lingering_close = 0; 188 r->lingering_close = 0;
188 } 189 }
189 } 190 }
190 191
191 if (error_pages[err].len) { 192 if (error_pages[err].len) {
192 r->headers_out.content_length = error_pages[err].len 193 r->headers_out.content_length_n = error_pages[err].len
193 + sizeof(error_tail) - 1 194 + sizeof(error_tail) - 1
194 + sizeof(msie_stub) - 1; 195 + sizeof(msie_stub) - 1;
195 196
196 ngx_test_null(r->headers_out.content_type, 197 ngx_test_null(r->headers_out.content_type,
197 ngx_push_table(r->headers_out.headers), 198 ngx_push_table(r->headers_out.headers),
198 NGX_HTTP_INTERNAL_SERVER_ERROR); 199 NGX_HTTP_INTERNAL_SERVER_ERROR);
199 200
201 r->headers_out.content_type->key.data = "Content-Type"; 202 r->headers_out.content_type->key.data = "Content-Type";
202 r->headers_out.content_type->value.len = 9; 203 r->headers_out.content_type->value.len = 9;
203 r->headers_out.content_type->value.data = "text/html"; 204 r->headers_out.content_type->value.data = "text/html";
204 205
205 } else { 206 } else {
206 r->headers_out.content_length = -1; 207 r->headers_out.content_length_n = -1;
208 r->headers_out.content_length = NULL;
207 } 209 }
208 210
209 rc = ngx_http_send_header(r); 211 rc = ngx_http_send_header(r);
210 212
211 if (rc == NGX_ERROR || r->header_only) { 213 if (rc == NGX_ERROR || r->header_only) {
214 216
215 if (error_pages[err].len == 0) { 217 if (error_pages[err].len == 0) {
216 return NGX_OK; 218 return NGX_OK;
217 } 219 }
218 220
221 out = NULL;
222 le = NULL;
223
219 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); 224 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR);
220
221 h->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY; 225 h->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY;
222 h->pos = error_pages[err].data; 226 h->pos = error_pages[err].data;
223 h->last = error_pages[err].data + error_pages[err].len; 227 h->last = error_pages[err].data + error_pages[err].len;
224 228
225 if (ngx_http_output_filter(r, h) == NGX_ERROR) { 229 ngx_alloc_ce_and_set_hunk(ce, h, r->pool, NGX_ERROR);
226 return NGX_ERROR; 230 ngx_chain_add_ce(out, le, ce);
227 } 231
228 232
229 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); 233 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR);
230
231 h->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY; 234 h->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY;
232 h->pos = error_tail; 235 h->pos = error_tail;
233 h->last = error_tail + sizeof(error_tail) - 1; 236 h->last = error_tail + sizeof(error_tail) - 1;
237
238 ngx_alloc_ce_and_set_hunk(ce, h, r->pool, NGX_ERROR);
239 ngx_chain_add_ce(out, le, ce);
234 240
235 if (/* STUB: "msie_padding on/off" */ 1 241 if (/* STUB: "msie_padding on/off" */ 1
236 && r->http_version >= NGX_HTTP_VERSION_10 242 && r->http_version >= NGX_HTTP_VERSION_10
237 && error >= NGX_HTTP_BAD_REQUEST 243 && error >= NGX_HTTP_BAD_REQUEST
238 && error != NGX_HTTP_REQUEST_URI_TOO_LARGE 244 && error != NGX_HTTP_REQUEST_URI_TOO_LARGE
239 ) 245 )
240 { 246 {
241
242 if (ngx_http_output_filter(r, h) == NGX_ERROR) {
243 return NGX_ERROR;
244 }
245
246 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); 247 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR);
247
248 h->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY; 248 h->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY;
249 h->pos = msie_stub; 249 h->pos = msie_stub;
250 h->last = msie_stub + sizeof(msie_stub) - 1; 250 h->last = msie_stub + sizeof(msie_stub) - 1;
251
252 ngx_alloc_ce_and_set_hunk(ce, h, r->pool, NGX_ERROR);
253 ngx_chain_add_ce(out, le, ce);
251 } 254 }
252 255
253 h->type |= NGX_HUNK_LAST; 256 h->type |= NGX_HUNK_LAST;
254 257
255 return ngx_http_output_filter(r, h); 258 return ngx_http_output_filter(r, out);
256 } 259 }