Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
bugfix: ngx_echo's config directives was not inherited automatically …
…by location if blocks.
  • Loading branch information
agentzh committed Jun 20, 2012
1 parent 4a77aaf commit 4d7cb5f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 42 deletions.
35 changes: 16 additions & 19 deletions src/ngx_http_echo_handler.c
Expand Up @@ -120,6 +120,10 @@ ngx_http_echo_handler(ngx_http_request_t *r)

dd("run cmds returned %d", (int) rc);

if (rc == NGX_OK || rc == NGX_DONE || rc == NGX_DECLINED) {
return rc;
}

if (rc == NGX_ERROR) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
Expand All @@ -128,33 +132,26 @@ ngx_http_echo_handler(ngx_http_request_t *r)
return rc;
}

if (rc == NGX_DONE) {
return NGX_DONE;
}
/* rc == NGX_AGAIN */

if (rc == NGX_AGAIN) {
#if defined(nginx_version) && nginx_version >= 8011
r->main->count++;
r->main->count++;
#endif

/* XXX we need this for 0.7.x and 0.8.x < 0.8.11 */
dd("%d", r->connection->destroyed);
dd("%d", r->done);
dd("%d", r->connection->destroyed);
dd("%d", r->done);

ctx = ngx_http_get_module_ctx(r, ngx_http_echo_module);
if (ctx) {
dd("mark busy %d for %.*s", (int) ctx->next_handler_cmd,
(int) r->uri.len,
r->uri.data);

ctx->waiting = 1;
ctx->done = 0;
}
ctx = ngx_http_get_module_ctx(r, ngx_http_echo_module);
if (ctx) {
dd("mark busy %d for %.*s", (int) ctx->next_handler_cmd,
(int) r->uri.len,
r->uri.data);

return NGX_DONE;
ctx->waiting = 1;
ctx->done = 0;
}

return NGX_OK;
return NGX_DONE;
}


Expand Down
52 changes: 29 additions & 23 deletions src/ngx_http_echo_module.c
Expand Up @@ -12,66 +12,49 @@
#include <ngx_log.h>

/* config init handler */
static void * ngx_http_echo_create_conf(ngx_conf_t *cf);
static void * ngx_http_echo_create_loc_conf(ngx_conf_t *cf);
static char * ngx_http_echo_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child);

/* config directive handlers */
static char * ngx_http_echo_echo(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);

static char * ngx_http_echo_echo_request_body(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);

static char * ngx_http_echo_echo_sleep(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);

static char * ngx_http_echo_echo_flush(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);

static char * ngx_http_echo_echo_blocking_sleep(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);

static char * ngx_http_echo_echo_reset_timer(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);

static char * ngx_http_echo_echo_before_body(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);

static char * ngx_http_echo_echo_after_body(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);

static char * ngx_http_echo_echo_location_async(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);

static char * ngx_http_echo_echo_location(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);

static char * ngx_http_echo_echo_subrequest_async(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);

static char * ngx_http_echo_echo_subrequest(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);

static char * ngx_http_echo_echo_duplicate(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);

static char * ngx_http_echo_echo_read_request_body(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);

static char * ngx_http_echo_echo_foreach_split(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);

static char * ngx_http_echo_echo_end(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);

static char * ngx_http_echo_echo_abort_parent(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);

static char * ngx_http_echo_echo_exec(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);

static char * ngx_http_echo_helper(ngx_http_echo_opcode_t opcode,
ngx_http_echo_cmd_category_t cat,
ngx_conf_t *cf, ngx_command_t *cmd, void* conf);
ngx_conf_t *cf, ngx_command_t *cmd, void *conf);


static ngx_http_module_t ngx_http_echo_module_ctx = {
Expand All @@ -85,8 +68,8 @@ static ngx_http_module_t ngx_http_echo_module_ctx = {
NULL, /* create server configuration */
NULL, /* merge server configuration */

ngx_http_echo_create_conf, /* create location configuration */
NULL /* merge location configuration */
ngx_http_echo_create_loc_conf, /* create location configuration */
ngx_http_echo_merge_loc_conf /* merge location configuration */
};


Expand Down Expand Up @@ -239,7 +222,7 @@ ngx_module_t ngx_http_echo_module = {


static void *
ngx_http_echo_create_conf(ngx_conf_t *cf)
ngx_http_echo_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_echo_loc_conf_t *conf;

Expand All @@ -260,6 +243,29 @@ ngx_http_echo_create_conf(ngx_conf_t *cf)
}


static char *
ngx_http_echo_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_echo_loc_conf_t *prev = parent;
ngx_http_echo_loc_conf_t *conf = child;

if (conf->handler_cmds == NULL) {
conf->handler_cmds = prev->handler_cmds;
conf->seen_leading_output = prev->seen_leading_output;
}

if (conf->before_body_cmds == NULL) {
conf->before_body_cmds = prev->before_body_cmds;
}

if (conf->after_body_cmds == NULL) {
conf->after_body_cmds = prev->after_body_cmds;
}

return NGX_CONF_OK;
}


static char *
ngx_http_echo_helper(ngx_http_echo_opcode_t opcode,
ngx_http_echo_cmd_category_t cat,
Expand Down
35 changes: 35 additions & 0 deletions t/if.t
Expand Up @@ -113,3 +113,38 @@ too long
--- response_body
ok
=== TEST 7: echo should be inherited by if blocks
--- config
location /foo {
if ($uri ~ 'foo') {
}
echo ok;
}
--- request
GET /foo
--- response_body
ok
=== TEST 8: echo_after_body and echo_before_body should be inherited by if blocks
--- config
location /foo {
if ($uri ~ 'foo') {
}
echo_before_body -n 'hello';
echo_location /comma;
echo_after_body 'world';
}
location = /comma {
internal;
echo -n ', ';
}
--- request
GET /foo
--- response_body
hello, world

0 comments on commit 4d7cb5f

Please sign in to comment.