233
233
ngx_connection_t *c;
234
234
ngx_http_request_t *r;
235
ngx_http_in_port_t *hip;
236
ngx_http_in_addr_t *hia;
235
struct sockaddr_in *sin;
236
ngx_http_port_t *port;
237
ngx_http_in_addr_t *addr;
237
238
ngx_http_log_ctx_t *ctx;
239
ngx_http_addr_conf_t *addr_conf;
238
240
ngx_http_connection_t *hc;
239
241
ngx_http_core_srv_conf_t *cscf;
240
242
ngx_http_core_loc_conf_t *clcf;
241
243
ngx_http_core_main_conf_t *cmcf;
245
struct sockaddr_in6 *sin6;
246
ngx_http_in6_addr_t *addr6;
243
249
#if (NGX_STAT_STUB)
244
250
ngx_atomic_fetch_add(ngx_stat_reading, -1);
293
299
/* find the server configuration for the address:port */
297
hip = c->listening->servers;
301
r->port_text = &hip->port_text;
301
port = c->listening->servers;
305
303
r->connection = c;
307
if (hip->naddrs > 1) {
305
if (port->naddrs > 1) {
310
* There are several addresses on this port and one of them
311
* is the "*:port" wildcard so getsockname() is needed to determine
312
* the server address.
314
* AcceptEx() already has given this address.
308
* there are several addresses on this port and one of them
309
* is an "*:port" wildcard so getsockname() in ngx_http_server_addr()
310
* is required to determine a server address
318
if (c->local_sockaddr) {
320
((struct sockaddr_in *) c->local_sockaddr)->sin_addr.s_addr;
313
if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) {
314
ngx_http_close_connection(c);
318
switch (c->local_sockaddr->sa_family) {
322
sin6 = (struct sockaddr_in6 *) c->local_sockaddr;
326
/* the last address is "*" */
328
for (i = 0; i < port->naddrs - 1; i++) {
329
if (ngx_memcmp(&addr6[i].addr6, &sin6->sin6_addr, 16) == 0) {
334
addr_conf = &addr6[i].conf;
325
if (ngx_http_server_addr(r, NULL) != NGX_OK) {
326
ngx_http_close_connection(c);
331
/* the last address is "*" */
333
for ( /* void */ ; i < hip->naddrs - 1; i++) {
334
if (hia[i].addr == r->in_addr) {
339
default: /* AF_INET */
340
sin = (struct sockaddr_in *) c->local_sockaddr;
344
/* the last address is "*" */
346
for (i = 0; i < port->naddrs - 1; i++) {
347
if (addr[i].addr == sin->sin_addr.s_addr) {
352
addr_conf = &addr[i].conf;
340
r->in_addr = hia[0].addr;
359
switch (c->local_sockaddr->sa_family) {
364
addr_conf = &addr6[0].conf;
368
default: /* AF_INET */
370
addr_conf = &addr[0].conf;
343
r->virtual_names = hia[i].virtual_names;
375
r->virtual_names = addr_conf->virtual_names;
345
377
/* the default server configuration for the address:port */
346
cscf = hia[i].core_srv_conf;
378
cscf = addr_conf->core_srv_conf;
348
380
r->main_conf = cscf->ctx->main_conf;
349
381
r->srv_conf = cscf->ctx->srv_conf;
357
389
ngx_http_ssl_srv_conf_t *sscf;
359
391
sscf = ngx_http_get_module_srv_conf(r, ngx_http_ssl_module);
392
if (sscf->enable || addr_conf->ssl) {
362
394
if (c->ssl == NULL) {
396
c->log->action = "SSL handshaking";
398
if (addr_conf->ssl && sscf->ssl.ctx == NULL) {
399
ngx_log_error(NGX_LOG_ERR, c->log, 0,
400
"no \"ssl_certificate\" is defined "
401
"in server listening on SSL port");
402
ngx_http_close_connection(c);
363
406
if (ngx_ssl_create_connection(&sscf->ssl, c, NGX_SSL_BUFFER)
366
409
ngx_http_close_connection(c);
587
633
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
588
634
"SSL server name: \"%s\"", servername);
636
len = ngx_strlen(servername);
639
return SSL_TLSEXT_ERR_NOACK;
592
if (ngx_http_find_virtual_server(r, (u_char *) servername,
593
ngx_strlen(servername))
644
if (ngx_http_find_virtual_server(r, (u_char *) servername, len) != NGX_OK) {
596
645
return SSL_TLSEXT_ERR_NOACK;
1572
server = ngx_palloc(r->pool, len);
1620
server = ngx_pnalloc(r->pool, len);
1573
1621
if (server == NULL) {
1574
1622
return NGX_ERROR;
1580
for (i = 0; i < len; i++) {
1583
ch = ngx_tolower(ch);
1586
hash = ngx_hash(hash, ch);
1626
hash = ngx_hash_strlow(server, host, len);
1589
1628
cscf = ngx_hash_find_combined(&r->virtual_names->names, hash, server, len);
1603
1643
name.len = len;
1604
1644
name.data = server;
1606
1648
sn = r->virtual_names->regex;
1608
1650
for (i = 0; i < r->virtual_names->nregex; i++) {
1610
n = ngx_regex_exec(sn[i].regex, &name, NULL, 0);
1652
if (sn[i].captures && r->captures == NULL) {
1654
ncaptures = (NGX_HTTP_MAX_CAPTURES + 1) * 3;
1656
r->captures = ngx_palloc(r->pool, ncaptures * sizeof(int));
1657
if (r->captures == NULL) {
1661
if (server == buf) {
1662
server = ngx_pnalloc(r->pool, len);
1663
if (server == NULL) {
1667
ngx_memcpy(server, buf, len);
1672
n = ngx_regex_exec(sn[i].regex, &name, r->captures, ncaptures);
1612
1674
if (n == NGX_REGEX_NO_MATCHED) {
1662
1727
ctx = c->log->data;
1663
1728
ctx->current_request = r;
1730
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1731
"http run request: \"%V?%V\"", &r->uri, &r->args);
1665
1733
if (ev->write) {
1666
1734
r->write_event_handler(r);
1669
1737
r->read_event_handler(r);
1740
ngx_http_run_posted_requests(c);
1745
ngx_http_run_posted_requests(ngx_connection_t *c)
1747
ngx_http_request_t *r;
1748
ngx_http_log_ctx_t *ctx;
1749
ngx_http_posted_request_t *pr;
1758
pr = r->main->posted_requests;
1764
r->main->posted_requests = pr->next;
1769
ctx->current_request = r;
1771
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1772
"http posted request: \"%V?%V\"", &r->uri, &r->args);
1774
r->write_event_handler(r);
1780
ngx_http_post_request(ngx_http_request_t *r)
1782
ngx_http_posted_request_t *pr, **p;
1784
pr = ngx_palloc(r->pool, sizeof(ngx_http_posted_request_t));
1792
for (p = &r->main->posted_requests; *p; p = &(*p)->next) { /* void */ }
1687
1812
c = r->connection;
1689
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
1690
"http finalize request: %d, \"%V?%V\"",
1691
rc, &r->uri, &r->args);
1814
ngx_log_debug4(NGX_LOG_DEBUG_HTTP, c->log, 0,
1815
"http finalize request: %d, \"%V?%V\" %d",
1816
rc, &r->uri, &r->args, r == c->data);
1818
if (rc == NGX_OK && r->filter_finalize) {
1693
1823
if (rc == NGX_DECLINED) {
1694
1824
r->content_handler = NULL;
1870
c->read->handler = ngx_http_request_handler;
1871
c->write->handler = ngx_http_request_handler;
1740
1873
ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc));
1744
if (r != r->main || rc == NGX_AGAIN) {
1745
if (ngx_http_set_write_handler(r) != NGX_OK) {
1753
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1754
"http finalize non-active request: \"%V?%V\"",
1759
1877
if (r != r->main) {
1879
if (r->buffered || r->postponed) {
1881
if (ngx_http_set_write_handler(r) != NGX_OK) {
1882
ngx_http_close_request(r->main, 0);
1890
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1891
"http finalize non-active request: \"%V?%V\"",
1761
1896
pr = r->parent;
1763
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1764
"http parent request: \"%V?%V\"", &pr->uri, &pr->args);
1766
if (rc != NGX_AGAIN) {
1902
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1904
if (clcf->log_subrequest) {
1905
ngx_http_log_request(r);
1911
ngx_log_error(NGX_LOG_ALERT, c->log, 0,
1912
"subrequest: \"%V?%V\" logged again",
1918
if (pr->postponed && pr->postponed->request == r) {
1919
pr->postponed = pr->postponed->next;
1771
ctx->current_request = pr;
1773
if (pr->postponed) {
1775
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1776
"http request: \"%V?%V\" has postponed",
1777
&pr->uri, &pr->args);
1779
if (rc != NGX_AGAIN && pr->postponed->request == r) {
1780
pr->postponed = pr->postponed->next;
1783
if (r->fast_subrequest) {
1785
if (rc == NGX_AGAIN) {
1786
r->fast_subrequest = 0;
1789
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1790
"http fast subrequest: \"%V?%V\" done",
1795
if (rc != NGX_AGAIN) {
1796
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1797
"http wake parent request: \"%V?%V\"",
1798
&pr->uri, &pr->args);
1800
pr->write_event_handler(pr);
1807
if (rc == NGX_AGAIN) {
1812
(void) ngx_http_set_write_handler(r);
1926
r->write_event_handler = ngx_http_request_finalizer;
1933
if (ngx_http_post_request(pr) != NGX_OK) {
1934
ngx_http_close_request(r->main, 0);
1938
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1939
"http wake parent request: \"%V?%V\"",
1940
&pr->uri, &pr->args);
1945
if (r->buffered || c->buffered || r->postponed) {
1947
if (ngx_http_set_write_handler(r) != NGX_OK) {
1948
ngx_http_close_request(r, 0);
1955
ngx_log_error(NGX_LOG_ALERT, c->log, 0,
1956
"http finalize non-active request: \"%V?%V\"",
1816
1963
if (!r->post_action) {
1817
1964
r->request_complete = 1;
1952
2098
"http writer output filter: %d, \"%V?%V\"",
1953
2099
rc, &r->uri, &r->args);
1955
if (rc == NGX_AGAIN) {
1956
clcf = ngx_http_get_module_loc_conf(r->main, ngx_http_core_module);
2101
if (rc == NGX_ERROR) {
2102
ngx_http_finalize_request(r, rc);
2106
if (r->buffered || r->postponed || (r == r->main && c->buffered)) {
1957
2108
if (!wev->ready && !wev->delayed) {
1958
2109
ngx_add_timer(wev, clcf->send_timeout);
1961
if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) {
2112
if (ngx_handle_write_event(wev, clcf->send_lowat) != NGX_OK) {
1962
2113
ngx_http_close_request(r, 0);
1965
if (r == r->main || r->buffered) {
1972
2119
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, wev->log, 0,
2626
2786
r->headers_out.status = error;
2629
cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
2631
log_handler = cmcf->phases[NGX_HTTP_LOG_PHASE].handlers.elts;
2632
n = cmcf->phases[NGX_HTTP_LOG_PHASE].handlers.nelts;
2633
for (i = 0; i < n; i++) {
2789
log->action = "logging request";
2791
ngx_http_log_request(r);
2793
log->action = "closing request";
2637
2795
if (r->connection->timedout) {
2638
2796
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);