Mercurial > hg > nginx
comparison src/http/ngx_http_request.c @ 200:abeaebe0a33c
nginx-0.0.1-2003-11-28-20:41:47 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 28 Nov 2003 17:41:47 +0000 |
parents | 2357fa41738a |
children | 267ea1d98683 |
comparison
equal
deleted
inserted
replaced
199:a65b630b3a66 | 200:abeaebe0a33c |
---|---|
223 if (!(r->pool = ngx_create_pool(cscf->request_pool_size, c->log))) { | 223 if (!(r->pool = ngx_create_pool(cscf->request_pool_size, c->log))) { |
224 ngx_http_close_connection(c); | 224 ngx_http_close_connection(c); |
225 return; | 225 return; |
226 } | 226 } |
227 | 227 |
228 r->cleanup.elts = ngx_palloc(r->pool, 5 * sizeof(ngx_http_cleanup_t)); | |
229 if (r->cleanup.elts == NULL) { | |
230 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
231 ngx_http_close_connection(c); | |
232 return; | |
233 } | |
234 /* | |
235 * set by ngx_pcalloc(): | |
236 * | |
237 * r->cleanup.nelts = 0; | |
238 */ | |
239 r->cleanup.nalloc = 5; | |
240 r->cleanup.size = sizeof(ngx_http_cleanup_t); | |
241 r->cleanup.pool = r->pool; | |
242 | |
228 /* TODO: ngx_init_table */ | 243 /* TODO: ngx_init_table */ |
229 if (!(r->headers_out.headers = ngx_create_table(r->pool, 20))) { | 244 if (!(r->headers_out.headers = ngx_create_table(r->pool, 20))) { |
230 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 245 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
231 ngx_http_close_connection(c); | 246 ngx_http_close_connection(c); |
232 return; | 247 return; |
287 if (rc == NGX_OK) { | 302 if (rc == NGX_OK) { |
288 | 303 |
289 /* the request line has been parsed successfully */ | 304 /* the request line has been parsed successfully */ |
290 | 305 |
291 /* TODO: we need to handle such URIs */ | 306 /* TODO: we need to handle such URIs */ |
292 if (r->complex_uri || r->unusual_uri) { | 307 if (r->unusual_uri) { |
293 r->request_line.len = r->request_end - r->request_start; | 308 r->request_line.len = r->request_end - r->request_start; |
294 r->request_line.data = r->request_start; | 309 r->request_line.data = r->request_start; |
295 r->request_line.data[r->request_line.len] = '\0'; | 310 r->request_line.data[r->request_line.len] = '\0'; |
296 | 311 |
297 ngx_http_client_error(r, NGX_HTTP_PARSE_INVALID_REQUEST, | 312 ngx_http_client_error(r, NGX_HTTP_PARSE_INVALID_REQUEST, |
309 | 324 |
310 ngx_http_client_error(r, NGX_HTTP_PARSE_TOO_LONG_URI, | 325 ngx_http_client_error(r, NGX_HTTP_PARSE_TOO_LONG_URI, |
311 NGX_HTTP_REQUEST_URI_TOO_LARGE); | 326 NGX_HTTP_REQUEST_URI_TOO_LARGE); |
312 return; | 327 return; |
313 } | 328 } |
314 | |
315 | |
316 /* copy URI */ | |
317 | |
318 if (r->args_start) { | |
319 r->uri.len = r->args_start - 1 - r->uri_start; | |
320 } else { | |
321 r->uri.len = r->uri_end - r->uri_start; | |
322 } | |
323 | |
324 if (!(r->uri.data = ngx_palloc(r->pool, r->uri.len + 1))) { | |
325 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
326 ngx_http_close_connection(c); | |
327 return; | |
328 } | |
329 | |
330 ngx_cpystrn(r->uri.data, r->uri_start, r->uri.len + 1); | |
331 | 329 |
332 | 330 |
333 /* copy unparsed URI */ | 331 /* copy unparsed URI */ |
334 | 332 |
335 r->unparsed_uri.len = r->uri_end - r->uri_start; | 333 r->unparsed_uri.len = r->uri_end - r->uri_start; |
342 | 340 |
343 ngx_cpystrn(r->unparsed_uri.data, r->uri_start, | 341 ngx_cpystrn(r->unparsed_uri.data, r->uri_start, |
344 r->unparsed_uri.len + 1); | 342 r->unparsed_uri.len + 1); |
345 | 343 |
346 | 344 |
345 /* copy URI */ | |
346 | |
347 if (r->args_start) { | |
348 r->uri.len = r->args_start - 1 - r->uri_start; | |
349 } else { | |
350 r->uri.len = r->uri_end - r->uri_start; | |
351 } | |
352 | |
353 if (!(r->uri.data = ngx_palloc(r->pool, r->uri.len + 1))) { | |
354 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
355 ngx_http_close_connection(c); | |
356 return; | |
357 } | |
358 | |
359 if (r->complex_uri) { | |
360 rc = ngx_http_parse_complex_uri(r); | |
361 | |
362 } else { | |
363 ngx_cpystrn(r->uri.data, r->uri_start, r->uri.len + 1); | |
364 } | |
365 | |
366 | |
347 r->request_line.len = r->request_end - r->request_start; | 367 r->request_line.len = r->request_end - r->request_start; |
348 | 368 |
349 if (cscf->large_client_header) { | 369 if (cscf->large_client_header) { |
350 | 370 |
351 /* | 371 /* |
364 r->request_line.len + 1); | 384 r->request_line.len + 1); |
365 | 385 |
366 } else { | 386 } else { |
367 r->request_line.data = r->request_start; | 387 r->request_line.data = r->request_start; |
368 r->request_line.data[r->request_line.len] = '\0'; | 388 r->request_line.data[r->request_line.len] = '\0'; |
389 } | |
390 | |
391 | |
392 if (rc != NGX_OK) { | |
393 /* | |
394 * we check ngx_http_parse_complex_uri() result here to log | |
395 * the request line | |
396 */ | |
397 ngx_http_client_error(r, rc, NGX_HTTP_BAD_REQUEST); | |
398 return; | |
369 } | 399 } |
370 | 400 |
371 | 401 |
372 if (r->uri_ext) { | 402 if (r->uri_ext) { |
373 | 403 |
1354 } | 1384 } |
1355 | 1385 |
1356 | 1386 |
1357 void ngx_http_close_request(ngx_http_request_t *r, int error) | 1387 void ngx_http_close_request(ngx_http_request_t *r, int error) |
1358 { | 1388 { |
1389 ngx_int_t i; | |
1359 ngx_http_log_ctx_t *ctx; | 1390 ngx_http_log_ctx_t *ctx; |
1391 ngx_http_cleanup_t *cleanup; | |
1360 | 1392 |
1361 ngx_log_debug(r->connection->log, "close http request"); | 1393 ngx_log_debug(r->connection->log, "close http request"); |
1362 | 1394 |
1363 if (r->pool == NULL) { | 1395 if (r->pool == NULL) { |
1364 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | 1396 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
1369 if (error) { | 1401 if (error) { |
1370 r->headers_out.status = error; | 1402 r->headers_out.status = error; |
1371 } | 1403 } |
1372 | 1404 |
1373 ngx_http_log_handler(r); | 1405 ngx_http_log_handler(r); |
1406 | |
1407 cleanup = r->cleanup.elts; | |
1408 for (i = 0; i < r->cleanup.nelts; i++) { | |
1409 if (cleanup[i].cache) { | |
1410 ngx_http_cache_unlock(cleanup[i].data.cache.hash, | |
1411 cleanup[i].data.cache.cache, | |
1412 r->connection->log); | |
1413 continue; | |
1414 } | |
1415 | |
1416 if (ngx_close_file(cleanup[i].data.file.fd) == NGX_FILE_ERROR) { | |
1417 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno, | |
1418 ngx_close_file_n " \"%s\" failed", | |
1419 cleanup[i].data.file.name); | |
1420 } | |
1421 } | |
1374 | 1422 |
1375 if (r->file.fd != NGX_INVALID_FILE) { | 1423 if (r->file.fd != NGX_INVALID_FILE) { |
1376 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) { | 1424 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) { |
1377 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno, | 1425 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno, |
1378 ngx_close_file_n " \"%s\" failed", r->file.name.data); | 1426 ngx_close_file_n " \"%s\" failed", r->file.name.data); |