mirror of
https://github.com/nginx/nginx.git
synced 2025-06-07 17:52:38 +08:00
nginx-0.0.7-2004-07-18-23:11:20 import
This commit is contained in:
parent
f38e046a0a
commit
74a5ddb47a
@ -74,6 +74,9 @@ struct ngx_connection_s {
|
|||||||
|
|
||||||
ngx_socket_t fd;
|
ngx_socket_t fd;
|
||||||
|
|
||||||
|
ngx_recv_pt recv;
|
||||||
|
ngx_send_chain_pt send_chain;
|
||||||
|
|
||||||
ngx_listening_t *listening;
|
ngx_listening_t *listening;
|
||||||
|
|
||||||
off_t sent;
|
off_t sent;
|
||||||
@ -120,6 +123,11 @@ struct ngx_connection_s {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef ngx_ssl_set_nosendshut
|
||||||
|
#define ngx_ssl_set_nosendshut(ssl)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle);
|
ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle);
|
||||||
ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle);
|
ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle);
|
||||||
void ngx_close_listening_sockets(ngx_cycle_t *cycle);
|
void ngx_close_listening_sockets(ngx_cycle_t *cycle);
|
||||||
|
@ -258,6 +258,9 @@ void ngx_event_accept(ngx_event_t *ev)
|
|||||||
c->ctx = ls->ctx;
|
c->ctx = ls->ctx;
|
||||||
c->servers = ls->servers;
|
c->servers = ls->servers;
|
||||||
|
|
||||||
|
c->recv = ngx_recv;
|
||||||
|
c->send_chain = ngx_send_chain;
|
||||||
|
|
||||||
c->log = log;
|
c->log = log;
|
||||||
rev->log = log;
|
rev->log = log;
|
||||||
wev->log = log;
|
wev->log = log;
|
||||||
|
@ -64,10 +64,10 @@ ngx_int_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size)
|
|||||||
|
|
||||||
sslerr = SSL_get_error(c->ssl->ssl, n);
|
sslerr = SSL_get_error(c->ssl->ssl, n);
|
||||||
|
|
||||||
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d", sslerr);
|
|
||||||
|
|
||||||
err = (sslerr == SSL_ERROR_SYSCALL) ? ngx_errno : 0;
|
err = (sslerr == SSL_ERROR_SYSCALL) ? ngx_errno : 0;
|
||||||
|
|
||||||
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d", sslerr);
|
||||||
|
|
||||||
if (sslerr == SSL_ERROR_WANT_READ) {
|
if (sslerr == SSL_ERROR_WANT_READ) {
|
||||||
return NGX_AGAIN;
|
return NGX_AGAIN;
|
||||||
}
|
}
|
||||||
@ -85,20 +85,18 @@ ngx_int_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size)
|
|||||||
handshake = "";
|
handshake = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c->ssl->no_rcv_shut = 1;
|
||||||
|
|
||||||
if (sslerr == SSL_ERROR_ZERO_RETURN || ERR_peek_error() == 0) {
|
if (sslerr == SSL_ERROR_ZERO_RETURN || ERR_peek_error() == 0) {
|
||||||
ngx_log_error(NGX_LOG_INFO, c->log, err,
|
ngx_log_error(NGX_LOG_INFO, c->log, err,
|
||||||
"client closed connection%s", handshake);
|
"client closed connection%s", handshake);
|
||||||
|
|
||||||
SSL_set_shutdown(c->ssl->ssl, SSL_RECEIVED_SHUTDOWN);
|
|
||||||
|
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngx_ssl_error(NGX_LOG_ALERT, c->log, err,
|
ngx_ssl_error(NGX_LOG_ALERT, c->log, err,
|
||||||
"SSL_read() failed%s", handshake);
|
"SSL_read() failed%s", handshake);
|
||||||
|
|
||||||
SSL_set_shutdown(c->ssl->ssl, SSL_RECEIVED_SHUTDOWN);
|
|
||||||
|
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +104,8 @@ ngx_int_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size)
|
|||||||
ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in,
|
ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in,
|
||||||
off_t limit)
|
off_t limit)
|
||||||
{
|
{
|
||||||
int n;
|
int n, sslerr;
|
||||||
|
ngx_err_t err;
|
||||||
ssize_t send, size;
|
ssize_t send, size;
|
||||||
ngx_buf_t *buf;
|
ngx_buf_t *buf;
|
||||||
|
|
||||||
@ -157,6 +156,7 @@ ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in,
|
|||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
buf->pos += n;
|
buf->pos += n;
|
||||||
send += n;
|
send += n;
|
||||||
|
c->sent += n;
|
||||||
|
|
||||||
if (n < size) {
|
if (n < size) {
|
||||||
break;
|
break;
|
||||||
@ -233,6 +233,7 @@ ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in,
|
|||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
in->buf->pos += n;
|
in->buf->pos += n;
|
||||||
send += n;
|
send += n;
|
||||||
|
c->sent += n;
|
||||||
|
|
||||||
if (n == size) {
|
if (n == size) {
|
||||||
if (send < limit) {
|
if (send < limit) {
|
||||||
@ -246,21 +247,26 @@ ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in,
|
|||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = SSL_get_error(c->ssl->ssl, n);
|
sslerr = SSL_get_error(c->ssl->ssl, n);
|
||||||
|
|
||||||
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d", n);
|
err = (sslerr == SSL_ERROR_SYSCALL) ? ngx_errno : 0;
|
||||||
|
|
||||||
if (n == SSL_ERROR_WANT_WRITE) {
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
||||||
|
"SSL_get_error: %d", sslerr);
|
||||||
|
|
||||||
|
if (sslerr == SSL_ERROR_WANT_WRITE) {
|
||||||
c->write->ready = 0;
|
c->write->ready = 0;
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (n == SSL_ERROR_WANT_READ) {
|
if (sslerr == SSL_ERROR_WANT_READ) {
|
||||||
return NGX_AGAIN;
|
return NGX_AGAIN;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
c->ssl->no_rcv_shut = 1;
|
||||||
|
|
||||||
ngx_ssl_error(NGX_LOG_ALERT, c->log, 0, "SSL_write() failed");
|
ngx_ssl_error(NGX_LOG_ALERT, c->log, 0, "SSL_write() failed");
|
||||||
|
|
||||||
return NGX_CHAIN_ERROR;
|
return NGX_CHAIN_ERROR;
|
||||||
@ -272,19 +278,21 @@ ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in,
|
|||||||
|
|
||||||
ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c)
|
ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c)
|
||||||
{
|
{
|
||||||
int n;
|
int n, sslerr;
|
||||||
ngx_uint_t again;
|
ngx_uint_t again;
|
||||||
|
|
||||||
#if 0
|
if (c->timedout) {
|
||||||
if (c->read->timedout || c->write->timedout) {
|
SSL_set_shutdown(c->ssl->ssl, SSL_RECEIVED_SHUTDOWN|SSL_SENT_SHUTDOWN);
|
||||||
SSL_set_shutdown(c->ssl, SSL_RECEIVED_SHUTDOWN);
|
|
||||||
SSL_set_shutdown(c->ssl, SSL_RECEIVED_SHUTDOWN|SSL_SENT_SHUTDOWN);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 0
|
} else {
|
||||||
|
if (c->ssl->no_rcv_shut) {
|
||||||
SSL_set_shutdown(c->ssl->ssl, SSL_RECEIVED_SHUTDOWN);
|
SSL_set_shutdown(c->ssl->ssl, SSL_RECEIVED_SHUTDOWN);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
|
if (c->ssl->no_send_shut) {
|
||||||
|
SSL_set_shutdown(c->ssl->ssl, SSL_SENT_SHUTDOWN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
again = 0;
|
again = 0;
|
||||||
|
|
||||||
@ -308,12 +316,13 @@ ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!again) {
|
if (!again) {
|
||||||
n = SSL_get_error(c->ssl->ssl, n);
|
sslerr = SSL_get_error(c->ssl->ssl, n);
|
||||||
|
|
||||||
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d", n);
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
||||||
|
"SSL_get_error: %d", sslerr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (again || n == SSL_ERROR_WANT_READ) {
|
if (again || sslerr == SSL_ERROR_WANT_READ) {
|
||||||
|
|
||||||
ngx_add_timer(c->read, 10000);
|
ngx_add_timer(c->read, 10000);
|
||||||
|
|
||||||
@ -324,7 +333,7 @@ ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c)
|
|||||||
return NGX_AGAIN;
|
return NGX_AGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n == SSL_ERROR_WANT_WRITE) {
|
if (sslerr == SSL_ERROR_WANT_WRITE) {
|
||||||
|
|
||||||
if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) {
|
if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) {
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
|
@ -13,6 +13,9 @@ typedef struct {
|
|||||||
SSL *ssl;
|
SSL *ssl;
|
||||||
ngx_buf_t *buf;
|
ngx_buf_t *buf;
|
||||||
ngx_event_handler_pt saved_handler;
|
ngx_event_handler_pt saved_handler;
|
||||||
|
|
||||||
|
unsigned no_rcv_shut:1;
|
||||||
|
unsigned no_send_shut:1;
|
||||||
} ngx_ssl_t;
|
} ngx_ssl_t;
|
||||||
|
|
||||||
|
|
||||||
@ -28,6 +31,9 @@ typedef SSL_CTX ngx_ssl_ctx_t;
|
|||||||
ngx_int_t ngx_ssl_init(ngx_log_t *log);
|
ngx_int_t ngx_ssl_init(ngx_log_t *log);
|
||||||
ngx_int_t ngx_ssl_create_session(ngx_ssl_ctx_t *ctx, ngx_connection_t *c,
|
ngx_int_t ngx_ssl_create_session(ngx_ssl_ctx_t *ctx, ngx_connection_t *c,
|
||||||
ngx_uint_t flags);
|
ngx_uint_t flags);
|
||||||
|
|
||||||
|
#define ngx_ssl_handshake(c) NGX_OK
|
||||||
|
|
||||||
ngx_int_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size);
|
ngx_int_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size);
|
||||||
ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in,
|
ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in,
|
||||||
off_t limit);
|
off_t limit);
|
||||||
@ -35,5 +41,10 @@ ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c);
|
|||||||
void ngx_ssl_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
|
void ngx_ssl_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
|
||||||
char *fmt, ...);
|
char *fmt, ...);
|
||||||
|
|
||||||
|
#define ngx_ssl_set_nosendshut(ssl) \
|
||||||
|
if (ssl) { \
|
||||||
|
ssl->no_send_shut = 1; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif /* _NGX_EVENT_OPENSSL_H_INCLUDED_ */
|
#endif /* _NGX_EVENT_OPENSSL_H_INCLUDED_ */
|
||||||
|
@ -190,13 +190,8 @@ static char *ngx_http_access_merge_loc_conf(ngx_conf_t *cf,
|
|||||||
static ngx_int_t ngx_http_access_init(ngx_cycle_t *cycle)
|
static ngx_int_t ngx_http_access_init(ngx_cycle_t *cycle)
|
||||||
{
|
{
|
||||||
ngx_http_handler_pt *h;
|
ngx_http_handler_pt *h;
|
||||||
ngx_http_conf_ctx_t *ctx;
|
|
||||||
ngx_http_core_main_conf_t *cmcf;
|
ngx_http_core_main_conf_t *cmcf;
|
||||||
|
|
||||||
#if 0
|
|
||||||
ctx = (ngx_http_conf_ctx_t *) cycle->conf_ctx[ngx_http_module.index];
|
|
||||||
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
|
|
||||||
#endif
|
|
||||||
cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
|
cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
|
||||||
|
|
||||||
h = ngx_push_array(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
|
h = ngx_push_array(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
|
||||||
|
@ -363,7 +363,6 @@ static char *ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
|||||||
ngx_int_t *cp;
|
ngx_int_t *cp;
|
||||||
ngx_str_t *value;
|
ngx_str_t *value;
|
||||||
ngx_http_charset_t *charset;
|
ngx_http_charset_t *charset;
|
||||||
ngx_http_conf_ctx_t *ctx;
|
|
||||||
ngx_http_charset_main_conf_t *mcf;
|
ngx_http_charset_main_conf_t *mcf;
|
||||||
|
|
||||||
cp = (ngx_int_t *) (p + cmd->offset);
|
cp = (ngx_int_t *) (p + cmd->offset);
|
||||||
@ -372,8 +371,9 @@ static char *ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
|||||||
return "is duplicate";
|
return "is duplicate";
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = cf->ctx;
|
mcf = ngx_http_conf_get_module_main_conf(cf,
|
||||||
mcf = ctx->main_conf[ngx_http_charset_filter_module.ctx_index];
|
ngx_http_charset_filter_module);
|
||||||
|
|
||||||
value = cf->args->elts;
|
value = cf->args->elts;
|
||||||
|
|
||||||
*cp = ngx_http_add_charset(&mcf->charsets, &value[1]);
|
*cp = ngx_http_add_charset(&mcf->charsets, &value[1]);
|
||||||
|
@ -98,6 +98,7 @@ ngx_module_t ngx_http_index_module = {
|
|||||||
ngx_int_t ngx_http_index_handler(ngx_http_request_t *r)
|
ngx_int_t ngx_http_index_handler(ngx_http_request_t *r)
|
||||||
{
|
{
|
||||||
u_char *name;
|
u_char *name;
|
||||||
|
size_t len;
|
||||||
ngx_fd_t fd;
|
ngx_fd_t fd;
|
||||||
ngx_int_t rc;
|
ngx_int_t rc;
|
||||||
ngx_str_t *index;
|
ngx_str_t *index;
|
||||||
@ -160,6 +161,7 @@ ngx_int_t ngx_http_index_handler(ngx_http_request_t *r)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
ctx->path.data = ngx_palloc(r->pool, clcf->root.len + r->uri.len
|
ctx->path.data = ngx_palloc(r->pool, clcf->root.len + r->uri.len
|
||||||
+ ilcf->max_index_len
|
+ ilcf->max_index_len
|
||||||
- clcf->alias * clcf->name.len);
|
- clcf->alias * clcf->name.len);
|
||||||
@ -169,9 +171,35 @@ ngx_int_t ngx_http_index_handler(ngx_http_request_t *r)
|
|||||||
|
|
||||||
ctx->redirect.data = ngx_cpymem(ctx->path.data, clcf->root.data,
|
ctx->redirect.data = ngx_cpymem(ctx->path.data, clcf->root.data,
|
||||||
clcf->root.len);
|
clcf->root.len);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (clcf->alias) {
|
if (clcf->alias) {
|
||||||
ctx->last = ngx_cpystrn(ctx->redirect.data,
|
if (clcf->root.len > clcf->name.len) {
|
||||||
|
ctx->path.data = ngx_palloc(r->pool, clcf->root.len
|
||||||
|
+ r->uri.len
|
||||||
|
- clcf->name.len
|
||||||
|
+ ilcf->max_index_len);
|
||||||
|
if (ctx->path.data == NULL) {
|
||||||
|
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->redirect.data = ctx->path.data + clcf->root.len + 1
|
||||||
|
- clcf->name.len;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ctx->redirect.data = ngx_palloc(r->pool, r->uri.len
|
||||||
|
+ ilcf->max_index_len);
|
||||||
|
if (ctx->redirect.data == NULL) {
|
||||||
|
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->path.data = ctx->redirect.data + clcf->name.len
|
||||||
|
- clcf->root.len;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_memcpy(ctx->path.data, clcf->root.data, clcf->root.len);
|
||||||
|
|
||||||
|
ctx->last = ngx_cpystrn(ctx->path.data + clcf->root.len,
|
||||||
r->uri.data + clcf->name.len,
|
r->uri.data + clcf->name.len,
|
||||||
r->uri.len + 1 - clcf->name.len);
|
r->uri.len + 1 - clcf->name.len);
|
||||||
|
|
||||||
@ -185,6 +213,15 @@ ngx_int_t ngx_http_index_handler(ngx_http_request_t *r)
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
ctx->path.data = ngx_palloc(r->pool, clcf->root.len + r->uri.len
|
||||||
|
+ ilcf->max_index_len);
|
||||||
|
if (ctx->path.data == NULL) {
|
||||||
|
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->redirect.data = ngx_cpymem(ctx->path.data, clcf->root.data,
|
||||||
|
clcf->root.len);
|
||||||
|
|
||||||
ctx->last = ngx_cpystrn(ctx->redirect.data, r->uri.data,
|
ctx->last = ngx_cpystrn(ctx->redirect.data, r->uri.data,
|
||||||
r->uri.len + 1);
|
r->uri.len + 1);
|
||||||
}
|
}
|
||||||
@ -255,8 +292,14 @@ ngx_int_t ngx_http_index_handler(ngx_http_request_t *r)
|
|||||||
ctx->redirect.data = index[ctx->index].data;
|
ctx->redirect.data = index[ctx->index].data;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ctx->redirect.len = r->uri.len + index[ctx->index].len;
|
if (clcf->alias) {
|
||||||
|
ngx_memcpy(ctx->redirect.data, clcf->name.data, clcf->name.len);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->redirect.len = r->uri.len + index[ctx->index].len
|
||||||
|
- clcf->alias * clcf->name.len;
|
||||||
r->file.name.len = clcf->root.len + r->uri.len
|
r->file.name.len = clcf->root.len + r->uri.len
|
||||||
|
- clcf->alias * clcf->name.len
|
||||||
+ index[ctx->index].len;
|
+ index[ctx->index].len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,11 +407,9 @@ static ngx_int_t ngx_http_index_error(ngx_http_request_t *r,
|
|||||||
static ngx_int_t ngx_http_index_init(ngx_cycle_t *cycle)
|
static ngx_int_t ngx_http_index_init(ngx_cycle_t *cycle)
|
||||||
{
|
{
|
||||||
ngx_http_handler_pt *h;
|
ngx_http_handler_pt *h;
|
||||||
ngx_http_conf_ctx_t *ctx;
|
|
||||||
ngx_http_core_main_conf_t *cmcf;
|
ngx_http_core_main_conf_t *cmcf;
|
||||||
|
|
||||||
ctx = (ngx_http_conf_ctx_t *) cycle->conf_ctx[ngx_http_module.index];
|
cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
|
||||||
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
|
|
||||||
|
|
||||||
h = ngx_push_array(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
|
h = ngx_push_array(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
|
@ -369,11 +369,9 @@ static char *ngx_http_rewrite_rule(ngx_conf_t *cf, ngx_command_t *cmd,
|
|||||||
static ngx_int_t ngx_http_rewrite_init(ngx_cycle_t *cycle)
|
static ngx_int_t ngx_http_rewrite_init(ngx_cycle_t *cycle)
|
||||||
{
|
{
|
||||||
ngx_http_handler_pt *h;
|
ngx_http_handler_pt *h;
|
||||||
ngx_http_conf_ctx_t *ctx;
|
|
||||||
ngx_http_core_main_conf_t *cmcf;
|
ngx_http_core_main_conf_t *cmcf;
|
||||||
|
|
||||||
ctx = (ngx_http_conf_ctx_t *) cycle->conf_ctx[ngx_http_module.index];
|
cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
|
||||||
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
|
|
||||||
|
|
||||||
h = ngx_push_array(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers);
|
h = ngx_push_array(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers);
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
|
@ -105,7 +105,8 @@ static char *ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf,
|
|||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SSL_CTX_use_certificate_file(conf->ssl_ctx, conf->certificate.data,
|
if (SSL_CTX_use_certificate_file(conf->ssl_ctx,
|
||||||
|
(char *) conf->certificate.data,
|
||||||
SSL_FILETYPE_PEM) == 0) {
|
SSL_FILETYPE_PEM) == 0) {
|
||||||
ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0,
|
ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0,
|
||||||
"SSL_CTX_use_certificate_file(\"%s\") failed",
|
"SSL_CTX_use_certificate_file(\"%s\") failed",
|
||||||
@ -113,7 +114,8 @@ static char *ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf,
|
|||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SSL_CTX_use_PrivateKey_file(conf->ssl_ctx, conf->certificate_key.data,
|
if (SSL_CTX_use_PrivateKey_file(conf->ssl_ctx,
|
||||||
|
(char *) conf->certificate_key.data,
|
||||||
SSL_FILETYPE_PEM) == 0) {
|
SSL_FILETYPE_PEM) == 0) {
|
||||||
ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0,
|
ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0,
|
||||||
"SSL_CTX_use_PrivateKey_file(\"%s\") failed",
|
"SSL_CTX_use_PrivateKey_file(\"%s\") failed",
|
||||||
|
@ -537,11 +537,9 @@ static char *ngx_http_static_merge_loc_conf(ngx_conf_t *cf,
|
|||||||
static ngx_int_t ngx_http_static_init(ngx_cycle_t *cycle)
|
static ngx_int_t ngx_http_static_init(ngx_cycle_t *cycle)
|
||||||
{
|
{
|
||||||
ngx_http_handler_pt *h;
|
ngx_http_handler_pt *h;
|
||||||
ngx_http_conf_ctx_t *ctx;
|
|
||||||
ngx_http_core_main_conf_t *cmcf;
|
ngx_http_core_main_conf_t *cmcf;
|
||||||
|
|
||||||
ctx = (ngx_http_conf_ctx_t *) cycle->conf_ctx[ngx_http_module.index];
|
cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
|
||||||
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
|
|
||||||
|
|
||||||
h = ngx_push_array(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
|
h = ngx_push_array(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
|
@ -299,11 +299,9 @@ static ngx_int_t ngx_http_status(ngx_http_status_ctx_t *ctx)
|
|||||||
|
|
||||||
static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||||
{
|
{
|
||||||
ngx_http_conf_ctx_t *ctx;
|
|
||||||
ngx_http_core_loc_conf_t *clcf;
|
ngx_http_core_loc_conf_t *clcf;
|
||||||
|
|
||||||
ctx = cf->ctx;
|
clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
|
||||||
clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
||||||
clcf->handler = ngx_http_status_handler;
|
clcf->handler = ngx_http_status_handler;
|
||||||
|
|
||||||
return NGX_CONF_OK;
|
return NGX_CONF_OK;
|
||||||
|
@ -1062,7 +1062,6 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
|
|||||||
in_addr_t addr;
|
in_addr_t addr;
|
||||||
ngx_str_t *value;
|
ngx_str_t *value;
|
||||||
struct hostent *h;
|
struct hostent *h;
|
||||||
ngx_http_conf_ctx_t *ctx;
|
|
||||||
ngx_http_core_loc_conf_t *clcf;
|
ngx_http_core_loc_conf_t *clcf;
|
||||||
|
|
||||||
|
|
||||||
@ -1177,10 +1176,11 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
|
|||||||
lcf->upstream->port_text.len + 1);
|
lcf->upstream->port_text.len + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = cf->ctx;
|
clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
|
||||||
clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
||||||
lcf->upstream->location = &clcf->name;
|
lcf->upstream->location = &clcf->name;
|
||||||
clcf->handler = ngx_http_proxy_handler;
|
clcf->handler = ngx_http_proxy_handler;
|
||||||
|
|
||||||
if (clcf->name.data[clcf->name.len - 1] == '/') {
|
if (clcf->name.data[clcf->name.len - 1] == '/') {
|
||||||
clcf->auto_redirect = 1;
|
clcf->auto_redirect = 1;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,11 @@
|
|||||||
|
|
||||||
|
|
||||||
static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||||
|
static char *ngx_http_merge_locations(ngx_conf_t *cf,
|
||||||
|
ngx_array_t *locations,
|
||||||
|
void **loc_conf,
|
||||||
|
ngx_http_module_t *module,
|
||||||
|
ngx_uint_t ctx_index);
|
||||||
|
|
||||||
int ngx_http_max_module;
|
int ngx_http_max_module;
|
||||||
|
|
||||||
@ -204,7 +208,16 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
|
|
||||||
/* merge the locations{}' loc_conf's */
|
/* merge the locations{}' loc_conf's */
|
||||||
|
|
||||||
clcfp = (ngx_http_core_loc_conf_t **)cscfp[s]->locations.elts;
|
rv = ngx_http_merge_locations(cf, &cscfp[s]->locations,
|
||||||
|
cscfp[s]->ctx->loc_conf,
|
||||||
|
module, mi);
|
||||||
|
if (rv != NGX_CONF_OK) {
|
||||||
|
*cf = pcf;
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
clcfp = (ngx_http_core_loc_conf_t **) cscfp[s]->locations.elts;
|
||||||
|
|
||||||
for (l = 0; l < cscfp[s]->locations.nelts; l++) {
|
for (l = 0; l < cscfp[s]->locations.nelts; l++) {
|
||||||
rv = module->merge_loc_conf(cf,
|
rv = module->merge_loc_conf(cf,
|
||||||
@ -215,6 +228,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -623,3 +637,33 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
|
|
||||||
return NGX_CONF_OK;
|
return NGX_CONF_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char *ngx_http_merge_locations(ngx_conf_t *cf,
|
||||||
|
ngx_array_t *locations,
|
||||||
|
void **loc_conf,
|
||||||
|
ngx_http_module_t *module,
|
||||||
|
ngx_uint_t ctx_index)
|
||||||
|
{
|
||||||
|
char *rv;
|
||||||
|
ngx_uint_t i;
|
||||||
|
ngx_http_core_loc_conf_t **clcfp;
|
||||||
|
|
||||||
|
clcfp = /* (ngx_http_core_loc_conf_t **) */ locations->elts;
|
||||||
|
|
||||||
|
for (i = 0; i < locations->nelts; i++) {
|
||||||
|
rv = module->merge_loc_conf(cf, loc_conf[ctx_index],
|
||||||
|
clcfp[i]->loc_conf[ctx_index]);
|
||||||
|
if (rv != NGX_CONF_OK) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
rv = ngx_http_merge_locations(cf, &clcfp[i]->locations,
|
||||||
|
clcfp[i]->loc_conf, module, ctx_index);
|
||||||
|
if (rv != NGX_CONF_OK) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NGX_CONF_OK;
|
||||||
|
}
|
||||||
|
@ -43,14 +43,18 @@ typedef struct {
|
|||||||
#define ngx_http_get_module_srv_conf(r, module) r->srv_conf[module.ctx_index]
|
#define ngx_http_get_module_srv_conf(r, module) r->srv_conf[module.ctx_index]
|
||||||
#define ngx_http_get_module_loc_conf(r, module) r->loc_conf[module.ctx_index]
|
#define ngx_http_get_module_loc_conf(r, module) r->loc_conf[module.ctx_index]
|
||||||
|
|
||||||
#define ngx_http_conf_get_module_main_conf(cf, module) \
|
|
||||||
((ngx_http_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index]
|
|
||||||
/*
|
/*
|
||||||
* ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
|
* ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
|
||||||
* could not be correctly implemented because at the merge phase cf->ctx
|
* msut not be used because at the merge phase cf->ctx points to http{}'s ctx
|
||||||
* points to http{}'s ctx
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define ngx_http_conf_get_module_main_conf(cf, module) \
|
||||||
|
((ngx_http_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index]
|
||||||
|
#define ngx_http_conf_get_module_srv_conf(cf, module) \
|
||||||
|
((ngx_http_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index]
|
||||||
|
#define ngx_http_conf_get_module_loc_conf(cf, module) \
|
||||||
|
((ngx_http_conf_ctx_t *) cf->ctx)->loc_conf[module.ctx_index]
|
||||||
|
|
||||||
#define ngx_http_cycle_get_module_main_conf(cycle, module) \
|
#define ngx_http_cycle_get_module_main_conf(cycle, module) \
|
||||||
((ngx_http_conf_ctx_t *) \
|
((ngx_http_conf_ctx_t *) \
|
||||||
cycle->conf_ctx[ngx_http_module.index])->main_conf[module.ctx_index]
|
cycle->conf_ctx[ngx_http_module.index])->main_conf[module.ctx_index]
|
||||||
|
@ -5,9 +5,16 @@
|
|||||||
#include <ngx_http.h>
|
#include <ngx_http.h>
|
||||||
#include <nginx.h>
|
#include <nginx.h>
|
||||||
|
|
||||||
|
/* STUB */
|
||||||
|
#define NGX_HTTP_LOCATION_EXACT 1
|
||||||
|
#define NGX_HTTP_LOCATION_AUTO_REDIRECT 2
|
||||||
|
#define NGX_HTTP_LOCATION_REGEX 3
|
||||||
|
|
||||||
|
|
||||||
static void ngx_http_phase_event_handler(ngx_event_t *rev);
|
static void ngx_http_phase_event_handler(ngx_event_t *rev);
|
||||||
static void ngx_http_run_phases(ngx_http_request_t *r);
|
static void ngx_http_run_phases(ngx_http_request_t *r);
|
||||||
|
static ngx_int_t ngx_http_find_location(ngx_http_request_t *r,
|
||||||
|
ngx_array_t *locations);
|
||||||
|
|
||||||
static void *ngx_http_core_create_main_conf(ngx_conf_t *cf);
|
static void *ngx_http_core_create_main_conf(ngx_conf_t *cf);
|
||||||
static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf);
|
static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf);
|
||||||
@ -103,7 +110,7 @@ static ngx_command_t ngx_http_core_commands[] = {
|
|||||||
&ngx_http_restrict_host_names },
|
&ngx_http_restrict_host_names },
|
||||||
|
|
||||||
{ ngx_string("location"),
|
{ ngx_string("location"),
|
||||||
NGX_HTTP_SRV_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12,
|
NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12,
|
||||||
ngx_location_block,
|
ngx_location_block,
|
||||||
NGX_HTTP_SRV_CONF_OFFSET,
|
NGX_HTTP_SRV_CONF_OFFSET,
|
||||||
0,
|
0,
|
||||||
@ -463,121 +470,25 @@ static void ngx_http_run_phases(ngx_http_request_t *r)
|
|||||||
|
|
||||||
ngx_int_t ngx_http_find_location_config(ngx_http_request_t *r)
|
ngx_int_t ngx_http_find_location_config(ngx_http_request_t *r)
|
||||||
{
|
{
|
||||||
int rc;
|
ngx_int_t rc;
|
||||||
ngx_uint_t i;
|
ngx_http_core_loc_conf_t *clcf;
|
||||||
ngx_str_t *auto_redirect;
|
|
||||||
ngx_http_core_loc_conf_t *clcf, **clcfp;
|
|
||||||
ngx_http_core_srv_conf_t *cscf;
|
ngx_http_core_srv_conf_t *cscf;
|
||||||
#if (HAVE_PCRE)
|
|
||||||
ngx_uint_t exact;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
||||||
auto_redirect = NULL;
|
|
||||||
#if (HAVE_PCRE)
|
|
||||||
exact = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
clcfp = cscf->locations.elts;
|
rc = ngx_http_find_location(r, &cscf->locations);
|
||||||
for (i = 0; i < cscf->locations.nelts; i++) {
|
|
||||||
|
|
||||||
#if (HAVE_PCRE)
|
if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) {
|
||||||
|
return rc;
|
||||||
if (clcfp[i]->regex) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
||||||
"find location: %s\"%s\"",
|
|
||||||
clcfp[i]->exact_match ? "= " : "",
|
|
||||||
clcfp[i]->name.data);
|
|
||||||
|
|
||||||
if (clcfp[i]->auto_redirect
|
|
||||||
&& r->uri.len == clcfp[i]->name.len - 1
|
|
||||||
&& ngx_strncmp(r->uri.data, clcfp[i]->name.data,
|
|
||||||
clcfp[i]->name.len - 1) == 0)
|
|
||||||
{
|
|
||||||
auto_redirect = &clcfp[i]->name;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r->uri.len < clcfp[i]->name.len) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = ngx_strncmp(r->uri.data, clcfp[i]->name.data, clcfp[i]->name.len);
|
|
||||||
|
|
||||||
if (rc < 0) {
|
|
||||||
/* locations are lexicographically sorted */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rc == 0) {
|
|
||||||
r->loc_conf = clcfp[i]->loc_conf;
|
|
||||||
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
||||||
|
|
||||||
r->connection->log->file = clcf->err_log->file;
|
r->connection->log->file = clcf->err_log->file;
|
||||||
if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
|
if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
|
||||||
r->connection->log->log_level = clcf->err_log->log_level;
|
r->connection->log->log_level = clcf->err_log->log_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clcfp[i]->exact_match && r->uri.len == clcfp[i]->name.len) {
|
|
||||||
#if (HAVE_PCRE)
|
|
||||||
exact = 1;
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (HAVE_PCRE)
|
|
||||||
|
|
||||||
if (!exact && !auto_redirect) {
|
|
||||||
/* regex matches */
|
|
||||||
|
|
||||||
for (/* void */; i < cscf->locations.nelts; i++) {
|
|
||||||
|
|
||||||
if (!clcfp[i]->regex) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
||||||
"find location: %s\"%s\"",
|
|
||||||
clcfp[i]->exact_match ? "= " :
|
|
||||||
clcfp[i]->regex ? "~ " : "",
|
|
||||||
clcfp[i]->name.data);
|
|
||||||
|
|
||||||
rc = ngx_regex_exec(clcfp[i]->regex, &r->uri, NULL, 0);
|
|
||||||
|
|
||||||
if (rc == NGX_DECLINED) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rc < 0) {
|
|
||||||
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
||||||
ngx_regex_exec_n
|
|
||||||
" failed: %d on \"%s\" using \"%s\"",
|
|
||||||
rc, r->uri.data, clcfp[i]->name.data);
|
|
||||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* match */
|
|
||||||
|
|
||||||
r->loc_conf = clcfp[i]->loc_conf;
|
|
||||||
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
||||||
r->connection->log->file = clcf->err_log->file;
|
|
||||||
if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
|
|
||||||
r->connection->log->log_level = clcf->err_log->log_level;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* HAVE_PCRE */
|
|
||||||
|
|
||||||
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
||||||
|
|
||||||
if (!(ngx_io.flags & NGX_IO_SENDFILE) || !clcf->sendfile) {
|
if (!(ngx_io.flags & NGX_IO_SENDFILE) || !clcf->sendfile) {
|
||||||
r->sendfile = 0;
|
r->sendfile = 0;
|
||||||
|
|
||||||
@ -609,14 +520,14 @@ ngx_int_t ngx_http_find_location_config(ngx_http_request_t *r)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (auto_redirect) {
|
if (rc == NGX_HTTP_LOCATION_AUTO_REDIRECT) {
|
||||||
if (!(r->headers_out.location =
|
if (!(r->headers_out.location =
|
||||||
ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
|
ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
|
||||||
{
|
{
|
||||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
r->headers_out.location->value = *auto_redirect;
|
r->headers_out.location->value = clcf->name;
|
||||||
|
|
||||||
return NGX_HTTP_MOVED_PERMANENTLY;
|
return NGX_HTTP_MOVED_PERMANENTLY;
|
||||||
}
|
}
|
||||||
@ -629,6 +540,125 @@ ngx_int_t ngx_http_find_location_config(ngx_http_request_t *r)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ngx_int_t ngx_http_find_location(ngx_http_request_t *r,
|
||||||
|
ngx_array_t *locations)
|
||||||
|
{
|
||||||
|
ngx_int_t n, rc;
|
||||||
|
ngx_uint_t i, found;
|
||||||
|
ngx_http_core_loc_conf_t *clcf, **clcfp;
|
||||||
|
|
||||||
|
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "find location");
|
||||||
|
|
||||||
|
found = 0;
|
||||||
|
|
||||||
|
clcfp = locations->elts;
|
||||||
|
for (i = 0; i < locations->nelts; i++) {
|
||||||
|
|
||||||
|
#if (HAVE_PCRE)
|
||||||
|
if (clcfp[i]->regex) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||||
|
"find location: %s\"%s\"",
|
||||||
|
clcfp[i]->exact_match ? "= " : "",
|
||||||
|
clcfp[i]->name.data);
|
||||||
|
|
||||||
|
if (clcfp[i]->auto_redirect
|
||||||
|
&& r->uri.len == clcfp[i]->name.len - 1
|
||||||
|
&& ngx_strncmp(r->uri.data, clcfp[i]->name.data,
|
||||||
|
clcfp[i]->name.len - 1) == 0)
|
||||||
|
{
|
||||||
|
/* the locations are lexicographically sorted */
|
||||||
|
|
||||||
|
r->loc_conf = clcfp[i]->loc_conf;
|
||||||
|
|
||||||
|
return NGX_HTTP_LOCATION_AUTO_REDIRECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r->uri.len < clcfp[i]->name.len) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
n = ngx_strncmp(r->uri.data, clcfp[i]->name.data, clcfp[i]->name.len);
|
||||||
|
|
||||||
|
if (n < 0) {
|
||||||
|
/* the locations are lexicographically sorted */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n == 0) {
|
||||||
|
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
||||||
|
|
||||||
|
if (clcf->name.len >= clcfp[i]->name.len) {
|
||||||
|
/* the previous match is longer */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
r->loc_conf = clcfp[i]->loc_conf;
|
||||||
|
|
||||||
|
if (clcfp[i]->exact_match && r->uri.len == clcfp[i]->name.len) {
|
||||||
|
return NGX_HTTP_LOCATION_EXACT;
|
||||||
|
}
|
||||||
|
|
||||||
|
found = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found) {
|
||||||
|
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
||||||
|
|
||||||
|
if (clcf->locations.nelts) {
|
||||||
|
rc = ngx_http_find_location(r, &clcf->locations);
|
||||||
|
|
||||||
|
if (rc != NGX_OK) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (HAVE_PCRE)
|
||||||
|
|
||||||
|
/* regex matches */
|
||||||
|
|
||||||
|
for (/* void */; i < locations->nelts; i++) {
|
||||||
|
|
||||||
|
if (!clcfp[i]->regex) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||||
|
"find location: ~ \"%s\"",
|
||||||
|
clcfp[i]->name.data);
|
||||||
|
|
||||||
|
n = ngx_regex_exec(clcfp[i]->regex, &r->uri, NULL, 0);
|
||||||
|
|
||||||
|
if (n == NGX_DECLINED) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n < 0) {
|
||||||
|
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
||||||
|
ngx_regex_exec_n
|
||||||
|
" failed: %d on \"%s\" using \"%s\"",
|
||||||
|
n, r->uri.data, clcfp[i]->name.data);
|
||||||
|
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* match */
|
||||||
|
|
||||||
|
r->loc_conf = clcfp[i]->loc_conf;
|
||||||
|
|
||||||
|
return NGX_HTTP_LOCATION_REGEX;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* HAVE_PCRE */
|
||||||
|
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r)
|
ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r)
|
||||||
{
|
{
|
||||||
uint32_t key;
|
uint32_t key;
|
||||||
@ -799,7 +829,7 @@ ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 1 /* STUB: test the delay http handler */
|
#if 0 /* STUB: test the delay http handler */
|
||||||
|
|
||||||
int ngx_http_delay_handler(ngx_http_request_t *r)
|
int ngx_http_delay_handler(ngx_http_request_t *r)
|
||||||
{
|
{
|
||||||
@ -863,7 +893,7 @@ static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
|||||||
char *rv;
|
char *rv;
|
||||||
ngx_http_module_t *module;
|
ngx_http_module_t *module;
|
||||||
ngx_conf_t pvcf;
|
ngx_conf_t pvcf;
|
||||||
ngx_http_conf_ctx_t *ctx, *hctx;
|
ngx_http_conf_ctx_t *ctx, *http_ctx;
|
||||||
ngx_http_core_main_conf_t *cmcf;
|
ngx_http_core_main_conf_t *cmcf;
|
||||||
ngx_http_core_srv_conf_t *cscf, **cscfp;
|
ngx_http_core_srv_conf_t *cscf, **cscfp;
|
||||||
|
|
||||||
@ -871,8 +901,8 @@ static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
|||||||
ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)),
|
ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)),
|
||||||
NGX_CONF_ERROR);
|
NGX_CONF_ERROR);
|
||||||
|
|
||||||
hctx = (ngx_http_conf_ctx_t *) cf->ctx;
|
http_ctx = cf->ctx;
|
||||||
ctx->main_conf = hctx->main_conf;
|
ctx->main_conf = http_ctx->main_conf;
|
||||||
|
|
||||||
/* the server{}'s srv_conf */
|
/* the server{}'s srv_conf */
|
||||||
|
|
||||||
@ -928,7 +958,7 @@ static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngx_qsort(cscf->locations.elts, (size_t) cscf->locations.nelts,
|
ngx_qsort(cscf->locations.elts, (size_t) cscf->locations.nelts,
|
||||||
sizeof(void *), ngx_cmp_locations);
|
sizeof(ngx_http_core_loc_conf_t *), ngx_cmp_locations);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
@ -936,20 +966,21 @@ static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
|||||||
|
|
||||||
static int ngx_cmp_locations(const void *one, const void *two)
|
static int ngx_cmp_locations(const void *one, const void *two)
|
||||||
{
|
{
|
||||||
ngx_http_core_loc_conf_t *first = *(ngx_http_core_loc_conf_t **) one;
|
|
||||||
ngx_http_core_loc_conf_t *second = *(ngx_http_core_loc_conf_t **) two;
|
|
||||||
|
|
||||||
ngx_int_t rc;
|
ngx_int_t rc;
|
||||||
|
ngx_http_core_loc_conf_t *first, *second;
|
||||||
|
|
||||||
|
first = *(ngx_http_core_loc_conf_t **) one;
|
||||||
|
second = *(ngx_http_core_loc_conf_t **) two;
|
||||||
|
|
||||||
#if (HAVE_PCRE)
|
#if (HAVE_PCRE)
|
||||||
|
|
||||||
if (first->regex && !second->regex) {
|
if (first->regex && !second->regex) {
|
||||||
/* shift regex matches to the end */
|
/* shift the regex matches to the end */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (first->regex || second->regex) {
|
if (first->regex || second->regex) {
|
||||||
/* do not sort regex matches */
|
/* do not sort the regex matches */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -971,11 +1002,11 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
|||||||
char *rv;
|
char *rv;
|
||||||
ngx_int_t m;
|
ngx_int_t m;
|
||||||
ngx_str_t *value;
|
ngx_str_t *value;
|
||||||
|
ngx_conf_t pcf;
|
||||||
ngx_http_module_t *module;
|
ngx_http_module_t *module;
|
||||||
ngx_conf_t pvcf;
|
ngx_http_conf_ctx_t *ctx, *pctx;
|
||||||
ngx_http_conf_ctx_t *ctx, *pvctx;
|
|
||||||
ngx_http_core_srv_conf_t *cscf;
|
ngx_http_core_srv_conf_t *cscf;
|
||||||
ngx_http_core_loc_conf_t *clcf, **clcfp;
|
ngx_http_core_loc_conf_t *clcf, *pclcf, **clcfp;
|
||||||
#if (HAVE_PCRE)
|
#if (HAVE_PCRE)
|
||||||
ngx_str_t err;
|
ngx_str_t err;
|
||||||
u_char errstr[NGX_MAX_CONF_ERRSTR];
|
u_char errstr[NGX_MAX_CONF_ERRSTR];
|
||||||
@ -985,9 +1016,9 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
|||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
pvctx = (ngx_http_conf_ctx_t *) cf->ctx;
|
pctx = cf->ctx;
|
||||||
ctx->main_conf = pvctx->main_conf;
|
ctx->main_conf = pctx->main_conf;
|
||||||
ctx->srv_conf = pvctx->srv_conf;
|
ctx->srv_conf = pctx->srv_conf;
|
||||||
|
|
||||||
ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
||||||
if (ctx->loc_conf == NULL) {
|
if (ctx->loc_conf == NULL) {
|
||||||
@ -1060,17 +1091,52 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
|||||||
clcf->name.data = value[1].data;
|
clcf->name.data = value[1].data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
|
||||||
|
|
||||||
|
if (pclcf->name.len == 0) {
|
||||||
cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
|
cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
|
||||||
if (!(clcfp = ngx_push_array(&cscf->locations))) {
|
if (!(clcfp = ngx_push_array(&cscf->locations))) {
|
||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
clcf->prev_location = pclcf;
|
||||||
|
|
||||||
|
if (pclcf->exact_match) {
|
||||||
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||||
|
"location \"%s\" could not be inside "
|
||||||
|
"the exact location \"%s\"",
|
||||||
|
clcf->name.data, pclcf->name.data);
|
||||||
|
return NGX_CONF_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clcf->regex == NULL
|
||||||
|
&& ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len)
|
||||||
|
!= 0)
|
||||||
|
{
|
||||||
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||||
|
"location \"%s\" is outside location \"%s\"",
|
||||||
|
clcf->name.data, pclcf->name.data);
|
||||||
|
return NGX_CONF_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pclcf->locations.elts == NULL) {
|
||||||
|
ngx_init_array(pclcf->locations, cf->pool, 5, sizeof(void *),
|
||||||
|
NGX_CONF_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(clcfp = ngx_push_array(&pclcf->locations))) {
|
||||||
|
return NGX_CONF_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
*clcfp = clcf;
|
*clcfp = clcf;
|
||||||
|
|
||||||
pvcf = *cf;
|
pcf = *cf;
|
||||||
cf->ctx = ctx;
|
cf->ctx = ctx;
|
||||||
cf->cmd_type = NGX_HTTP_LOC_CONF;
|
cf->cmd_type = NGX_HTTP_LOC_CONF;
|
||||||
rv = ngx_conf_parse(cf, NULL);
|
rv = ngx_conf_parse(cf, NULL);
|
||||||
*cf = pvcf;
|
*cf = pcf;
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
@ -1220,9 +1286,12 @@ static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
|
|||||||
n->name.len = ngx_strlen(n->name.data);
|
n->name.len = ngx_strlen(n->name.data);
|
||||||
n->core_srv_conf = conf;
|
n->core_srv_conf = conf;
|
||||||
|
|
||||||
|
#if 0
|
||||||
ctx = (ngx_http_conf_ctx_t *)
|
ctx = (ngx_http_conf_ctx_t *)
|
||||||
cf->cycle->conf_ctx[ngx_http_module.index];
|
cf->cycle->conf_ctx[ngx_http_module.index];
|
||||||
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
|
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
|
||||||
|
#endif
|
||||||
|
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
|
||||||
|
|
||||||
if (cmcf->max_server_name_len < n->name.len) {
|
if (cmcf->max_server_name_len < n->name.len) {
|
||||||
cmcf->max_server_name_len = n->name.len;
|
cmcf->max_server_name_len = n->name.len;
|
||||||
@ -1478,8 +1547,11 @@ static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
/* TODO: several names */
|
/* TODO: several names */
|
||||||
/* TODO: warn about duplicate 'server_name' directives */
|
/* TODO: warn about duplicate 'server_name' directives */
|
||||||
|
|
||||||
|
#if 0
|
||||||
ctx = (ngx_http_conf_ctx_t *) cf->cycle->conf_ctx[ngx_http_module.index];
|
ctx = (ngx_http_conf_ctx_t *) cf->cycle->conf_ctx[ngx_http_module.index];
|
||||||
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
|
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
|
||||||
|
#endif
|
||||||
|
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
|
||||||
|
|
||||||
value = cf->args->elts;
|
value = cf->args->elts;
|
||||||
|
|
||||||
|
@ -124,9 +124,24 @@ typedef struct {
|
|||||||
} ngx_http_err_page_t;
|
} ngx_http_err_page_t;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct ngx_http_core_loc_conf_s ngx_http_core_loc_conf_t;
|
||||||
|
|
||||||
|
struct ngx_http_core_loc_conf_s {
|
||||||
ngx_str_t name; /* location name */
|
ngx_str_t name; /* location name */
|
||||||
void **loc_conf ; /* pointer to the modules' loc_conf */
|
|
||||||
|
#if (HAVE_PCRE)
|
||||||
|
ngx_regex_t *regex;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
unsigned exact_match:1;
|
||||||
|
unsigned auto_redirect:1;
|
||||||
|
unsigned alias:1;
|
||||||
|
|
||||||
|
/* array of inclusive ngx_http_core_loc_conf_t */
|
||||||
|
ngx_array_t locations;
|
||||||
|
|
||||||
|
/* pointer to the modules' loc_conf */
|
||||||
|
void **loc_conf ;
|
||||||
|
|
||||||
ngx_http_handler_pt handler;
|
ngx_http_handler_pt handler;
|
||||||
|
|
||||||
@ -157,16 +172,10 @@ typedef struct {
|
|||||||
|
|
||||||
ngx_http_cache_hash_t *open_files;
|
ngx_http_cache_hash_t *open_files;
|
||||||
|
|
||||||
#if (HAVE_PCRE)
|
|
||||||
ngx_regex_t *regex;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
unsigned exact_match:1;
|
|
||||||
unsigned auto_redirect:1;
|
|
||||||
unsigned alias:1;
|
|
||||||
|
|
||||||
ngx_log_t *err_log;
|
ngx_log_t *err_log;
|
||||||
} ngx_http_core_loc_conf_t;
|
|
||||||
|
ngx_http_core_loc_conf_t *prev_location;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
extern ngx_http_module_t ngx_http_core_module_ctx;
|
extern ngx_http_module_t ngx_http_core_module_ctx;
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
static void ngx_http_init_request(ngx_event_t *ev);
|
static void ngx_http_init_request(ngx_event_t *ev);
|
||||||
#if (NGX_HTTP_SSL)
|
#if (NGX_HTTP_SSL)
|
||||||
static void ngx_http_check_ssl_handshake(ngx_event_t *rev);
|
static void ngx_http_ssl_handshake(ngx_event_t *rev);
|
||||||
#endif
|
#endif
|
||||||
static void ngx_http_process_request_line(ngx_event_t *rev);
|
static void ngx_http_process_request_line(ngx_event_t *rev);
|
||||||
static void ngx_http_process_request_headers(ngx_event_t *rev);
|
static void ngx_http_process_request_headers(ngx_event_t *rev);
|
||||||
@ -238,13 +238,12 @@ static void ngx_http_init_request(ngx_event_t *rev)
|
|||||||
|
|
||||||
rev->event_handler = ngx_http_process_request_line;
|
rev->event_handler = ngx_http_process_request_line;
|
||||||
|
|
||||||
r->recv = ngx_recv;
|
|
||||||
r->send_chain = ngx_send_chain;
|
|
||||||
|
|
||||||
#if (NGX_HTTP_SSL)
|
#if (NGX_HTTP_SSL)
|
||||||
|
|
||||||
sscf = ngx_http_get_module_srv_conf(r, ngx_http_ssl_module);
|
sscf = ngx_http_get_module_srv_conf(r, ngx_http_ssl_module);
|
||||||
if (sscf->enable) {
|
if (sscf->enable) {
|
||||||
|
|
||||||
|
if (c->ssl == NULL) {
|
||||||
if (ngx_ssl_create_session(sscf->ssl_ctx, c, NGX_SSL_BUFFER)
|
if (ngx_ssl_create_session(sscf->ssl_ctx, c, NGX_SSL_BUFFER)
|
||||||
== NGX_ERROR)
|
== NGX_ERROR)
|
||||||
{
|
{
|
||||||
@ -252,8 +251,19 @@ static void ngx_http_init_request(ngx_event_t *rev)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The majority of browsers do not send the "close notify" alert.
|
||||||
|
* Among them are MSIE, Mozilla, Netscape 4, Konqueror, and Links.
|
||||||
|
* And what is more MSIE ignores the server's alert.
|
||||||
|
*
|
||||||
|
* Opera always sends the alert.
|
||||||
|
*/
|
||||||
|
|
||||||
|
c->ssl->no_rcv_shut = 1;
|
||||||
|
rev->event_handler = ngx_http_ssl_handshake;
|
||||||
|
}
|
||||||
|
|
||||||
r->filter_need_in_memory = 1;
|
r->filter_need_in_memory = 1;
|
||||||
rev->event_handler = ngx_http_check_ssl_handshake;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -339,9 +349,10 @@ static void ngx_http_init_request(ngx_event_t *rev)
|
|||||||
|
|
||||||
#if (NGX_HTTP_SSL)
|
#if (NGX_HTTP_SSL)
|
||||||
|
|
||||||
static void ngx_http_check_ssl_handshake(ngx_event_t *rev)
|
static void ngx_http_ssl_handshake(ngx_event_t *rev)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
ngx_int_t rc;
|
||||||
u_char buf[1];
|
u_char buf[1];
|
||||||
ngx_connection_t *c;
|
ngx_connection_t *c;
|
||||||
ngx_http_request_t *r;
|
ngx_http_request_t *r;
|
||||||
@ -368,8 +379,20 @@ static void ngx_http_check_ssl_handshake(ngx_event_t *rev)
|
|||||||
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, rev->log, 0,
|
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, rev->log, 0,
|
||||||
"https ssl handshake: 0x%X", buf[0]);
|
"https ssl handshake: 0x%X", buf[0]);
|
||||||
|
|
||||||
r->recv = ngx_ssl_recv;
|
c->recv = ngx_ssl_recv;
|
||||||
r->send_chain = ngx_ssl_send_chain;
|
c->send_chain = ngx_ssl_send_chain;
|
||||||
|
|
||||||
|
rc = ngx_ssl_handshake(c);
|
||||||
|
|
||||||
|
if (rc == NGX_ERROR) {
|
||||||
|
ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST);
|
||||||
|
ngx_http_close_connection(r->connection);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rc != NGX_OK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0,
|
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0,
|
||||||
@ -892,7 +915,7 @@ static ssize_t ngx_http_read_request_header(ngx_http_request_t *r)
|
|||||||
return NGX_AGAIN;
|
return NGX_AGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = r->recv(r->connection, r->header_in->last,
|
n = r->connection->recv(r->connection, r->header_in->last,
|
||||||
r->header_in->end - r->header_in->last);
|
r->header_in->end - r->header_in->last);
|
||||||
|
|
||||||
if (n == NGX_AGAIN) {
|
if (n == NGX_AGAIN) {
|
||||||
@ -963,7 +986,10 @@ static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r)
|
|||||||
|
|
||||||
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
||||||
r->connection->log->file = clcf->err_log->file;
|
r->connection->log->file = clcf->err_log->file;
|
||||||
|
if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION))
|
||||||
|
{
|
||||||
r->connection->log->log_level = clcf->err_log->log_level;
|
r->connection->log->log_level = clcf->err_log->log_level;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1040,6 +1066,12 @@ static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r)
|
|||||||
if (ua[4] == ' ' && ua[5] == '4' && ua[6] == '.') {
|
if (ua[4] == ' ' && ua[5] == '4' && ua[6] == '.') {
|
||||||
r->headers_in.msie4 = 1;
|
r->headers_in.msie4 = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* MSIE ignores the SSL "close notify" alert */
|
||||||
|
|
||||||
|
ngx_ssl_set_nosendshut(r->connection->ssl);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1355,7 +1387,8 @@ static ngx_int_t ngx_http_read_discarded_body(ngx_http_request_t *r)
|
|||||||
size = (ssize_t) clcf->discarded_buffer_size;
|
size = (ssize_t) clcf->discarded_buffer_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = ngx_recv(r->connection, r->discarded_buffer, size);
|
n = r->connection->recv(r->connection, r->discarded_buffer, size);
|
||||||
|
|
||||||
if (n == NGX_ERROR) {
|
if (n == NGX_ERROR) {
|
||||||
|
|
||||||
r->closed = 1;
|
r->closed = 1;
|
||||||
@ -1502,7 +1535,8 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev)
|
|||||||
|
|
||||||
c->log_error = NGX_ERROR_IGNORE_ECONNRESET;
|
c->log_error = NGX_ERROR_IGNORE_ECONNRESET;
|
||||||
ngx_set_socket_errno(0);
|
ngx_set_socket_errno(0);
|
||||||
n = ngx_recv(c, c->buffer->last, c->buffer->end - c->buffer->last);
|
|
||||||
|
n = c->recv(c, c->buffer->last, c->buffer->end - c->buffer->last);
|
||||||
c->log_error = NGX_ERROR_INFO;
|
c->log_error = NGX_ERROR_INFO;
|
||||||
|
|
||||||
if (n == NGX_AGAIN) {
|
if (n == NGX_AGAIN) {
|
||||||
@ -1640,7 +1674,7 @@ static void ngx_http_lingering_close_handler(ngx_event_t *rev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
n = ngx_recv(c, r->discarded_buffer, clcf->discarded_buffer_size);
|
n = c->recv(c, r->discarded_buffer, clcf->discarded_buffer_size);
|
||||||
|
|
||||||
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "lingering read: %d", n);
|
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "lingering read: %d", n);
|
||||||
|
|
||||||
|
@ -218,9 +218,6 @@ struct ngx_http_request_s {
|
|||||||
|
|
||||||
ngx_connection_t *connection;
|
ngx_connection_t *connection;
|
||||||
|
|
||||||
ngx_recv_pt recv;
|
|
||||||
ngx_send_chain_pt send_chain;
|
|
||||||
|
|
||||||
void **ctx;
|
void **ctx;
|
||||||
void **main_conf;
|
void **main_conf;
|
||||||
void **srv_conf;
|
void **srv_conf;
|
||||||
|
@ -140,7 +140,7 @@ static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r)
|
|||||||
size = r->request_body->rest;
|
size = r->request_body->rest;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = ngx_recv(c, r->request_body->buf->last, size);
|
n = c->recv(c, r->request_body->buf->last, size);
|
||||||
|
|
||||||
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
||||||
"http client request body recv " SIZE_T_FMT, n);
|
"http client request body recv " SIZE_T_FMT, n);
|
||||||
|
@ -104,9 +104,11 @@ static char error_416_page[] =
|
|||||||
|
|
||||||
static char error_497_page[] =
|
static char error_497_page[] =
|
||||||
"<html>" CRLF
|
"<html>" CRLF
|
||||||
"<head><title>The plain HTTP request was sent to HTTPS port</title></head>" CRLF
|
"<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>"
|
||||||
|
CRLF
|
||||||
"<body bgcolor=\"white\">" CRLF
|
"<body bgcolor=\"white\">" CRLF
|
||||||
"<center><h1>The plain HTTP request was sent to HTTPS por</h1></center>" CRLF
|
"<center><h1>400 Bad Request</h1></center>" CRLF
|
||||||
|
"<center>The plain HTTP request was sent to HTTPS port</center>" CRLF
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
@ -174,7 +176,7 @@ static ngx_str_t error_pages[] = {
|
|||||||
ngx_null_string, /* 415 */
|
ngx_null_string, /* 415 */
|
||||||
ngx_string(error_416_page),
|
ngx_string(error_416_page),
|
||||||
|
|
||||||
ngx_string(error_400_page), /* 497, http to https */
|
ngx_string(error_497_page), /* 497, http to https */
|
||||||
ngx_string(error_404_page), /* 498, invalid host name */
|
ngx_string(error_404_page), /* 498, invalid host name */
|
||||||
ngx_null_string, /* 499, client closed connection */
|
ngx_null_string, /* 499, client closed connection */
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|||||||
int last;
|
int last;
|
||||||
off_t size, flush, sent;
|
off_t size, flush, sent;
|
||||||
ngx_chain_t *cl, *ln, **ll, *chain;
|
ngx_chain_t *cl, *ln, **ll, *chain;
|
||||||
|
ngx_connection_t *c;
|
||||||
ngx_http_core_loc_conf_t *clcf;
|
ngx_http_core_loc_conf_t *clcf;
|
||||||
ngx_http_write_filter_ctx_t *ctx;
|
ngx_http_write_filter_ctx_t *ctx;
|
||||||
|
|
||||||
@ -95,7 +96,9 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
c = r->connection;
|
||||||
|
|
||||||
|
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
||||||
"http write filter: l:%d f:" OFF_T_FMT " s:" OFF_T_FMT,
|
"http write filter: l:%d f:" OFF_T_FMT " s:" OFF_T_FMT,
|
||||||
last, flush, size);
|
last, flush, size);
|
||||||
|
|
||||||
@ -112,7 +115,7 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r->connection->write->delayed) {
|
if (c->write->delayed) {
|
||||||
return NGX_AGAIN;
|
return NGX_AGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,17 +127,17 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
sent = r->connection->sent;
|
sent = c->sent;
|
||||||
|
|
||||||
chain = r->send_chain(r->connection, ctx->out,
|
chain = c->send_chain(c, ctx->out,
|
||||||
clcf->limit_rate ? clcf->limit_rate: OFF_T_MAX_VALUE);
|
clcf->limit_rate ? clcf->limit_rate: OFF_T_MAX_VALUE);
|
||||||
|
|
||||||
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
||||||
"http write filter %X", chain);
|
"http write filter %X", chain);
|
||||||
|
|
||||||
if (clcf->limit_rate) {
|
if (clcf->limit_rate) {
|
||||||
sent = r->connection->sent - sent;
|
sent = c->sent - sent;
|
||||||
r->connection->write->delayed = 1;
|
c->write->delayed = 1;
|
||||||
ngx_add_timer(r->connection->write,
|
ngx_add_timer(r->connection->write,
|
||||||
(ngx_msec_t) (sent * 1000 / clcf->limit_rate));
|
(ngx_msec_t) (sent * 1000 / clcf->limit_rate));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user