nginx-0.0.1-2003-10-24-10:53:41 import

This commit is contained in:
Igor Sysoev 2003-10-24 06:53:41 +00:00
parent 8556e6da41
commit 12b4b00784
8 changed files with 108 additions and 109 deletions

View File

@ -596,8 +596,9 @@ char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
int *np;
ngx_str_t *value;
int *np;
ngx_str_t *value;
ngx_conf_post_t *post;
np = (int *) (p + cmd->offset);
@ -612,8 +613,9 @@ char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return "invalid number";
}
if (cmd->bounds) {
return cmd->bounds->check(cf, cmd->bounds, np);
if (cmd->post) {
post = cmd->post;
return post->post_handler(cf, post, np);
}
return NGX_CONF_OK;
@ -624,8 +626,9 @@ char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
int *np;
ngx_str_t *value;
int *np;
ngx_str_t *value;
ngx_conf_post_t *post;
np = (int *) (p + cmd->offset);
@ -640,8 +643,9 @@ char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return "invalid value";
}
if (cmd->bounds) {
return cmd->bounds->check(cf, cmd->bounds, np);
if (cmd->post) {
post = cmd->post;
return post->post_handler(cf, post, np);
}
return NGX_CONF_OK;
@ -652,10 +656,9 @@ char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
int size, total, len, scale, *np;
u_int max, i;
char last, *start;
ngx_str_t *value;
int *np;
ngx_str_t *value;
ngx_conf_post_t *post;
np = (int *) (p + cmd->offset);
@ -674,8 +677,9 @@ char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return "value must be less than 597 hours";
}
if (cmd->bounds) {
return cmd->bounds->check(cf, cmd->bounds, np);
if (cmd->post) {
post = cmd->post;
return post->post_handler(cf, post, np);
}
return NGX_CONF_OK;
@ -686,10 +690,9 @@ char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
int size, total, len, scale, *np;
u_int max, i;
char last, *start;
ngx_str_t *value;
int *np;
ngx_str_t *value;
ngx_conf_post_t *post;
np = (int *) (p + cmd->offset);
@ -708,8 +711,9 @@ char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return "value must be less than 68 years";
}
if (cmd->bounds) {
return cmd->bounds->check(cf, cmd->bounds, np);
if (cmd->post) {
post = cmd->post;
return post->post_handler(cf, post, np);
}
return NGX_CONF_OK;
@ -751,14 +755,13 @@ char *ngx_conf_unsupported(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
char *ngx_conf_check_num_bounds(ngx_conf_t *cf, ngx_conf_bounds_t *bounds,
void *conf)
char *ngx_conf_check_num_bounds(ngx_conf_t *cf, void *post, void *data)
{
int *num = conf;
ngx_conf_num_bounds_t *bounds = post;
int *np = data;
if (*num >= bounds->type.num.low && *num <= bounds->type.num.high) {
if (*np >= bounds->low && (u_int) *np <= (u_int) bounds->high) {
return NGX_CONF_OK;
}
return "invalid value";

View File

@ -51,34 +51,13 @@
#define NGX_CONF_MODULE 0x464E4F43 /* "CONF" */
typedef struct ngx_conf_bounds_s ngx_conf_bounds_t;
struct ngx_conf_bounds_s {
char *(*check)(ngx_conf_t *cf, ngx_conf_bounds_t *bounds, void *conf);
union {
struct {
int low;
int high;
} num;
struct num {
int low_num;
int high_num;
int low_size;
int high_size;
} bufs;
} type;
};
struct ngx_command_s {
ngx_str_t name;
int type;
char *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
int conf;
int offset;
ngx_conf_bounds_t *bounds;
ngx_str_t name;
int type;
char *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
int conf;
int offset;
void *post;
};
#define ngx_null_command { ngx_null_string, 0, NULL, 0, 0, NULL }
@ -156,6 +135,24 @@ struct ngx_conf_s {
};
typedef char *(*ngx_conf_post_handler_pt) (ngx_conf_t *cf,
void *data, void *conf);
typedef struct {
ngx_conf_post_handler_pt post_handler;
} ngx_conf_post_t;
typedef struct {
ngx_conf_post_handler_pt post_handler;
int low;
int high;
} ngx_conf_num_bounds_t;
char *ngx_conf_check_num_bounds(ngx_conf_t *cf, void *post, void *data);
#define ngx_get_conf(conf_ctx, module) conf_ctx[module.index]
@ -240,9 +237,6 @@ 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,
void *conf);
char *ngx_conf_check_num_bounds(ngx_conf_t *cf, ngx_conf_bounds_t *bounds,
void *conf);
extern ngx_module_t *ngx_modules[];
extern ngx_cycle_t *ngx_cycle;

View File

@ -50,12 +50,19 @@ static int ngx_http_gzip_filter_init(ngx_cycle_t *cycle);
static void *ngx_http_gzip_create_conf(ngx_conf_t *cf);
static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf,
void *parent, void *child);
static char *ngx_http_gzip_set_window(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *ngx_http_gzip_set_hash(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *ngx_http_gzip_set_window(ngx_conf_t *cf, void *post, void *data);
static char *ngx_http_gzip_set_hash(ngx_conf_t *cf, void *post, void *data);
static ngx_conf_num_bounds_t ngx_http_gzip_comp_level_bounds = {
ngx_conf_check_num_bounds, 1, 9
};
static ngx_conf_post_handler_pt ngx_http_gzip_set_window_p =
ngx_http_gzip_set_window;
static ngx_conf_post_handler_pt ngx_http_gzip_set_hash_p =
ngx_http_gzip_set_hash;
static ngx_conf_bounds_t ngx_http_gzip_comp_level_bounds;
static ngx_command_t ngx_http_gzip_filter_commands[] = {
@ -83,17 +90,17 @@ static ngx_command_t ngx_http_gzip_filter_commands[] = {
{ngx_string("gzip_window"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_http_gzip_set_window,
ngx_conf_set_size_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_gzip_conf_t, wbits),
NULL},
&ngx_http_gzip_set_window_p},
{ngx_string("gzip_hash"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_http_gzip_set_hash,
ngx_conf_set_size_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_gzip_conf_t, memlevel),
NULL},
&ngx_http_gzip_set_hash_p},
{ngx_string("gzip_no_buffer"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
@ -128,12 +135,7 @@ ngx_module_t ngx_http_gzip_filter_module = {
};
static ngx_conf_bounds_t ngx_http_gzip_comp_level_bounds = {
ngx_conf_check_num_bounds, { { 1, 9 } }
};
static u_char gzheader[10] = { 0x1f, 0x8b, Z_DEFLATED, 0, 0, 0, 0, 0, 0, 3 };
static u_char gzheader[10] = { 0x1f, 0x8b, Z_DEFLATED, 0, 0, 0, 0, 0, 0, 3 };
#if (HAVE_LITTLE_ENDIAN)
@ -240,8 +242,8 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
/*
* We preallocate a memory for zlib in one hunk (200K-400K), this
* dicreases number of malloc() and free() calls and probably
* syscalls.
* dicreases a number of malloc() and free() calls and also probably
* dicreases a number of syscalls.
* Besides we free() this memory as soon as the gzipping will complete
* and do not wait while a whole response will be sent to a client.
*
@ -591,28 +593,21 @@ static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf,
}
static char *ngx_http_gzip_set_window(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf)
static char *ngx_http_gzip_set_window(ngx_conf_t *cf, void *post, void *data)
{
ngx_http_gzip_conf_t *lcf = conf;
int *np = data;
int wbits, wsize;
char *rv;
int wbits, wsize;
rv = ngx_conf_set_size_slot(cf, cmd, conf);
if (rv) {
return rv;
}
ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "WBITS: %d", lcf->wbits);
ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "WBITS: %d", *np);
wbits = 15;
for (wsize = 32 * 1024; wsize > 256; wsize >>= 1) {
if (wsize == lcf->wbits) {
lcf->wbits = wbits;
ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "WBITS: %d", lcf->wbits);
if (wsize == *np) {
*np = wbits;
ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "WBITS: %d", *np);
return NULL;
}
@ -623,28 +618,21 @@ ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "WBITS: %d", lcf->wbits);
}
static char *ngx_http_gzip_set_hash(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf)
static char *ngx_http_gzip_set_hash(ngx_conf_t *cf, void *post, void *data)
{
ngx_http_gzip_conf_t *lcf = conf;
int *np = data;
int memlevel, hsize;
char *rv;
int memlevel, hsize;
rv = ngx_conf_set_size_slot(cf, cmd, conf);
if (rv) {
return rv;
}
ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "MEMLEVEL: %d", lcf->memlevel);
ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "MEMLEVEL: %d", *np);
memlevel = 9;
for (hsize = 128 * 1024; hsize > 256; hsize >>= 1) {
if (hsize == lcf->memlevel) {
lcf->memlevel = memlevel;
ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "MEMLEVEL: %d", lcf->memlevel);
if (hsize == *np) {
*np = memlevel;
ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "MEMLEVEL: %d", *np);
return NULL;
}

View File

@ -188,8 +188,6 @@ static int ngx_http_proxy_handler(ngx_http_request_t *r)
/* STUB */ p->accel = 1;
p->host_header = p->upstream.peers->peers[0].host;
ngx_test_null(p->request_hunks, ngx_http_proxy_create_request(p),
NGX_HTTP_INTERNAL_SERVER_ERROR);
@ -220,7 +218,7 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
+ r->uri.len - p->location_len
+ 1 + r->args.len /* 1 is for "?" */
+ sizeof(http_version) - 1
+ sizeof(host_header) - 1 + p->host_header.len + 2
+ sizeof(host_header) - 1 + p->lcf->upstream->host_header.len + 2
/* 2 is for "\r\n" */
+ sizeof(connection_close_header) - 1
+ 2; /* 2 is for "\r\n" at the header end */
@ -268,7 +266,8 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
/* the "Host" header */
h->last = ngx_cpymem(h->last, host_header, sizeof(host_header) - 1);
h->last = ngx_cpymem(h->last, p->host_header.data, p->host_header.len);
h->last = ngx_cpymem(h->last, p->lcf->upstream->host_header.data,
p->lcf->upstream->host_header.len);
*(h->last++) = CR; *(h->last++) = LF;

View File

@ -73,7 +73,6 @@ struct ngx_http_proxy_ctx_s {
int method;
ngx_str_t uri;
int location_len;
ngx_str_t host_header;
ngx_event_pipe_t *event_pipe;

View File

@ -165,6 +165,13 @@ static ngx_command_t ngx_http_core_commands[] = {
offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
NULL},
{ngx_string("msie_padding"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_flag_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_core_loc_conf_t, msie_padding),
NULL},
{ngx_string("error_log"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_set_error_log,
@ -843,6 +850,8 @@ static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf)
lcf->lingering_time = NGX_CONF_UNSET;
lcf->lingering_timeout = NGX_CONF_UNSET;
lcf->msie_padding = NGX_CONF_UNSET;
return lcf;
}
@ -916,6 +925,8 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
ngx_conf_merge_msec_value(conf->lingering_timeout,
prev->lingering_timeout, 5000);
ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
return NGX_CONF_OK;
}

View File

@ -118,6 +118,8 @@ typedef struct {
ngx_msec_t lingering_time; /* lingering_time */
ngx_msec_t lingering_timeout; /* lingering_timeout */
int msie_padding; /* msie_padding */
ngx_log_t *err_log;
} ngx_http_core_loc_conf_t;

View File

@ -152,9 +152,10 @@ static ngx_str_t error_pages[] = {
int ngx_http_special_response_handler(ngx_http_request_t *r, int error)
{
int err, rc;
ngx_hunk_t *h;
ngx_chain_t *out, **ll, *cl;
int err, rc;
ngx_hunk_t *h;
ngx_chain_t *out, **ll, *cl;
ngx_http_core_loc_conf_t *clcf;
r->headers_out.status = error;
@ -238,7 +239,9 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error)
ngx_alloc_link_and_set_hunk(cl, h, r->pool, NGX_ERROR);
ngx_chain_add_link(out, ll, cl);
if (/* STUB: "msie_padding on/off" */ 1
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
if (clcf->msie_padding
&& r->http_version >= NGX_HTTP_VERSION_10
&& error >= NGX_HTTP_BAD_REQUEST
&& error != NGX_HTTP_REQUEST_URI_TOO_LARGE