mirror of
https://github.com/nginx/nginx.git
synced 2025-06-13 06:12:44 +08:00
nginx-0.0.1-2003-10-08-19:32:54 import
This commit is contained in:
parent
fd3e374a02
commit
3ae32483cd
@ -859,6 +859,60 @@ char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *ngx_conf_set_bufs_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||||
|
{
|
||||||
|
char *p = conf;
|
||||||
|
|
||||||
|
int len, scale;
|
||||||
|
char last;
|
||||||
|
ngx_str_t *value;
|
||||||
|
ngx_bufs_t *bufs;
|
||||||
|
|
||||||
|
|
||||||
|
bufs = (ngx_bufs_t *) (p + cmd->offset);
|
||||||
|
|
||||||
|
if (bufs->num) {
|
||||||
|
return "is duplicate";
|
||||||
|
}
|
||||||
|
|
||||||
|
value = (ngx_str_t *) cf->args->elts;
|
||||||
|
|
||||||
|
bufs->num = ngx_atoi(value[1].data, value[1].len);
|
||||||
|
if (bufs->num == NGX_ERROR || bufs->num == 0) {
|
||||||
|
return "invalid value";
|
||||||
|
}
|
||||||
|
|
||||||
|
len = value[2].len;
|
||||||
|
last = value[2].data[len - 1];
|
||||||
|
|
||||||
|
switch (last) {
|
||||||
|
case 'K':
|
||||||
|
case 'k':
|
||||||
|
len--;
|
||||||
|
scale = 1024;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'M':
|
||||||
|
case 'm':
|
||||||
|
len--;
|
||||||
|
scale = 1024 * 1024;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
scale = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bufs->size = ngx_atoi(value[2].data, len);
|
||||||
|
if (bufs->size == NGX_ERROR || bufs->size == 0) {
|
||||||
|
return "invalid value";
|
||||||
|
}
|
||||||
|
|
||||||
|
bufs->size *= scale;
|
||||||
|
|
||||||
|
return NGX_CONF_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
char *ngx_conf_unsupported(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
char *ngx_conf_unsupported(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||||
{
|
{
|
||||||
return "unsupported on this platform";
|
return "unsupported on this platform";
|
||||||
|
@ -175,6 +175,17 @@ struct ngx_conf_s {
|
|||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ngx_conf_merge_bufs_value(conf, prev, default_num, default_size) \
|
||||||
|
if (conf.num == 0) { \
|
||||||
|
if (prev.num) { \
|
||||||
|
conf.num = prev.num; \
|
||||||
|
conf.size = prev.size; \
|
||||||
|
} else { \
|
||||||
|
conf.num = default_num; \
|
||||||
|
conf.size = default_size; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define addressof(addr) ((int) &addr)
|
#define addressof(addr) ((int) &addr)
|
||||||
|
|
||||||
@ -193,6 +204,7 @@ char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
|||||||
char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||||
char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||||
char *ngx_conf_set_time_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
char *ngx_conf_set_time_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||||
|
char *ngx_conf_set_bufs_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||||
|
|
||||||
char *ngx_conf_set_core_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
char *ngx_conf_set_core_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
void *conf);
|
void *conf);
|
||||||
|
@ -64,6 +64,12 @@ struct ngx_chain_s {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int num;
|
||||||
|
ssize_t size;
|
||||||
|
} ngx_bufs_t;
|
||||||
|
|
||||||
|
|
||||||
#define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR
|
#define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,10 +7,9 @@
|
|||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int enable;
|
int enable;
|
||||||
int hunk_size;
|
ngx_bufs_t bufs;
|
||||||
int hunks;
|
int no_buffer;
|
||||||
int no_buffer;
|
|
||||||
} ngx_http_gzip_conf_t;
|
} ngx_http_gzip_conf_t;
|
||||||
|
|
||||||
|
|
||||||
@ -51,18 +50,11 @@ static ngx_command_t ngx_http_gzip_filter_commands[] = {
|
|||||||
offsetof(ngx_http_gzip_conf_t, enable),
|
offsetof(ngx_http_gzip_conf_t, enable),
|
||||||
NULL},
|
NULL},
|
||||||
|
|
||||||
{ngx_string("gzip_hunk_size"),
|
{ngx_string("gzip_buffers"),
|
||||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
|
||||||
ngx_conf_set_size_slot,
|
ngx_conf_set_bufs_slot,
|
||||||
NGX_HTTP_LOC_CONF_OFFSET,
|
NGX_HTTP_LOC_CONF_OFFSET,
|
||||||
offsetof(ngx_http_gzip_conf_t, hunk_size),
|
offsetof(ngx_http_gzip_conf_t, bufs),
|
||||||
NULL},
|
|
||||||
|
|
||||||
{ngx_string("gzip_hunks"),
|
|
||||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
||||||
ngx_conf_set_num_slot,
|
|
||||||
NGX_HTTP_LOC_CONF_OFFSET,
|
|
||||||
offsetof(ngx_http_gzip_conf_t, hunks),
|
|
||||||
NULL},
|
NULL},
|
||||||
|
|
||||||
{ngx_string("gzip_no_buffer"),
|
{ngx_string("gzip_no_buffer"),
|
||||||
@ -173,7 +165,7 @@ static int ngx_http_gzip_header_filter(ngx_http_request_t *r)
|
|||||||
|
|
||||||
static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||||
{
|
{
|
||||||
int rc, wbits, mem_level, zin, zout;
|
int rc, wbits, mem_level, zin, zout, last;
|
||||||
struct gztrailer *trailer;
|
struct gztrailer *trailer;
|
||||||
ngx_hunk_t *h;
|
ngx_hunk_t *h;
|
||||||
ngx_chain_t *ce;
|
ngx_chain_t *ce;
|
||||||
@ -240,6 +232,8 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
last = NGX_NONE;
|
||||||
|
|
||||||
for ( ;; ) {
|
for ( ;; ) {
|
||||||
|
|
||||||
for ( ;; ) {
|
for ( ;; ) {
|
||||||
@ -285,11 +279,12 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|||||||
ctx->out_hunk = ctx->free->hunk;
|
ctx->out_hunk = ctx->free->hunk;
|
||||||
ctx->free = ctx->free->next;
|
ctx->free = ctx->free->next;
|
||||||
|
|
||||||
} else if (ctx->hunks < conf->hunks) {
|
} else if (ctx->hunks < conf->bufs.num) {
|
||||||
ngx_test_null(ctx->out_hunk,
|
ngx_test_null(ctx->out_hunk,
|
||||||
ngx_create_temp_hunk(r->pool, conf->hunk_size,
|
ngx_create_temp_hunk(r->pool, conf->bufs.size,
|
||||||
0, 0),
|
0, 0),
|
||||||
ngx_http_gzip_error(ctx));
|
ngx_http_gzip_error(ctx));
|
||||||
|
ctx->out_hunk->type |= NGX_HUNK_RECYCLED;
|
||||||
ctx->hunks++;
|
ctx->hunks++;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -297,7 +292,7 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx->zstream.next_out = (unsigned char *) ctx->out_hunk->pos;
|
ctx->zstream.next_out = (unsigned char *) ctx->out_hunk->pos;
|
||||||
ctx->zstream.avail_out = conf->hunk_size;
|
ctx->zstream.avail_out = conf->bufs.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngx_log_debug(r->connection->log, "deflate(): %08x %08x %d %d %d" _
|
ngx_log_debug(r->connection->log, "deflate(): %08x %08x %d %d %d" _
|
||||||
@ -318,7 +313,7 @@ ngx_log_debug(r->connection->log, "DEFLATE(): %08x %08x %d %d %d" _
|
|||||||
ctx->in_hunk->pos = (char *) ctx->zstream.next_in;
|
ctx->in_hunk->pos = (char *) ctx->zstream.next_in;
|
||||||
|
|
||||||
if (ctx->zstream.avail_out == 0) {
|
if (ctx->zstream.avail_out == 0) {
|
||||||
ctx->out_hunk->last += conf->hunk_size;
|
ctx->out_hunk->last += conf->bufs.size;
|
||||||
ngx_add_hunk_to_chain(ce, ctx->out_hunk, r->pool,
|
ngx_add_hunk_to_chain(ce, ctx->out_hunk, r->pool,
|
||||||
ngx_http_gzip_error(ctx));
|
ngx_http_gzip_error(ctx));
|
||||||
*ctx->last_out = ce;
|
*ctx->last_out = ce;
|
||||||
@ -409,15 +404,13 @@ ngx_log_debug(r->connection->log, "DEFLATE(): %08x %08x %d %d %d" _
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->out == NULL) {
|
if (ctx->out == NULL && last != NGX_NONE) {
|
||||||
if (ctx->in || ctx->zstream.avail_in) {
|
return last;
|
||||||
return NGX_AGAIN;
|
|
||||||
} else {
|
|
||||||
return NGX_OK;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (next_body_filter(r, ctx->out) == NGX_ERROR) {
|
last = next_body_filter(r, ctx->out);
|
||||||
|
|
||||||
|
if (last == NGX_ERROR) {
|
||||||
return ngx_http_gzip_error(ctx);
|
return ngx_http_gzip_error(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,8 +456,7 @@ static void *ngx_http_gzip_create_conf(ngx_conf_t *cf)
|
|||||||
NGX_CONF_ERROR);
|
NGX_CONF_ERROR);
|
||||||
|
|
||||||
conf->enable = NGX_CONF_UNSET;
|
conf->enable = NGX_CONF_UNSET;
|
||||||
conf->hunk_size = NGX_CONF_UNSET;
|
/* conf->bufs.num = 0; */
|
||||||
conf->hunks = NGX_CONF_UNSET;
|
|
||||||
conf->no_buffer = NGX_CONF_UNSET;
|
conf->no_buffer = NGX_CONF_UNSET;
|
||||||
|
|
||||||
return conf;
|
return conf;
|
||||||
@ -478,9 +470,8 @@ static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf,
|
|||||||
ngx_http_gzip_conf_t *conf = child;
|
ngx_http_gzip_conf_t *conf = child;
|
||||||
|
|
||||||
ngx_conf_merge_value(conf->enable, prev->enable, 0);
|
ngx_conf_merge_value(conf->enable, prev->enable, 0);
|
||||||
ngx_conf_merge_size_value(conf->hunk_size, prev->hunk_size,
|
ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 4,
|
||||||
/* STUB: PAGE_SIZE */ 4096);
|
/* STUB: PAGE_SIZE */ 4096);
|
||||||
ngx_conf_merge_value(conf->hunks, prev->hunks, 4);
|
|
||||||
ngx_conf_merge_value(conf->no_buffer, prev->no_buffer, 0);
|
ngx_conf_merge_value(conf->no_buffer, prev->no_buffer, 0);
|
||||||
|
|
||||||
return NGX_CONF_OK;
|
return NGX_CONF_OK;
|
||||||
|
@ -101,8 +101,12 @@ static char conn_close_header[] = "Connection: close" CRLF;
|
|||||||
|
|
||||||
static int ngx_http_proxy_translate_handler(ngx_http_request_t *r)
|
static int ngx_http_proxy_translate_handler(ngx_http_request_t *r)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
r->handler = ngx_http_proxy_handler;
|
r->handler = ngx_http_proxy_handler;
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
|
#else
|
||||||
|
return NGX_DECLINED;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,15 +5,26 @@
|
|||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ssize_t hunk_size;
|
ngx_bufs_t bufs;
|
||||||
} ngx_http_output_filter_conf_t;
|
} ngx_http_output_filter_conf_t;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ngx_hunk_t *hunk; /* the temporary hunk to copy */
|
|
||||||
ngx_chain_t *incoming;
|
/*
|
||||||
ngx_chain_t in; /* one chain entry for input */
|
* NOTE: we do not need now to store hunk in ctx,
|
||||||
ngx_chain_t out; /* one chain entry for output */
|
* it's needed for the future NGX_FILE_AIO_READ support only
|
||||||
|
*/
|
||||||
|
|
||||||
|
ngx_hunk_t *hunk;
|
||||||
|
|
||||||
|
ngx_chain_t *in;
|
||||||
|
ngx_chain_t *out;
|
||||||
|
ngx_chain_t **last_out;
|
||||||
|
ngx_chain_t *free;
|
||||||
|
ngx_chain_t *busy;
|
||||||
|
|
||||||
|
int hunks;
|
||||||
} ngx_http_output_filter_ctx_t;
|
} ngx_http_output_filter_ctx_t;
|
||||||
|
|
||||||
|
|
||||||
@ -25,11 +36,11 @@ static char *ngx_http_output_filter_merge_conf(ngx_conf_t *cf,
|
|||||||
|
|
||||||
static ngx_command_t ngx_http_output_filter_commands[] = {
|
static ngx_command_t ngx_http_output_filter_commands[] = {
|
||||||
|
|
||||||
{ngx_string("output_buffer"),
|
{ngx_string("output_buffers"),
|
||||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
|
||||||
ngx_conf_set_size_slot,
|
ngx_conf_set_bufs_slot,
|
||||||
NGX_HTTP_LOC_CONF_OFFSET,
|
NGX_HTTP_LOC_CONF_OFFSET,
|
||||||
offsetof(ngx_http_output_filter_conf_t, hunk_size),
|
offsetof(ngx_http_output_filter_conf_t, bufs),
|
||||||
NULL},
|
NULL},
|
||||||
|
|
||||||
ngx_null_command
|
ngx_null_command
|
||||||
@ -58,7 +69,7 @@ ngx_module_t ngx_http_output_filter_module = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define next_filter (*ngx_http_top_body_filter)
|
#define ngx_next_filter (*ngx_http_top_body_filter)
|
||||||
|
|
||||||
#define need_to_copy(r, hunk) \
|
#define need_to_copy(r, hunk) \
|
||||||
(((r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY) \
|
(((r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY) \
|
||||||
@ -67,11 +78,12 @@ ngx_module_t ngx_http_output_filter_module = {
|
|||||||
&& (hunk->type & (NGX_HUNK_MEMORY|NGX_HUNK_MMAP))))
|
&& (hunk->type & (NGX_HUNK_MEMORY|NGX_HUNK_MMAP))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
|
int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc, last;
|
||||||
ssize_t size;
|
ssize_t size;
|
||||||
ngx_chain_t *ce, *le;
|
ngx_chain_t out, *ce, **le;
|
||||||
ngx_http_output_filter_ctx_t *ctx;
|
ngx_http_output_filter_ctx_t *ctx;
|
||||||
ngx_http_output_filter_conf_t *conf;
|
ngx_http_output_filter_conf_t *conf;
|
||||||
|
|
||||||
@ -81,120 +93,86 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
|
|||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
ngx_http_create_ctx(r, ctx, ngx_http_output_filter_module,
|
ngx_http_create_ctx(r, ctx, ngx_http_output_filter_module,
|
||||||
sizeof(ngx_http_output_filter_ctx_t), NGX_ERROR);
|
sizeof(ngx_http_output_filter_ctx_t), NGX_ERROR);
|
||||||
|
ctx->last_out = &ctx->out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the short path for the case when the chain ctx->incoming is empty
|
/*
|
||||||
and there is no hunk or the hunk does not require the copy */
|
* the short path for the case when the chain ctx->in is empty
|
||||||
if (ctx->incoming == NULL) {
|
* and there's no hunk or the hunk does not require the copy
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (ctx->in == NULL) {
|
||||||
|
|
||||||
if (hunk == NULL) {
|
if (hunk == NULL) {
|
||||||
return next_filter(r, NULL);
|
return ngx_next_filter(r, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we do not need to copy the incoming hunk to our hunk */
|
|
||||||
if (!need_to_copy(r, hunk)) {
|
if (!need_to_copy(r, hunk)) {
|
||||||
ctx->out.hunk = hunk;
|
out.hunk = hunk;
|
||||||
ctx->out.next = NULL;
|
out.next = NULL;
|
||||||
return next_filter(r, &ctx->out);
|
return ngx_next_filter(r, &out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add the incoming hunk to the chain ctx->incoming */
|
/* add the incoming hunk to the chain ctx->in */
|
||||||
|
|
||||||
if (hunk) {
|
if (hunk) {
|
||||||
|
le = &ctx->in;
|
||||||
|
|
||||||
/* the output of the only hunk is common case so we have
|
for (ce = ctx->in; ce; ce = ce->next) {
|
||||||
the special chain entry ctx->in for it */
|
le = &ce->next;
|
||||||
if (ctx->incoming == NULL) {
|
|
||||||
ctx->in.hunk = hunk;
|
|
||||||
ctx->in.next = NULL;
|
|
||||||
ctx->incoming = &ctx->in;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
for (ce = ctx->incoming; ce->next; ce = ce->next) { /* void */ ; }
|
|
||||||
ngx_add_hunk_to_chain(ce->next, hunk, r->pool, NGX_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngx_add_hunk_to_chain(ce, hunk, r->pool, NGX_ERROR);
|
||||||
|
*le = ce;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate our hunk if it's needed */
|
conf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
|
||||||
if (ctx->hunk == NULL) {
|
ngx_http_output_filter_module);
|
||||||
|
|
||||||
conf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
|
last = NGX_NONE;
|
||||||
ngx_http_output_filter_module);
|
|
||||||
|
|
||||||
if (hunk->type & NGX_HUNK_LAST) {
|
for ( ;; ) {
|
||||||
if (hunk->type & NGX_HUNK_IN_MEMORY) {
|
|
||||||
size = hunk->last - hunk->pos;
|
while (ctx->in) {
|
||||||
} else {
|
|
||||||
size = (size_t) (hunk->file_last - hunk->file_pos);
|
if (!need_to_copy(r, ctx->in->hunk)) {
|
||||||
|
|
||||||
|
/* move the chain entry to the chain ctx->out */
|
||||||
|
|
||||||
|
ce = ctx->in;
|
||||||
|
ctx->in = ce->next;
|
||||||
|
|
||||||
|
*ctx->last_out = ce;
|
||||||
|
ctx->last_out = &ce->next;
|
||||||
|
ce->next = NULL;
|
||||||
|
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size > conf->hunk_size) {
|
if (ctx->hunk == NULL) {
|
||||||
size = conf->hunk_size;
|
|
||||||
|
/* get the free hunk */
|
||||||
|
|
||||||
|
if (ctx->free) {
|
||||||
|
ctx->hunk = ctx->free->hunk;
|
||||||
|
ctx->free = ctx->free->next;
|
||||||
|
|
||||||
|
} else if (ctx->hunks < conf->bufs.num) {
|
||||||
|
ngx_test_null(ctx->hunk,
|
||||||
|
ngx_create_temp_hunk(r->pool, conf->bufs.size,
|
||||||
|
0, 0),
|
||||||
|
NGX_ERROR);
|
||||||
|
ctx->hunk->type |= NGX_HUNK_RECYCLED;
|
||||||
|
ctx->hunks++;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
rc = ngx_http_output_filter_copy_hunk(ctx->hunk, ctx->in->hunk);
|
||||||
size = conf->hunk_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngx_test_null(ctx->hunk,
|
|
||||||
ngx_create_temp_hunk(r->pool, size, 50, 50),
|
|
||||||
NGX_ERROR);
|
|
||||||
ctx->hunk->type |= NGX_HUNK_RECYCLED;
|
|
||||||
|
|
||||||
|
|
||||||
/* our hunk is still busy */
|
|
||||||
} else if (ctx->hunk->pos < ctx->hunk->last) {
|
|
||||||
rc = next_filter(r, NULL);
|
|
||||||
|
|
||||||
if (rc == NGX_ERROR || rc == NGX_AGAIN) {
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* NGX_OK */
|
|
||||||
#if 1
|
|
||||||
/* set our hunk free */
|
|
||||||
ctx->hunk->pos = ctx->hunk->last = ctx->hunk->start;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (NGX_SUPPRESS_WARN)
|
|
||||||
le = NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* process the chain ctx->incoming */
|
|
||||||
do {
|
|
||||||
/* find the hunks that do not need to be copied ... */
|
|
||||||
for (ce = ctx->incoming; ce; ce = ce->next) {
|
|
||||||
if (need_to_copy(r, ce->hunk)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
le = ce;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ... and pass them to the next filter */
|
|
||||||
if (ctx->incoming != ce) {
|
|
||||||
|
|
||||||
ctx->out.hunk = ctx->incoming->hunk;
|
|
||||||
ctx->out.next = ctx->incoming->next;
|
|
||||||
ctx->incoming = ce;
|
|
||||||
le->next = NULL;
|
|
||||||
|
|
||||||
rc = next_filter(r, &ctx->out);
|
|
||||||
if (rc == NGX_ERROR || rc == NGX_AGAIN) {
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* NGX_OK */
|
|
||||||
if (ctx->incoming == NULL) {
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* copy the first hunk or its part from the chain ctx->incoming
|
|
||||||
to our hunk and pass it to the next filter */
|
|
||||||
do {
|
|
||||||
rc = ngx_http_output_filter_copy_hunk(ctx->hunk,
|
|
||||||
ctx->incoming->hunk);
|
|
||||||
if (rc == NGX_ERROR) {
|
if (rc == NGX_ERROR) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -205,42 +183,35 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ctx->incoming->hunk->type & NGX_HUNK_IN_MEMORY) {
|
if (ctx->in->hunk->type & NGX_HUNK_IN_MEMORY) {
|
||||||
size = ctx->incoming->hunk->last - ctx->incoming->hunk->pos;
|
size = ctx->in->hunk->last - ctx->in->hunk->pos;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
size = (size_t) (ctx->incoming->hunk->file_last
|
size = (size_t) (ctx->in->hunk->file_last
|
||||||
- ctx->incoming->hunk->file_pos);
|
- ctx->in->hunk->file_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* delete the completed hunk from the incoming chain */
|
/* delete the completed hunk from the chain ctx->in */
|
||||||
|
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
ctx->incoming = ctx->incoming->next;
|
ctx->in = ctx->in->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->out.hunk = ctx->hunk;
|
ngx_add_hunk_to_chain(ce, ctx->hunk, r->pool, NGX_ERROR);
|
||||||
ctx->out.next = NULL;
|
*ctx->last_out = ce;
|
||||||
|
ctx->last_out = &ce->next;
|
||||||
|
ctx->hunk = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
rc = next_filter(r, &ctx->out);
|
if (ctx->out == NULL && last != NGX_NONE) {
|
||||||
if (rc == NGX_ERROR || rc == NGX_AGAIN) {
|
return last;
|
||||||
return rc;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* NGX_OK */
|
last = ngx_next_filter(r, ctx->out);
|
||||||
#if 1
|
|
||||||
/* set our hunk free */
|
|
||||||
ctx->hunk->pos = ctx->hunk->last = ctx->hunk->start;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* repeat until we will have copied the whole first hunk from
|
ngx_chain_update_chains(&ctx->free, &ctx->busy, &ctx->out);
|
||||||
the chain ctx->incoming */
|
ctx->last_out = &ctx->out;
|
||||||
|
}
|
||||||
} while (size);
|
|
||||||
|
|
||||||
/* repeat until we will have processed the whole chain ctx->incoming */
|
|
||||||
} while (ctx->incoming);
|
|
||||||
|
|
||||||
return NGX_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -319,7 +290,7 @@ static void *ngx_http_output_filter_create_conf(ngx_conf_t *cf)
|
|||||||
ngx_palloc(cf->pool, sizeof(ngx_http_output_filter_conf_t)),
|
ngx_palloc(cf->pool, sizeof(ngx_http_output_filter_conf_t)),
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
conf->hunk_size = NGX_CONF_UNSET;
|
conf->bufs.num = 0;
|
||||||
|
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
@ -331,7 +302,7 @@ static char *ngx_http_output_filter_merge_conf(ngx_conf_t *cf,
|
|||||||
ngx_http_output_filter_conf_t *prev = parent;
|
ngx_http_output_filter_conf_t *prev = parent;
|
||||||
ngx_http_output_filter_conf_t *conf = child;
|
ngx_http_output_filter_conf_t *conf = child;
|
||||||
|
|
||||||
ngx_conf_merge_size_value(conf->hunk_size, prev->hunk_size, 32768);
|
ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 2, 32768);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2,20 +2,6 @@
|
|||||||
#define _NGX_HTTP_REQUEST_H_INCLUDED_
|
#define _NGX_HTTP_REQUEST_H_INCLUDED_
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#include <ngx_config.h>
|
|
||||||
|
|
||||||
#include <ngx_types.h>
|
|
||||||
#include <ngx_string.h>
|
|
||||||
#include <ngx_table.h>
|
|
||||||
#include <ngx_hunk.h>
|
|
||||||
#include <ngx_files.h>
|
|
||||||
#include <ngx_connection.h>
|
|
||||||
#include <ngx_conf_file.h>
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#define NGX_HTTP_VERSION_9 9
|
#define NGX_HTTP_VERSION_9 9
|
||||||
#define NGX_HTTP_VERSION_10 1000
|
#define NGX_HTTP_VERSION_10 1000
|
||||||
#define NGX_HTTP_VERSION_11 1001
|
#define NGX_HTTP_VERSION_11 1001
|
||||||
@ -28,6 +14,9 @@
|
|||||||
#define NGX_HTTP_CONN_KEEP_ALIVE 1
|
#define NGX_HTTP_CONN_KEEP_ALIVE 1
|
||||||
|
|
||||||
|
|
||||||
|
#define NGX_NONE 1
|
||||||
|
|
||||||
|
|
||||||
#define NGX_HTTP_PARSE_HEADER_DONE 1
|
#define NGX_HTTP_PARSE_HEADER_DONE 1
|
||||||
#define NGX_HTTP_PARSE_INVALID_METHOD 10
|
#define NGX_HTTP_PARSE_INVALID_METHOD 10
|
||||||
#define NGX_HTTP_PARSE_INVALID_REQUEST 11
|
#define NGX_HTTP_PARSE_INVALID_REQUEST 11
|
||||||
|
Loading…
Reference in New Issue
Block a user