Mercurial > hg > nginx
comparison src/http/ngx_http_request.c @ 396:6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 18 Jul 2004 19:11:20 +0000 |
parents | f8f0f1834266 |
children | ba0809223309 |
comparison
equal
deleted
inserted
replaced
395:f8f0f1834266 | 396:6f3b20c1ac50 |
---|---|
5 #include <ngx_http.h> | 5 #include <ngx_http.h> |
6 | 6 |
7 | 7 |
8 static void ngx_http_init_request(ngx_event_t *ev); | 8 static void ngx_http_init_request(ngx_event_t *ev); |
9 #if (NGX_HTTP_SSL) | 9 #if (NGX_HTTP_SSL) |
10 static void ngx_http_check_ssl_handshake(ngx_event_t *rev); | 10 static void ngx_http_ssl_handshake(ngx_event_t *rev); |
11 #endif | 11 #endif |
12 static void ngx_http_process_request_line(ngx_event_t *rev); | 12 static void ngx_http_process_request_line(ngx_event_t *rev); |
13 static void ngx_http_process_request_headers(ngx_event_t *rev); | 13 static void ngx_http_process_request_headers(ngx_event_t *rev); |
14 static ssize_t ngx_http_read_request_header(ngx_http_request_t *r); | 14 static ssize_t ngx_http_read_request_header(ngx_http_request_t *r); |
15 static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r); | 15 static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r); |
236 r->srv_conf = cscf->ctx->srv_conf; | 236 r->srv_conf = cscf->ctx->srv_conf; |
237 r->loc_conf = cscf->ctx->loc_conf; | 237 r->loc_conf = cscf->ctx->loc_conf; |
238 | 238 |
239 rev->event_handler = ngx_http_process_request_line; | 239 rev->event_handler = ngx_http_process_request_line; |
240 | 240 |
241 r->recv = ngx_recv; | |
242 r->send_chain = ngx_send_chain; | |
243 | |
244 #if (NGX_HTTP_SSL) | 241 #if (NGX_HTTP_SSL) |
245 | 242 |
246 sscf = ngx_http_get_module_srv_conf(r, ngx_http_ssl_module); | 243 sscf = ngx_http_get_module_srv_conf(r, ngx_http_ssl_module); |
247 if (sscf->enable) { | 244 if (sscf->enable) { |
248 if (ngx_ssl_create_session(sscf->ssl_ctx, c, NGX_SSL_BUFFER) | 245 |
246 if (c->ssl == NULL) { | |
247 if (ngx_ssl_create_session(sscf->ssl_ctx, c, NGX_SSL_BUFFER) | |
249 == NGX_ERROR) | 248 == NGX_ERROR) |
250 { | 249 { |
251 ngx_http_close_connection(c); | 250 ngx_http_close_connection(c); |
252 return; | 251 return; |
252 } | |
253 | |
254 /* | |
255 * The majority of browsers do not send the "close notify" alert. | |
256 * Among them are MSIE, Mozilla, Netscape 4, Konqueror, and Links. | |
257 * And what is more MSIE ignores the server's alert. | |
258 * | |
259 * Opera always sends the alert. | |
260 */ | |
261 | |
262 c->ssl->no_rcv_shut = 1; | |
263 rev->event_handler = ngx_http_ssl_handshake; | |
253 } | 264 } |
254 | 265 |
255 r->filter_need_in_memory = 1; | 266 r->filter_need_in_memory = 1; |
256 rev->event_handler = ngx_http_check_ssl_handshake; | |
257 } | 267 } |
258 | 268 |
259 #endif | 269 #endif |
260 | 270 |
261 server_name = cscf->server_names.elts; | 271 server_name = cscf->server_names.elts; |
337 } | 347 } |
338 | 348 |
339 | 349 |
340 #if (NGX_HTTP_SSL) | 350 #if (NGX_HTTP_SSL) |
341 | 351 |
342 static void ngx_http_check_ssl_handshake(ngx_event_t *rev) | 352 static void ngx_http_ssl_handshake(ngx_event_t *rev) |
343 { | 353 { |
344 int n; | 354 int n; |
355 ngx_int_t rc; | |
345 u_char buf[1]; | 356 u_char buf[1]; |
346 ngx_connection_t *c; | 357 ngx_connection_t *c; |
347 ngx_http_request_t *r; | 358 ngx_http_request_t *r; |
348 | 359 |
349 c = rev->data; | 360 c = rev->data; |
366 if (n == 1) { | 377 if (n == 1) { |
367 if (buf[0] == 0x80 /* SSLv2 */ || buf[0] == 0x16 /* SSLv3/TLSv1 */) { | 378 if (buf[0] == 0x80 /* SSLv2 */ || buf[0] == 0x16 /* SSLv3/TLSv1 */) { |
368 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, rev->log, 0, | 379 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, rev->log, 0, |
369 "https ssl handshake: 0x%X", buf[0]); | 380 "https ssl handshake: 0x%X", buf[0]); |
370 | 381 |
371 r->recv = ngx_ssl_recv; | 382 c->recv = ngx_ssl_recv; |
372 r->send_chain = ngx_ssl_send_chain; | 383 c->send_chain = ngx_ssl_send_chain; |
384 | |
385 rc = ngx_ssl_handshake(c); | |
386 | |
387 if (rc == NGX_ERROR) { | |
388 ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST); | |
389 ngx_http_close_connection(r->connection); | |
390 return; | |
391 } | |
392 | |
393 if (rc != NGX_OK) { | |
394 return; | |
395 } | |
373 | 396 |
374 } else { | 397 } else { |
375 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, | 398 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, |
376 "plain http"); | 399 "plain http"); |
377 | 400 |
890 | 913 |
891 if (!rev->ready) { | 914 if (!rev->ready) { |
892 return NGX_AGAIN; | 915 return NGX_AGAIN; |
893 } | 916 } |
894 | 917 |
895 n = r->recv(r->connection, r->header_in->last, | 918 n = r->connection->recv(r->connection, r->header_in->last, |
896 r->header_in->end - r->header_in->last); | 919 r->header_in->end - r->header_in->last); |
897 | 920 |
898 if (n == NGX_AGAIN) { | 921 if (n == NGX_AGAIN) { |
899 if (!r->header_timeout_set) { | 922 if (!r->header_timeout_set) { |
900 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | 923 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
901 ngx_add_timer(rev, cscf->client_header_timeout); | 924 ngx_add_timer(rev, cscf->client_header_timeout); |
961 r->loc_conf = name[i].core_srv_conf->ctx->loc_conf; | 984 r->loc_conf = name[i].core_srv_conf->ctx->loc_conf; |
962 r->server_name = &name[i].name; | 985 r->server_name = &name[i].name; |
963 | 986 |
964 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 987 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
965 r->connection->log->file = clcf->err_log->file; | 988 r->connection->log->file = clcf->err_log->file; |
966 r->connection->log->log_level = clcf->err_log->log_level; | 989 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) |
990 { | |
991 r->connection->log->log_level = clcf->err_log->log_level; | |
992 } | |
967 | 993 |
968 break; | 994 break; |
969 } | 995 } |
970 } | 996 } |
971 | 997 |
1038 { | 1064 { |
1039 r->headers_in.msie = 1; | 1065 r->headers_in.msie = 1; |
1040 if (ua[4] == ' ' && ua[5] == '4' && ua[6] == '.') { | 1066 if (ua[4] == ' ' && ua[5] == '4' && ua[6] == '.') { |
1041 r->headers_in.msie4 = 1; | 1067 r->headers_in.msie4 = 1; |
1042 } | 1068 } |
1069 | |
1070 #if 0 | |
1071 /* MSIE ignores the SSL "close notify" alert */ | |
1072 | |
1073 ngx_ssl_set_nosendshut(r->connection->ssl); | |
1074 #endif | |
1043 } | 1075 } |
1044 } | 1076 } |
1045 | 1077 |
1046 return NGX_OK; | 1078 return NGX_OK; |
1047 } | 1079 } |
1353 | 1385 |
1354 if (size > (ssize_t) clcf->discarded_buffer_size) { | 1386 if (size > (ssize_t) clcf->discarded_buffer_size) { |
1355 size = (ssize_t) clcf->discarded_buffer_size; | 1387 size = (ssize_t) clcf->discarded_buffer_size; |
1356 } | 1388 } |
1357 | 1389 |
1358 n = ngx_recv(r->connection, r->discarded_buffer, size); | 1390 n = r->connection->recv(r->connection, r->discarded_buffer, size); |
1391 | |
1359 if (n == NGX_ERROR) { | 1392 if (n == NGX_ERROR) { |
1360 | 1393 |
1361 r->closed = 1; | 1394 r->closed = 1; |
1362 | 1395 |
1363 /* | 1396 /* |
1500 * so we ignore ECONNRESET here. | 1533 * so we ignore ECONNRESET here. |
1501 */ | 1534 */ |
1502 | 1535 |
1503 c->log_error = NGX_ERROR_IGNORE_ECONNRESET; | 1536 c->log_error = NGX_ERROR_IGNORE_ECONNRESET; |
1504 ngx_set_socket_errno(0); | 1537 ngx_set_socket_errno(0); |
1505 n = ngx_recv(c, c->buffer->last, c->buffer->end - c->buffer->last); | 1538 |
1539 n = c->recv(c, c->buffer->last, c->buffer->end - c->buffer->last); | |
1506 c->log_error = NGX_ERROR_INFO; | 1540 c->log_error = NGX_ERROR_INFO; |
1507 | 1541 |
1508 if (n == NGX_AGAIN) { | 1542 if (n == NGX_AGAIN) { |
1509 return; | 1543 return; |
1510 } | 1544 } |
1531 ngx_http_init_request(rev); | 1565 ngx_http_init_request(rev); |
1532 } | 1566 } |
1533 | 1567 |
1534 | 1568 |
1535 static void ngx_http_set_lingering_close(ngx_http_request_t *r) | 1569 static void ngx_http_set_lingering_close(ngx_http_request_t *r) |
1536 { | 1570 { |
1537 ngx_event_t *rev, *wev; | 1571 ngx_event_t *rev, *wev; |
1538 ngx_connection_t *c; | 1572 ngx_connection_t *c; |
1539 ngx_http_core_loc_conf_t *clcf; | 1573 ngx_http_core_loc_conf_t *clcf; |
1540 | 1574 |
1541 c = r->connection; | 1575 c = r->connection; |
1638 } | 1672 } |
1639 } | 1673 } |
1640 } | 1674 } |
1641 | 1675 |
1642 do { | 1676 do { |
1643 n = ngx_recv(c, r->discarded_buffer, clcf->discarded_buffer_size); | 1677 n = c->recv(c, r->discarded_buffer, clcf->discarded_buffer_size); |
1644 | 1678 |
1645 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "lingering read: %d", n); | 1679 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "lingering read: %d", n); |
1646 | 1680 |
1647 if (n == NGX_ERROR || n == 0) { | 1681 if (n == NGX_ERROR || n == 0) { |
1648 ngx_http_close_request(r, 0); | 1682 ngx_http_close_request(r, 0); |