summaryrefslogtreecommitdiffhomepage
path: root/src/http
diff options
context:
space:
mode:
Diffstat (limited to 'src/http')
-rw-r--r--src/http/modules/ngx_http_ssl_filter.c48
-rw-r--r--src/http/modules/ngx_http_ssl_filter.h2
-rw-r--r--src/http/ngx_http_core_module.c19
-rw-r--r--src/http/ngx_http_core_module.h2
-rw-r--r--src/http/ngx_http_header_filter.c7
-rw-r--r--src/http/ngx_http_write_filter.c87
6 files changed, 83 insertions, 82 deletions
diff --git a/src/http/modules/ngx_http_ssl_filter.c b/src/http/modules/ngx_http_ssl_filter.c
index 742c29366..344577b64 100644
--- a/src/http/modules/ngx_http_ssl_filter.c
+++ b/src/http/modules/ngx_http_ssl_filter.c
@@ -22,12 +22,12 @@ typedef struct {
typedef struct {
SSL *ssl;
-
- unsigned accepted;
} ngx_http_ssl_ctx_t;
static ngx_http_ssl_ctx_t *ngx_http_ssl_create_ctx(ngx_http_request_t *r);
+static ngx_chain_t *ngx_http_ssl_write(ngx_http_request_t *r, ngx_chain_t *in,
+ off_t limit);
static void ngx_http_ssl_error(ngx_uint_t level, ngx_log_t *log, int err,
char *fmt, ...);
static void *ngx_http_ssl_create_srv_conf(ngx_conf_t *cf);
@@ -152,7 +152,7 @@ ngx_int_t ngx_http_ssl_read(ngx_http_request_t *r, u_char *buf, size_t n)
}
ngx_http_ssl_error(NGX_LOG_ALERT, r->connection->log, rc,
- "SSL_accept() failed");
+ "SSL_read() failed");
SSL_set_shutdown(ctx->ssl, SSL_RECEIVED_SHUTDOWN);
@@ -160,11 +160,8 @@ ngx_int_t ngx_http_ssl_read(ngx_http_request_t *r, u_char *buf, size_t n)
}
-ngx_int_t ngx_http_ssl_write(ngx_http_request_t *r, ngx_chain_t *in,
- off_t limit)
+ngx_int_t ngx_http_ssl_writer(ngx_http_request_t *r, ngx_chain_t *in)
{
- int rc;
- size_t send, size;
ngx_http_ssl_ctx_t *ctx;
ctx = ngx_http_get_module_ctx(r, ngx_http_ssl_filter_module);
@@ -175,7 +172,12 @@ ngx_int_t ngx_http_ssl_write(ngx_http_request_t *r, ngx_chain_t *in,
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"SSL_shutdown: %d", rc);
+ if (rc == 0) {
+ return NGX_AGAIN;
+ }
+
if (rc == 1) {
+ SSL_free(ctx->ssl);
return NGX_OK;
}
@@ -188,9 +190,28 @@ ngx_int_t ngx_http_ssl_write(ngx_http_request_t *r, ngx_chain_t *in,
return NGX_AGAIN;
}
+ ngx_http_ssl_error(NGX_LOG_ALERT, r->connection->log, rc,
+ "SSL_shutdown() failed");
+
return NGX_ERROR;
}
+ ch = ngx_http_ssl_write(r, ctx, in, 0);
+
+ return NGX_OK;
+}
+
+
+static ngx_chain_t *ngx_http_ssl_write(ngx_http_request_t *r,
+ ngx_http_ssl_ctx_t *ctx,
+ ngx_chain_t *in,
+ off_t limit)
+{
+ int rc;
+ size_t send, size;
+
+ ctx = ngx_http_get_module_ctx(r, ngx_http_ssl_filter_module);
+
send = 0;
for (/* void */; in; in = in->next) {
@@ -205,9 +226,20 @@ ngx_int_t ngx_http_ssl_write(ngx_http_request_t *r, ngx_chain_t *in,
}
rc = SSL_write(ctx->ssl, in->buf->pos, size);
+
+ if (rc > 0) {
+ in->buf->pos += rc;
+
+ if (rc == size) {
+ continue;
+ }
+
+ r->connection->write->ready = 0;
+ return in;
+ }
}
- return NGX_OK;
+ return in;
}
diff --git a/src/http/modules/ngx_http_ssl_filter.h b/src/http/modules/ngx_http_ssl_filter.h
index b94b36724..9bbe65a4f 100644
--- a/src/http/modules/ngx_http_ssl_filter.h
+++ b/src/http/modules/ngx_http_ssl_filter.h
@@ -14,6 +14,8 @@
ngx_int_t ngx_http_ssl_read(ngx_http_request_t *r, u_char *buf, size_t n);
+ngx_int_t ngx_http_ssl_writer(ngx_http_request_t *r, ngx_chain_t *in);
+
void ngx_http_ssl_close_connection(SSL *ssl, ngx_log_t *log);
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 2e967854c..001ed8900 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -206,6 +206,20 @@ static ngx_command_t ngx_http_core_commands[] = {
offsetof(ngx_http_core_loc_conf_t, send_lowat),
&ngx_http_lowat_post },
+ { ngx_string("postpone_output"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_size_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_core_loc_conf_t, postpone_output),
+ NULL },
+
+ { ngx_string("limit_rate"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_size_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_core_loc_conf_t, limit_rate),
+ NULL },
+
{ ngx_string("keepalive_timeout"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
@@ -1251,6 +1265,8 @@ static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf)
lcf->tcp_nopush = NGX_CONF_UNSET;
lcf->send_timeout = NGX_CONF_UNSET_MSEC;
lcf->send_lowat = NGX_CONF_UNSET_SIZE;
+ lcf->postpone_output = NGX_CONF_UNSET_SIZE;
+ lcf->limit_rate = NGX_CONF_UNSET_SIZE;
lcf->discarded_buffer_size = NGX_CONF_UNSET_SIZE;
lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
lcf->lingering_time = NGX_CONF_UNSET_MSEC;
@@ -1334,6 +1350,9 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
+ ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,
+ 1460);
+ ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0);
ngx_conf_merge_size_value(conf->discarded_buffer_size,
prev->discarded_buffer_size, 1500);
ngx_conf_merge_msec_value(conf->keepalive_timeout,
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
index 834cf582b..051486a22 100644
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -134,6 +134,8 @@ typedef struct {
size_t discarded_buffer_size; /* discarded_buffer_size */
size_t client_body_buffer_size; /* client_body_buffer_size */
size_t send_lowat; /* send_lowat */
+ size_t postpone_output; /* postpone_output */
+ size_t limit_rate; /* limit_rate */
ngx_msec_t client_body_timeout; /* client_body_timeout */
ngx_msec_t send_timeout; /* send_timeout */
diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c
index 738f1ebf5..f565d2fc8 100644
--- a/src/http/ngx_http_header_filter.c
+++ b/src/http/ngx_http_header_filter.c
@@ -33,6 +33,9 @@ ngx_module_t ngx_http_header_filter_module = {
};
+static ngx_http_output_body_filter_pt write_filter;
+
+
static char server_string[] = "Server: " NGINX_VER CRLF;
@@ -355,7 +358,7 @@ static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r)
ln->buf = b;
ln->next = NULL;
- return ngx_http_write_filter(r, ln);
+ return write_filter(r, ln);
}
@@ -363,5 +366,7 @@ static ngx_int_t ngx_http_header_filter_init(ngx_cycle_t *cycle)
{
ngx_http_top_header_filter = ngx_http_header_filter;
+ write_filter = ngx_http_top_body_filter;
+
return NGX_OK;
}
diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c
index 2d4ba23bb..2d4c1ef1c 100644
--- a/src/http/ngx_http_write_filter.c
+++ b/src/http/ngx_http_write_filter.c
@@ -6,42 +6,13 @@
typedef struct {
- size_t postpone_output; /* postpone_output */
- size_t limit_rate; /* limit_rate */
-} ngx_http_write_filter_conf_t;
-
-
-typedef struct {
ngx_chain_t *out;
} ngx_http_write_filter_ctx_t;
-static void *ngx_http_write_filter_create_conf(ngx_conf_t *cf);
-static char *ngx_http_write_filter_merge_conf(ngx_conf_t *cf,
- void *parent, void *child);
static ngx_int_t ngx_http_write_filter_init(ngx_cycle_t *cycle);
-static ngx_command_t ngx_http_write_filter_commands[] = {
-
- { ngx_string("postpone_output"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_size_slot,
- NGX_HTTP_LOC_CONF_OFFSET,
- offsetof(ngx_http_write_filter_conf_t, postpone_output),
- NULL },
-
- { ngx_string("limit_rate"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_size_slot,
- NGX_HTTP_LOC_CONF_OFFSET,
- offsetof(ngx_http_write_filter_conf_t, limit_rate),
- NULL },
-
- ngx_null_command
-};
-
-
ngx_http_module_t ngx_http_write_filter_module_ctx = {
NULL, /* pre conf */
@@ -51,15 +22,15 @@ ngx_http_module_t ngx_http_write_filter_module_ctx = {
NULL, /* create server configuration */
NULL, /* merge server configuration */
- ngx_http_write_filter_create_conf, /* create location configuration */
- ngx_http_write_filter_merge_conf /* merge location configuration */
+ NULL, /* create location configuration */
+ NULL, /* merge location configuration */
};
ngx_module_t ngx_http_write_filter_module = {
NGX_MODULE,
&ngx_http_write_filter_module_ctx, /* module context */
- ngx_http_write_filter_commands, /* module directives */
+ NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_write_filter_init, /* init module */
NULL /* init process */
@@ -68,11 +39,11 @@ ngx_module_t ngx_http_write_filter_module = {
ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
- int last;
- off_t size, flush, sent;
- ngx_chain_t *cl, *ln, **ll, *chain;
- ngx_http_write_filter_ctx_t *ctx;
- ngx_http_write_filter_conf_t *conf;
+ int last;
+ off_t size, flush, sent;
+ ngx_chain_t *cl, *ln, **ll, *chain;
+ ngx_http_core_loc_conf_t *clcf;
+ ngx_http_write_filter_ctx_t *ctx;
ctx = ngx_http_get_module_ctx(r->main ? r->main : r,
ngx_http_write_filter_module);
@@ -125,8 +96,8 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
"http write filter: l:%d f:" OFF_T_FMT " s:" OFF_T_FMT,
last, flush, size);
- conf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
- ngx_http_write_filter_module);
+ clcf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
+ ngx_http_core_module);
/*
* avoid the output if there is no last buf, no flush point,
@@ -134,7 +105,7 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
* is smaller than "postpone_output" directive
*/
- if (!last && flush == 0 && in && size < (off_t) conf->postpone_output) {
+ if (!last && flush == 0 && in && size < (off_t) clcf->postpone_output) {
return NGX_OK;
}
@@ -153,17 +124,17 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
sent = r->connection->sent;
chain = ngx_write_chain(r->connection, ctx->out,
- conf->limit_rate ? conf->limit_rate:
+ clcf->limit_rate ? clcf->limit_rate:
OFF_T_MAX_VALUE);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http write filter %X", chain);
- if (conf->limit_rate) {
+ if (clcf->limit_rate) {
sent = r->connection->sent - sent;
r->connection->write->delayed = 1;
ngx_add_timer(r->connection->write,
- (ngx_msec_t) sent * 1000 / conf->limit_rate);
+ (ngx_msec_t) (sent * 1000 / clcf->limit_rate));
}
if (chain == NGX_CHAIN_ERROR) {
@@ -180,36 +151,6 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
-static void *ngx_http_write_filter_create_conf(ngx_conf_t *cf)
-{
- ngx_http_write_filter_conf_t *conf;
-
- ngx_test_null(conf,
- ngx_palloc(cf->pool, sizeof(ngx_http_write_filter_conf_t)),
- NULL);
-
- conf->postpone_output = NGX_CONF_UNSET_SIZE;
- conf->limit_rate = NGX_CONF_UNSET_SIZE;
-
- return conf;
-}
-
-
-static char *ngx_http_write_filter_merge_conf(ngx_conf_t *cf,
- void *parent, void *child)
-{
- ngx_http_write_filter_conf_t *prev = parent;
- ngx_http_write_filter_conf_t *conf = child;
-
- ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,
- 1460);
-
- ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0);
-
- return NULL;
-}
-
-
static ngx_int_t ngx_http_write_filter_init(ngx_cycle_t *cycle)
{
ngx_http_top_body_filter = ngx_http_write_filter;