Mercurial > hg > nginx
comparison src/http/ngx_http_request.c @ 1219:86c5c9288acc
SNI support
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 29 May 2007 15:21:09 +0000 |
parents | 6e2216ad2c87 |
children | 754f3648642d |
comparison
equal
deleted
inserted
replaced
1218:e081e9c2291c | 1219:86c5c9288acc |
---|---|
23 ngx_table_elt_t *h, ngx_uint_t offset); | 23 ngx_table_elt_t *h, ngx_uint_t offset); |
24 static ngx_int_t ngx_http_process_cookie(ngx_http_request_t *r, | 24 static ngx_int_t ngx_http_process_cookie(ngx_http_request_t *r, |
25 ngx_table_elt_t *h, ngx_uint_t offset); | 25 ngx_table_elt_t *h, ngx_uint_t offset); |
26 | 26 |
27 static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r); | 27 static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r); |
28 static void ngx_http_find_virtual_server(ngx_http_request_t *r, | 28 static void ngx_http_find_virtual_server(ngx_http_request_t *r, u_char *host, |
29 ngx_http_virtual_names_t *vn, ngx_uint_t hash); | 29 size_t len, ngx_uint_t hash); |
30 | 30 |
31 static void ngx_http_request_handler(ngx_event_t *ev); | 31 static void ngx_http_request_handler(ngx_event_t *ev); |
32 static ngx_int_t ngx_http_set_write_handler(ngx_http_request_t *r); | 32 static ngx_int_t ngx_http_set_write_handler(ngx_http_request_t *r); |
33 static void ngx_http_writer(ngx_http_request_t *r); | 33 static void ngx_http_writer(ngx_http_request_t *r); |
34 | 34 |
542 ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST); | 542 ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST); |
543 | 543 |
544 return; | 544 return; |
545 } | 545 } |
546 | 546 |
547 #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME | |
548 | |
549 int | |
550 ngx_http_ssl_servername(ngx_ssl_conn_t *ssl_conn, int *ad, void *arg) | |
551 { | |
552 u_char *p; | |
553 ngx_uint_t hash; | |
554 const char *servername; | |
555 ngx_connection_t *c; | |
556 ngx_http_request_t *r; | |
557 ngx_http_ssl_srv_conf_t *sscf; | |
558 | |
559 servername = SSL_get_servername(ssl_conn, TLSEXT_NAMETYPE_host_name); | |
560 | |
561 if (servername == NULL) { | |
562 return SSL_TLSEXT_ERR_NOACK; | |
563 } | |
564 | |
565 c = ngx_ssl_get_connection(ssl_conn); | |
566 | |
567 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
568 "SSL server name: \"%s\"", servername); | |
569 | |
570 r = c->data; | |
571 | |
572 if (r->virtual_names == NULL) { | |
573 return SSL_TLSEXT_ERR_NOACK; | |
574 } | |
575 | |
576 /* it seems browsers send low case server name */ | |
577 | |
578 hash = 0; | |
579 | |
580 for (p = (u_char *) servername; *p; p++) { | |
581 hash = ngx_hash(hash, *p); | |
582 } | |
583 | |
584 ngx_http_find_virtual_server(r, (u_char *) servername, | |
585 p - (u_char *) servername, hash); | |
586 | |
587 sscf = ngx_http_get_module_srv_conf(r, ngx_http_ssl_module); | |
588 | |
589 SSL_set_SSL_CTX(ssl_conn, sscf->ssl.ctx); | |
590 | |
591 return SSL_TLSEXT_ERR_OK; | |
592 } | |
593 | |
594 #endif | |
547 | 595 |
548 #endif | 596 #endif |
549 | 597 |
550 | 598 |
551 static void | 599 static void |
1201 | 1249 |
1202 static ngx_int_t | 1250 static ngx_int_t |
1203 ngx_http_process_request_header(ngx_http_request_t *r) | 1251 ngx_http_process_request_header(ngx_http_request_t *r) |
1204 { | 1252 { |
1205 size_t len; | 1253 size_t len; |
1206 u_char *ua, *user_agent, ch; | 1254 u_char *host, *ua, *user_agent, ch; |
1207 ngx_uint_t hash; | 1255 ngx_uint_t hash; |
1208 #if (NGX_HTTP_SSL) | 1256 #if (NGX_HTTP_SSL) |
1209 long rc; | 1257 long rc; |
1210 ngx_http_ssl_srv_conf_t *sscf; | 1258 ngx_http_ssl_srv_conf_t *sscf; |
1211 #endif | 1259 #endif |
1232 } | 1280 } |
1233 | 1281 |
1234 r->headers_in.host_name_len = len; | 1282 r->headers_in.host_name_len = len; |
1235 | 1283 |
1236 if (r->virtual_names) { | 1284 if (r->virtual_names) { |
1237 ngx_http_find_virtual_server(r, r->virtual_names, hash); | 1285 |
1286 host = r->host_start; | |
1287 | |
1288 if (host == NULL) { | |
1289 host = r->headers_in.host->value.data; | |
1290 len = r->headers_in.host_name_len; | |
1291 | |
1292 } else { | |
1293 len = r->host_end - host; | |
1294 } | |
1295 | |
1296 ngx_http_find_virtual_server(r, host, len, hash); | |
1238 } | 1297 } |
1239 | 1298 |
1240 } else { | 1299 } else { |
1241 if (r->http_version > NGX_HTTP_VERSION_10) { | 1300 if (r->http_version > NGX_HTTP_VERSION_10) { |
1242 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, | 1301 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, |
1392 return NGX_OK; | 1451 return NGX_OK; |
1393 } | 1452 } |
1394 | 1453 |
1395 | 1454 |
1396 static void | 1455 static void |
1397 ngx_http_find_virtual_server(ngx_http_request_t *r, | 1456 ngx_http_find_virtual_server(ngx_http_request_t *r, u_char *host, size_t len, |
1398 ngx_http_virtual_names_t *vn, ngx_uint_t hash) | 1457 ngx_uint_t hash) |
1399 { | 1458 { |
1400 size_t len; | 1459 ngx_http_virtual_names_t *vn; |
1401 u_char *host; | |
1402 ngx_http_core_loc_conf_t *clcf; | 1460 ngx_http_core_loc_conf_t *clcf; |
1403 ngx_http_core_srv_conf_t *cscf; | 1461 ngx_http_core_srv_conf_t *cscf; |
1404 | 1462 |
1405 host = r->host_start; | 1463 vn = r->virtual_names; |
1406 | |
1407 if (host == NULL) { | |
1408 host = r->headers_in.host->value.data; | |
1409 len = r->headers_in.host_name_len; | |
1410 | |
1411 } else { | |
1412 len = r->host_end - host; | |
1413 } | |
1414 | 1464 |
1415 if (vn->hash.buckets) { | 1465 if (vn->hash.buckets) { |
1416 cscf = ngx_hash_find(&vn->hash, hash, host, len); | 1466 cscf = ngx_hash_find(&vn->hash, hash, host, len); |
1417 if (cscf) { | 1467 if (cscf) { |
1418 goto found; | 1468 goto found; |