Updated the nginx-echo module with the 0.41 version.

This commit is contained in:
Cyril Lavier 2012-12-12 11:24:11 +01:00
parent 18e70f08f3
commit e1c052af95
17 changed files with 558 additions and 963 deletions

View file

@ -22,7 +22,7 @@ README for Modules versions
nginx-echo
https://github.com/agentzh/echo-nginx-module
Version: v0.38rc2-7-g080c0a1
Version: v0.41
nginx-lua
Homepage: https://github.com/chaoslawful/lua-nginx-module

63
debian/modules/nginx-echo/.gitignore vendored Normal file
View file

@ -0,0 +1,63 @@
.libs
*.swp
*.slo
*.la
*.swo
*.lo
*.mobi
genmobi.sh
*~
*.o
print.txt
.rsync
*.tar.gz
dist
build[789]
build
tags
update-readme
*.tmp
test/Makefile
test/blib
test.sh
t.sh
t/t.sh
test/t/servroot/
releng
reset
*.t_
reindex
src/location.h
src/filter.c
src/subrequest.h
src/sleep.h
src/util.c
src/echo.c
src/info.c
src/util.h
src/var.h
src/filter.h
src/sleep.c
src/var.c
src/timer.c
src/module.h
src/echo.h
src/info.h
src/foreach.c
src/location.c
src/timer.h
src/module.c
src/subrequest.c
src/handler.h
src/foreach.h
src/handler.c
nginx
*.html
ctags
t/servroot
all
buildroot/
go
Changes
build1[012]
analyze

View file

@ -9,9 +9,9 @@ Status
This module is production ready.
Version
This document describes echo-nginx-module v0.38rc2
(<https://github.com/agentzh/echo-nginx-module/tags>) released on 21
March 2012.
This document describes ngx_echo v0.41
(<https://github.com/agentzh/echo-nginx-module/tags>) released on 12
August 2012.
Synopsis
location /hello {
@ -195,13 +195,6 @@ Description
handler or register itself as an output filter only upon demand. By
default, this module does not do anything at all.
Use of any of this module's directives (no matter content handler
directives or filter directives) will force the chunked encoding to be
used for the HTTP response due to the streaming nature of this module
(unless HTTP 1.0 is enforced by the client and the Content-Length header
will be set to the size of the first handler directive that generates
contents).
Technially, this module has also demonstrated the following techniques
that might be helpful for module writers:
@ -1089,6 +1082,39 @@ Content Handler Directives
This directive was first introduced in the v0.21 release.
echo_status
syntax: *echo_status <status-num>*
default: *echo_status 200*
context: *location, location if*
phase: *content*
Specify the default response status code. Default to 200. This directive
is declarative and the relative order with other echo-like directives is
not important.
Here is an example,
location = /bad {
echo_status 404;
echo "Something is missing...";
}
then we get a response like this:
HTTP/1.1 404 Not Found
Server: nginx/1.2.1
Date: Sun, 24 Jun 2012 03:58:18 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
Something is missing...
This directive was first introduced in the "v0.40" release.
Filter Directives
Use of the following directives trigger the filter registration of this
module. By default, no filter will be registered by this module.
@ -1353,12 +1379,12 @@ Installation
source:
Grab the nginx source code from nginx.org (<http://nginx.org/>), for
example, the version 1.0.11 (see nginx compatibility), and then build
the source with this module:
example, the version 1.2.1 (see nginx compatibility), and then build the
source with this module:
$ wget 'http://sysoev.ru/nginx/nginx-1.0.11.tar.gz'
$ tar -xzvf nginx-1.0.11.tar.gz
$ cd nginx-1.0.11/
$ wget 'http://sysoev.ru/nginx/nginx-1.2.1.tar.gz'
$ tar -xzvf nginx-1.2.1.tar.gz
$ cd nginx-1.2.1/
# Here we assume you would install you nginx under /opt/nginx/.
$ ./configure --prefix=/opt/nginx \
@ -1377,6 +1403,8 @@ Installation
Compatibility
The following versions of Nginx should work with this module:
* 1.2.x (last tested: 1.2.1)
* 1.1.x (last tested: 1.1.5)
* 1.0.x (last tested: 1.0.11)
@ -1434,6 +1462,15 @@ Limitations
? echo $a;
? }
Community
English Mailing List
The openresty-en (<https://groups.google.com/group/openresty-en>)
mailing list is for English speakers.
Chinese Mailing List
The openresty (<https://groups.google.com/group/openresty>) mailing list
is for Chinese speakers.
Report Bugs
Although a lot of effort has been put into testing and code tuning,
there must be some serious bugs lurking somewhere in this module. So
@ -1443,360 +1480,18 @@ Report Bugs
(<http://github.com/agentzh/echo-nginx-module/issues>) provided by
GitHub,
2. or send a bug report, questions, or even patches to the nginx
mailing list (<http://mailman.nginx.org/mailman/listinfo/nginx>).
2. or send a bug report, questions, or even patches to the OpenResty
Community.
Source Repository
Available on github at agentzh/echo-nginx-module
(<http://github.com/agentzh/echo-nginx-module>).
ChangeLog
v0.37
January 13, 2012
Changes
The changes of every release of this module can be obtained from the
ngx_openresty bundle's change logs:
* bugfix: data truncation might occur with echo_after_body in
not-so-good networks (we should be prepared for "NGX_AGAIN" returned
by downstream output filters). thanks 林青 (Kindy Lin) for reporting
it.
* bugfix: we no longer check "sync" buffers for subrequests because it
is incorrect.
* bugfix: fixed a bug when sending out response headers: we did not
take into account the "NGX_ERROR" error code returned by
"ngx_http_send_header".
* bugfix: we did not work with HEAD http requests before.
* bugfix: now we carefully eliminate empty flush buffers in
echo_after_body to work around a long-standing bug in the standard
[[HttpGzipModule]].
* bugfix: we might send empty chain link in echo_after_body because it
may trigger the infamous "the http output chain is empty" alert in
"error.log" when the standard [[HttpSsiModule]] is disabled. thanks
Sparsh Gupta.
* bugfix: we did not set subrequest's "Content-Length" request headers
which could cause problems in the backends.
* bugfix: echo_exec + named locations might cause weird issues and now
we explicitly clear all the modules' contexts before calling
"ngx_http_named_location".
* bugfix: echo_exec might hang when running after echo_sleep (or other
I/O interruption calls): we should have called
"ngx_http_finalize_request" on "NGX_DONE" to decrement
"r->main->count" anyway.
* bugfix: there was a memory issue in both echo_sleep and
echo_blocking_sleep: we should not pass "ngx_str_t" strings to
"atof()" which expects C strings.
* bugfix: some users report that this module cannot be compiled with
Nginx 1.0.x on their systems due to "ngx_time_update" (as in github
issue #7 (<https://github.com/agentzh/echo-nginx-module/issues/7>)).
this is a blind attemp to fix it because we could not reproduce it
on our side.
* bugfix: fixed places in the source code that we did not check null
pointers returned by the memory allocator.
v0.36
July 08, 2011
* now we back-ported the subrequest mechanism of ngx_lua to ngx_echo.
this also helps some crazy test cases of mixing echo_location and
echo_location_async pass now.
* now echo_location and its friends can work with ngx_xss (as well as
other output filter modules) completely. thanks wd for reporting
this issue.
* done some minor optimization when modifying subrequest's
content-length header.
* now we always pad a trailing \0 to filepath in
"echo_subrequest(_async) METHOD /path -f filepath" because
ngx_open_cached_file requires a C string file name. thanks dr-dr xp.
* made our filter optimization works with nginx HUP by clearing the
ngx_http_echo_filter_used flag at nginx pre-config callback. thanks
Marcus Clyne.
v0.35
February 07, 2011
* added the "-f /path/to/file" option to the echo_subrequest and
echo_subrequest_async directives to allow POST/PUT a disk file in
the subrequest. thanks Bernd Dorn (<https://github.com/dobe>).
v0.34
September 14, 2010
* we no longer use the problematic "ngx_strXcmp" macros in our source
because it may cause invalid reads and thus segmentation faults.
thanks Piotr Sikora.
v0.33
June 08, 2010
* fixed compatibility with nginx 0.7.66+ because the ngx_time_update
macro's parameter list has changed. thanks Guang Feng (蔡镜明).
v0.32
June 04, 2010
* we should have used "ngx_calloc_buf" instead of "ngx_alloc_buf" for
the last chunk generated for echo_after_body. thanks valgrind's
memcheck tool.
* we should initialize flags before feeding it into
"ngx_http_parse_unsafe_uri". thanks valgrind's memcheck tool.
* fixed a minor issue in the echo_location/echo_subrequest
implementation, which used to have race conditions.
v0.31
May 24, 2010
* the echo wev handler should not proceed if it is still waiting for
some sequential subrequest or has just processed one to avoid
bouncing issues.
* fixed a segfault for echo_exec for 0.7.x: we should check "r->done"
before proceeding.
* no longer explicitly set "r->write_event_handler" to
"ngx_http_request_empty_handler" because it's totally wrong for the
state machine.
* fixed the sequential subrequest model bugs: we should ensure the
"pr->write_event_handler" gets called immediately after the
"post_subrequest" callback when the subrequest finalizes.
v0.30
May 06, 2010
* fixed the echo_exec directive for nginx >= 0.8.11. we didn't get the
"r->main->count" right in the previous version.
v0.29
May 05, 2010
* refactored the core of this module. now the implementation of
echo_location, echo_subrequest, echo_sleep, and
echo_read_request_body finally fit well with the nginx event model
and Igor Sysoev's way of thinking.
v0.28
May 03, 2010
* added support for the "-n" and "--" options to the echo,
echo_before_body, and echo_after_body directives.
v0.27
April 02, 2010
* applied the patch from Sergey A. Osokin to work with nginx 0.8.35.
v0.26
January 26, 2010
* bug fix: we should bypass upstream filters in our echo filters. an
output filter should ever call "ngx_http_output_filter" nor
"ngx_http_send_special".
v0.25
January 15, 2010
* now we register a request cleanup handler to ensure our sleep
event's timer will always get properly deleted even if the request
is quit prematurely. this affects the echo_sleep directive.
* use ngx_null_string whenever possible in the source.
* sync'd the bundled test scaffold to Test::Nginx 0.07.
v0.24
December 28, 2009
* various source file name and coding style fixes. (the code now looks
more like Igor Sysoev's.)
v0.23
December 04, 2009
* now the subrequest can read the client request body directly (for
the main request) because we made subrequests inherit its parent's
"r->header_in" as well. This affects the echo_read_request_body
directive.
* fixed echo_after_body in subrequests by using a hack (checking
"cl->buf->sync" for the last buf) for nginx 0.8.7+ only.
* added new varaible $echo_response_status to help testing the status
code of a subrequest. (The memc module makes use of it.)
* use the "ngx_calloc_buf" macro to allocate new bufs in the code
rather than explicit "ngx_pcalloc" calls for safety.
v0.22
November 25, 2009
* Now we allowed all the directives appear in the [module
(HttpRewriteModule)]'s if block. But so far I've only tested the
echo directive.
v0.21
November 23, 2009
* Added a new directive named echo_exec which does internal redirect
to other (named) locations.
v0.20
November 20, 2009
* Fixed a bug in echo_sleep's "r->main->count" handling for nginx
0.8.x. This bug will cause the server to hang when proxing a
location with echo_sleep.
* Applied the "ngx_str3cmp", "ngx_str4cmp", and "ngx_str6cmp"
optimizing macros to the "parse_method_name" function, as suggested
by Marcus Clyne.
* Added TODO items regarding $echo_random and "echo_repeat" suggested
by Marcus Clyne.
v0.19
November 19, 2009
* Fixed the CPS-style chained subrequest model for the echo_location
and echo_subrequest directives. they are now working perfectly and
will not hang the server with the recent nginx 0.8.21 ~ 0.8.27
releases. To be specifically, the chained subrequest should call
"ngx_http_finalize_request" on its parent request if the content
handler of the parent request does not return "NGX_DONE".
* Undeprecated the echo_location and echo_subrequest directives.
v0.18
November 15, 2009
* Fixed the "zero size buf in output" alerts in error.log.
* Added the new directive echo_request_body.
* Now we use the "ngx_http_parse_unsafe_uri" function to check the
locations to echo_location_async and its friends. Thanks Arvind
Jayaprakash for suggesting this fix.
* Deprecated the echo_location and echo_subrequest directives.
* For HTTP 1.0 clients, use the buf length of the first chain link as
the output header Content-Length.
* Implemented new variable $echo_incr.
v0.17
October 26, 2009
* Added new directives echo_foreach_split and echo_end. Also
introduced a "topic variable" named $echo_it.
* Added new variables $echo_request_uri and
$echo_cacheable_request_uri.
v0.16
October 25, 2009
* Now the subrequests issued by the echo_location_async and
echo_location directives no longer inherit cached variable values
from its parent request. (The underlying "ngx_http_subrequest"
function, however, does automatic cachable variable value
inheritance.)
* Added an undocumented variable *echo_cached_request_uri* to help
testing of this module.
v0.15
October 24, 2009
* Added new directives echo_subrequest and echo_subrequest_async for
the full nginx subrequest API.
* Removed the "echo_client_request_headers" directive, and provided
the $echo_client_request_headers variable instead.
* Added new variables $echo_request_method and
$echo_client_request_method.
v0.14
October 22, 2009
* Added new directive echo_read_request_body to explicitly read client
request body so that the [[HttpCoreModule#$request_body]] variable
will always have non-empty values.
* Now we shuffer test cases automatically in .t files and fixed bugs
in the tests themselves which are hidden by config reload fallback
in failure.
v0.13
October 21, 2009
* Fixed the special cases when the outputs of a echo_duplicate
directive is empty.
* Now we explicitly clear content length and accept ranges headers in
the content handler.
v0.12
October 21, 2009
* Implemented the echo_location directive, which can issue chained GET
subrequests in the Continuation Passing Style (CPS), rather than the
parallel subrequest issued by the echo_location_async directive.
v0.11
October 20, 2009
* Implemented the echo_duplicate directive to help generating large
chunk of data for testing.
v0.10
October 20, 2009
* Fixed compilation regression against Nginx 0.7.21. This bug appears
in version 0.09.
* Refactored the codebase by splitting source into various small
files.
v0.09
October 19, 2009
* Reimplement the echo_sleep directive using per-request event and
timer; the old implementation uses the global connection's
read/write event to register timer, so it will break horribly when
multiple subrequests "sleep" at the same time.
* Added the echo_location_async directive which can issue a GET
subrequest and insert its contents herein.
v0.08
October 18, 2009
* echo_sleep: now we delete our "write event timer" in the
"post_sleep" handle.
* Added "doc/manpage.wiki" which tracks changes in the wiki page
(<http://wiki.nginx.org/HttpEchoModule>).
* Added the "util/wiki2pod.pl" script to convert "doc/manpage.wiki" to
"README".
* Disabled the "DDEBUG" macro in the C source by default.
http://openresty.org/#Changes
Test Suite
This module comes with a Perl-driven test suite. The test cases
@ -1895,16 +1590,13 @@ Getting involved
a commit bit to the source repository on GitHub.
Author
Zhang "agentzh" Yichun (章亦春) *<agentzh@gmail.com>*
Yichun "agentzh" Zhang (章亦春) *<agentzh@gmail.com>*
This wiki page is also maintained by the author himself, and everybody
is encouraged to improve this page as well.
Copyright & License
Copyright (c) 2009, 2010, 2011, Taobao Inc., Alibaba Group (
http://www.taobao.com ).
Copyright (c) 2009, 2010, 2011, Zhang "agentzh" Yichun (章亦春)
Copyright (c) 2009-2012, Yichun "agentzh" Zhang (章亦春)
<agentzh@gmail.com>.
This module is licensed under the terms of the BSD license.

View file

@ -1,3 +1,8 @@
<!---
Don't edit this file manually! Instead you should generate it by using:
wiki2markdown.pl doc/HttpEchoModule.wiki
-->
Name
====
@ -13,7 +18,7 @@ This module is production ready.
Version
=======
This document describes echo-nginx-module [v0.38rc2](https://github.com/agentzh/echo-nginx-module/tags) released on 21 March 2012.
This document describes ngx_echo [v0.41](https://github.com/agentzh/echo-nginx-module/tags) released on 12 August 2012.
Synopsis
========
@ -214,8 +219,6 @@ People will also find it useful in real-world applications that need to
This is a special dual-role module that can *lazily* serve as a content handler or register itself as an output filter only upon demand. By default, this module does not do anything at all.
Use of any of this module's directives (no matter [content handler directives](http://wiki.nginx.org/HttpEchoModule#Content_Handler_Directives) or [filter directives](http://wiki.nginx.org/HttpEchoModule#Filter_Directives)) will force the chunked encoding to be used for the HTTP response due to the streaming nature of this module (unless HTTP 1.0 is enforced by the client and the Content-Length header will be set to the size of the first handler directive that generates contents).
Technially, this module has also demonstrated the following techniques that might be helpful for module writers:
1. Issue parallel subreqeusts directly from content handler.
@ -1073,6 +1076,42 @@ Technically speaking, this directive exposes the Nginx internal API functions `n
This directive was first introduced in the [v0.21 release](http://wiki.nginx.org/HttpEchoModule#v0.21).
echo_status
-----------
**syntax:** *echo_status &lt;status-num&gt;*
**default:** *echo_status 200*
**context:** *location, location if*
**phase:** *content*
Specify the default response status code. Default to `200`. This directive is declarative and the relative order with other echo-like directives is not important.
Here is an example,
location = /bad {
echo_status 404;
echo "Something is missing...";
}
then we get a response like this:
HTTP/1.1 404 Not Found
Server: nginx/1.2.1
Date: Sun, 24 Jun 2012 03:58:18 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
Something is missing...
This directive was first introduced in the `v0.40` release.
Filter Directives
=================
@ -1337,12 +1376,12 @@ You're recommended to install this module (as well as the Nginx core and many ot
Alternatively, you can install this module manually with the Nginx source:
Grab the nginx source code from [nginx.org](http://nginx.org/), for example,
the version 1.0.11 (see [nginx compatibility](http://wiki.nginx.org/HttpEchoModule#Compatibility)), and then build the source with this module:
the version 1.2.1 (see [nginx compatibility](http://wiki.nginx.org/HttpEchoModule#Compatibility)), and then build the source with this module:
$ wget 'http://sysoev.ru/nginx/nginx-1.0.11.tar.gz'
$ tar -xzvf nginx-1.0.11.tar.gz
$ cd nginx-1.0.11/
$ wget 'http://sysoev.ru/nginx/nginx-1.2.1.tar.gz'
$ tar -xzvf nginx-1.2.1.tar.gz
$ cd nginx-1.2.1/
# Here we assume you would install you nginx under /opt/nginx/.
$ ./configure --prefix=/opt/nginx \
@ -1361,6 +1400,7 @@ Compatibility
The following versions of Nginx should work with this module:
* **1.2.x** (last tested: 1.2.1)
* **1.1.x** (last tested: 1.1.5)
* **1.0.x** (last tested: 1.0.11)
* **0.9.x** (last tested: 0.9.4)
@ -1405,275 +1445,38 @@ By design, all of this module's directives do not inherit between nested locatio
? }
Community
=========
English Mailing List
--------------------
The [openresty-en](https://groups.google.com/group/openresty-en) mailing list is for English speakers.
Chinese Mailing List
--------------------
The [openresty](https://groups.google.com/group/openresty) mailing list is for Chinese speakers.
Report Bugs
===========
Although a lot of effort has been put into testing and code tuning, there must be some serious bugs lurking somewhere in this module. So whenever you are bitten by any quirks, please don't hesitate to
1. create a ticket on the [issue tracking interface](http://github.com/agentzh/echo-nginx-module/issues) provided by GitHub,
1. or send a bug report, questions, or even patches to the [nginx mailing list](http://mailman.nginx.org/mailman/listinfo/nginx).
1. or send a bug report, questions, or even patches to the [OpenResty Community](http://wiki.nginx.org/HttpEchoModule#Community).
Source Repository
=================
Available on github at [agentzh/echo-nginx-module](http://github.com/agentzh/echo-nginx-module).
ChangeLog
=========
Changes
=======
v0.37
-----
The changes of every release of this module can be obtained from the ngx_openresty bundle's change logs:
January 13, 2012
* bugfix: data truncation might occur with [echo_after_body](http://wiki.nginx.org/HttpEchoModule#echo_after_body) in not-so-good networks (we should be prepared for `NGX_AGAIN` returned by downstream output filters). thanks 林青 (Kindy Lin) for reporting it.
* bugfix: we no longer check `sync` buffers for subrequests because it is incorrect.
* bugfix: fixed a bug when sending out response headers: we did not take into account the `NGX_ERROR` error code returned by `ngx_http_send_header`.
* bugfix: we did not work with HEAD http requests before.
* bugfix: now we carefully eliminate empty flush buffers in [echo_after_body](http://wiki.nginx.org/HttpEchoModule#echo_after_body) to work around a long-standing bug in the standard [HttpGzipModule](http://wiki.nginx.org/HttpGzipModule).
* bugfix: we might send empty chain link in [echo_after_body](http://wiki.nginx.org/HttpEchoModule#echo_after_body) because it may trigger the infamous `"the http output chain is empty"` alert in `error.log` when the standard [HttpSsiModule](http://wiki.nginx.org/HttpSsiModule) is disabled. thanks Sparsh Gupta.
* bugfix: we did not set subrequest's `Content-Length` request headers which could cause problems in the backends.
* bugfix: [echo_exec](http://wiki.nginx.org/HttpEchoModule#echo_exec) + named locations might cause weird issues and now we explicitly clear all the modules' contexts before calling `ngx_http_named_location`.
* bugfix: [echo_exec](http://wiki.nginx.org/HttpEchoModule#echo_exec) might hang when running after [echo_sleep](http://wiki.nginx.org/HttpEchoModule#echo_sleep) (or other I/O interruption calls): we should have called `ngx_http_finalize_request` on `NGX_DONE` to decrement `r->main->count` anyway.
* bugfix: there was a memory issue in both [echo_sleep](http://wiki.nginx.org/HttpEchoModule#echo_sleep) and [echo_blocking_sleep](http://wiki.nginx.org/HttpEchoModule#echo_blocking_sleep): we should not pass `ngx_str_t` strings to `atof()` which expects C strings.
* bugfix: some users report that this module cannot be compiled with Nginx 1.0.x on their systems due to `ngx_time_update` (as in [github issue #7](https://github.com/agentzh/echo-nginx-module/issues/7)). this is a blind attemp to fix it because we could not reproduce it on our side.
* bugfix: fixed places in the source code that we did not check null pointers returned by the memory allocator.
v0.36
-----
July 08, 2011
* now we back-ported the subrequest mechanism of ngx_lua to ngx_echo. this also helps some crazy test cases of mixing echo_location and echo_location_async pass now.
* now echo_location and its friends can work with ngx_xss (as well as other output filter modules) completely. thanks wd for reporting this issue.
* done some minor optimization when modifying subrequest's content-length header.
* now we always pad a trailing \0 to filepath in "echo_subrequest(_async) METHOD /path -f filepath" because ngx_open_cached_file requires a C string file name. thanks dr-dr xp.
* made our filter optimization works with nginx HUP by clearing the ngx_http_echo_filter_used flag at nginx pre-config callback. thanks Marcus Clyne.
v0.35
-----
February 07, 2011
* added the `-f /path/to/file` option to the [echo_subrequest](http://wiki.nginx.org/HttpEchoModule#echo_subrequest) and [echo_subrequest_async](http://wiki.nginx.org/HttpEchoModule#echo_subrequest_async) directives to allow POST/PUT a disk file in the subrequest. thanks [Bernd Dorn](https://github.com/dobe).
v0.34
-----
September 14, 2010
* we no longer use the problematic `ngx_strXcmp` macros in our source because it may cause invalid reads and thus segmentation faults. thanks Piotr Sikora.
v0.33
-----
June 08, 2010
* fixed compatibility with nginx 0.7.66+ because the ngx_time_update macro's parameter list has changed. thanks Guang Feng (蔡镜明).
v0.32
-----
June 04, 2010
* we should have used `ngx_calloc_buf` instead of `ngx_alloc_buf` for the last chunk generated for [echo_after_body](http://wiki.nginx.org/HttpEchoModule#echo_after_body). thanks valgrind's memcheck tool.
* we should initialize flags before feeding it into `ngx_http_parse_unsafe_uri`. thanks valgrind's memcheck tool.
* fixed a minor issue in the [echo_location](http://wiki.nginx.org/HttpEchoModule#echo_location)/[echo_subrequest](http://wiki.nginx.org/HttpEchoModule#echo_subrequest) implementation, which used to have race conditions.
v0.31
-----
May 24, 2010
* the echo wev handler should not proceed if it is still waiting for some sequential subrequest or has just processed one to avoid bouncing issues.
* fixed a segfault for echo_exec for 0.7.x: we should check `r->done` before proceeding.
* no longer explicitly set `r->write_event_handler` to `ngx_http_request_empty_handler` because it's totally wrong for the state machine.
* fixed the sequential subrequest model bugs: we should ensure the `pr->write_event_handler` gets called immediately after the `post_subrequest` callback when the subrequest finalizes.
v0.30
-----
May 06, 2010
* fixed the [echo_exec](http://wiki.nginx.org/HttpEchoModule#echo_exec) directive for nginx >= 0.8.11. we didn't get the `r->main->count` right in the previous version.
v0.29
-----
May 05, 2010
* refactored the core of this module. now the implementation of [echo_location](http://wiki.nginx.org/HttpEchoModule#echo_location), [echo_subrequest](http://wiki.nginx.org/HttpEchoModule#echo_subrequest), [echo_sleep](http://wiki.nginx.org/HttpEchoModule#echo_sleep), and [echo_read_request_body](http://wiki.nginx.org/HttpEchoModule#echo_read_request_body) finally fit well with the nginx event model and Igor Sysoev's way of thinking.
v0.28
-----
May 03, 2010
* added support for the `-n` and `--` options to the [echo](http://wiki.nginx.org/HttpEchoModule#echo), [echo_before_body](http://wiki.nginx.org/HttpEchoModule#echo_before_body), and [echo_after_body](http://wiki.nginx.org/HttpEchoModule#echo_after_body) directives.
v0.27
-----
April 02, 2010
* applied the patch from Sergey A. Osokin to work with nginx 0.8.35.
v0.26
-----
January 26, 2010
* bug fix: we should bypass upstream filters in our echo filters. an output filter should ever call `ngx_http_output_filter` nor `ngx_http_send_special`.
v0.25
-----
January 15, 2010
* now we register a request cleanup handler to ensure our sleep event's timer will always get properly deleted even if the request is quit prematurely. this affects the echo_sleep directive.
* use ngx_null_string whenever possible in the source.
* sync'd the bundled test scaffold to Test::Nginx 0.07.
v0.24
-----
December 28, 2009
* various source file name and coding style fixes. (the code now looks more like Igor Sysoev's.)
v0.23
-----
December 04, 2009
* now the subrequest can read the client request body directly (for the main request) because we made subrequests inherit its parent's `r->header_in` as well. This affects the [echo_read_request_body](http://wiki.nginx.org/HttpEchoModule#echo_read_request_body) directive.
* fixed [echo_after_body](http://wiki.nginx.org/HttpEchoModule#echo_after_body) in subrequests by using a hack (checking `cl->buf->sync` for the last buf) for nginx 0.8.7+ only.
* added new varaible [$echo_response_status](http://wiki.nginx.org/HttpEchoModule#.24echo_response_status) to help testing the status code of a subrequest. (The [memc](http://wiki.nginx.org/HttpMemcModule) module makes use of it.)
* use the `ngx_calloc_buf` macro to allocate new bufs in the code rather than explicit `ngx_pcalloc` calls for safety.
v0.22
-----
November 25, 2009
* Now we allowed all the directives appear in the [rewrite module](http://wiki.nginx.org/HttpRewriteModule)'s [if](http://wiki.nginx.org/HttpRewriteModule#if) block. But so far I've only tested the [echo](http://wiki.nginx.org/HttpEchoModule#echo) directive.
v0.21
-----
November 23, 2009
* Added a new directive named [echo_exec](http://wiki.nginx.org/HttpEchoModule#echo_exec) which does internal redirect to other (named) locations.
v0.20
-----
November 20, 2009
* Fixed a bug in [echo_sleep](http://wiki.nginx.org/HttpEchoModule#echo_sleep)'s `r->main->count` handling for nginx 0.8.x. This bug will cause the server to hang when proxing a location with [echo_sleep](http://wiki.nginx.org/HttpEchoModule#echo_sleep).
* Applied the `ngx_str3cmp`, `ngx_str4cmp`, and `ngx_str6cmp` optimizing macros to the `parse_method_name` function, as suggested by Marcus Clyne.
* Added [TODO items](http://wiki.nginx.org/HttpEchoModule#TODO) regarding `$echo_random` and `echo_repeat` suggested by Marcus Clyne.
v0.19
-----
November 19, 2009
* Fixed the CPS-style chained subrequest model for the [echo_location](http://wiki.nginx.org/HttpEchoModule#echo_location) and [echo_subrequest](http://wiki.nginx.org/HttpEchoModule#echo_subrequest) directives. they are now working perfectly and will not hang the server with the recent nginx 0.8.21 ~ 0.8.27 releases. To be specifically, the chained subrequest should call `ngx_http_finalize_request` on its parent request if the content handler of the parent request does not return `NGX_DONE`.
* Undeprecated the [echo_location](http://wiki.nginx.org/HttpEchoModule#echo_location) and [echo_subrequest](http://wiki.nginx.org/HttpEchoModule#echo_subrequest) directives.
v0.18
-----
November 15, 2009
* Fixed the "zero size buf in output" alerts in error.log.
* Added the new directive [echo_request_body](http://wiki.nginx.org/HttpEchoModule#echo_request_body).
* Now we use the `ngx_http_parse_unsafe_uri` function to check the locations to [echo_location_async](http://wiki.nginx.org/HttpEchoModule#echo_location_async) and its friends. Thanks Arvind Jayaprakash for suggesting this fix.
* Deprecated the [echo_location](http://wiki.nginx.org/HttpEchoModule#echo_location) and [echo_subrequest](http://wiki.nginx.org/HttpEchoModule#echo_subrequest) directives.
* For HTTP 1.0 clients, use the buf length of the first chain link as the output header Content-Length.
* Implemented new variable [$echo_incr](http://wiki.nginx.org/HttpEchoModule#.24echo_incr).
v0.17
-----
October 26, 2009
* Added new directives [echo_foreach_split](http://wiki.nginx.org/HttpEchoModule#echo_foreach_split) and [echo_end](http://wiki.nginx.org/HttpEchoModule#echo_end). Also introduced a "topic variable" named [$echo_it](http://wiki.nginx.org/HttpEchoModule#.24echo_it).
* Added new variables [$echo_request_uri](http://wiki.nginx.org/HttpEchoModule#.24echo_request_uri) and [$echo_cacheable_request_uri](http://wiki.nginx.org/HttpEchoModule#.24echo_cacheable_request_uri).
v0.16
-----
October 25, 2009
* Now the subrequests issued by the [echo_location_async](http://wiki.nginx.org/HttpEchoModule#echo_location) and [echo_location](http://wiki.nginx.org/HttpEchoModule#echo_location) directives no longer inherit cached variable values from its parent request. (The underlying `ngx_http_subrequest` function, however, does automatic cachable variable value inheritance.)
* Added an undocumented variable *echo_cached_request_uri* to help testing of this module.
v0.15
-----
October 24, 2009
* Added new directives [echo_subrequest](http://wiki.nginx.org/HttpEchoModule#echo_subrequest) and [echo_subrequest_async](http://wiki.nginx.org/HttpEchoModule#echo_subrequest_async) for the full nginx subrequest API.
* Removed the `echo_client_request_headers` directive, and provided the [$echo_client_request_headers](http://wiki.nginx.org/HttpEchoModule#.24echo_client_request_headers) variable instead.
* Added new variables [$echo_request_method](http://wiki.nginx.org/HttpEchoModule#.24echo_request_method) and [$echo_client_request_method](http://wiki.nginx.org/HttpEchoModule#.24echo_client_request_method).
v0.14
-----
October 22, 2009
* Added new directive [echo_read_request_body](http://wiki.nginx.org/HttpEchoModule#echo_read_request_body) to explicitly read client request body so that the [[HttpCoreModule#$request_body]] variable will always have non-empty values.
* Now we shuffer test cases automatically in .t files and fixed bugs in the tests themselves which are hidden by config reload fallback in failure.
v0.13
-----
October 21, 2009
* Fixed the special cases when the outputs of a [echo_duplicate](http://wiki.nginx.org/HttpEchoModule#echo_duplicate) directive is empty.
* Now we explicitly clear content length and accept ranges headers in the content handler.
v0.12
-----
October 21, 2009
* Implemented the [echo_location](http://wiki.nginx.org/HttpEchoModule#echo_location) directive, which can issue chained GET subrequests in the Continuation Passing Style (CPS), rather than the parallel subrequest issued by the [echo_location_async](http://wiki.nginx.org/HttpEchoModule#echo_location_async) directive.
v0.11
-----
October 20, 2009
* Implemented the [echo_duplicate](http://wiki.nginx.org/HttpEchoModule#echo_duplicate) directive to help generating large chunk of data for testing.
v0.10
-----
October 20, 2009
* Fixed compilation regression against Nginx 0.7.21. This bug appears in version 0.09.
* Refactored the codebase by splitting source into various small files.
v0.09
-----
October 19, 2009
* Reimplement the [echo_sleep](http://wiki.nginx.org/HttpEchoModule#echo_sleep) directive using per-request event and timer; the old implementation uses the global connection's read/write event to register timer, so it will break horribly when multiple subrequests "sleep" at the same time.
* Added the [echo_location_async](http://wiki.nginx.org/HttpEchoModule#echo_location_async) directive which can issue a GET subrequest and insert its contents herein.
v0.08
-----
October 18, 2009
* [echo_sleep](http://wiki.nginx.org/HttpEchoModule#echo_sleep): now we delete our `write event timer` in the `post_sleep` handle.
* Added `doc/manpage.wiki` which tracks changes in the [wiki page](http://wiki.nginx.org/HttpEchoModule).
* Added the `util/wiki2pod.pl` script to convert `doc/manpage.wiki` to `README`.
* Disabled the `DDEBUG` macro in the C source by default.
<http://openresty.org/#Changes>
Test Suite
==========
@ -1768,16 +1571,14 @@ You'll be very welcomed to submit patches to the [author](http://wiki.nginx.org/
Author
======
Zhang "agentzh" Yichun (章亦春) *&lt;agentzh@gmail.com&gt;*
Yichun "agentzh" Zhang (章亦春) *&lt;agentzh@gmail.com&gt;*
This wiki page is also maintained by the author himself, and everybody is encouraged to improve this page as well.
Copyright & License
===================
Copyright (c) 2009, 2010, 2011, Taobao Inc., Alibaba Group ( <http://www.taobao.com> ).
Copyright (c) 2009, 2010, 2011, Zhang "agentzh" Yichun (章亦春) <agentzh@gmail.com>.
Copyright (c) 2009-2012, Yichun "agentzh" Zhang (章亦春) <agentzh@gmail.com>.
This module is licensed under the terms of the BSD license.

View file

@ -10,7 +10,7 @@ This module is production ready.
= Version =
This document describes echo-nginx-module [https://github.com/agentzh/echo-nginx-module/tags v0.38rc2] released on 21 March 2012.
This document describes ngx_echo [https://github.com/agentzh/echo-nginx-module/tags v0.41] released on 12 August 2012.
= Synopsis =
@ -209,8 +209,6 @@ People will also find it useful in real-world applications that need to
This is a special dual-role module that can ''lazily'' serve as a content handler or register itself as an output filter only upon demand. By default, this module does not do anything at all.
Use of any of this module's directives (no matter [[#Content Handler Directives|content handler directives]] or [[#Filter Directives|filter directives]]) will force the chunked encoding to be used for the HTTP response due to the streaming nature of this module (unless HTTP 1.0 is enforced by the client and the Content-Length header will be set to the size of the first handler directive that generates contents).
Technially, this module has also demonstrated the following techniques that might be helpful for module writers:
# Issue parallel subreqeusts directly from content handler.
@ -1052,6 +1050,41 @@ Technically speaking, this directive exposes the Nginx internal API functions <c
This directive was first introduced in the [[#v0.21|v0.21 release]].
== echo_status ==
'''syntax:''' ''echo_status <status-num>''
'''default:''' ''echo_status 200''
'''context:''' ''location, location if''
'''phase:''' ''content''
Specify the default response status code. Default to <code>200</code>. This directive is declarative and the relative order with other echo-like directives is not important.
Here is an example,
<geshi lang="nginx">
location = /bad {
echo_status 404;
echo "Something is missing...";
}
</geshi>
then we get a response like this:
<geshi lang="text">
HTTP/1.1 404 Not Found
Server: nginx/1.2.1
Date: Sun, 24 Jun 2012 03:58:18 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
Something is missing...
</geshi>
This directive was first introduced in the <code>v0.40</code> release.
= Filter Directives =
Use of the following directives trigger the filter registration of this module. By default, no filter will be registered by this module.
@ -1301,12 +1334,12 @@ You're recommended to install this module (as well as the Nginx core and many ot
Alternatively, you can install this module manually with the Nginx source:
Grab the nginx source code from [http://nginx.org/ nginx.org], for example,
the version 1.0.11 (see [[#Compatibility|nginx compatibility]]), and then build the source with this module:
the version 1.2.1 (see [[#Compatibility|nginx compatibility]]), and then build the source with this module:
<geshi lang="bash">
$ wget 'http://sysoev.ru/nginx/nginx-1.0.11.tar.gz'
$ tar -xzvf nginx-1.0.11.tar.gz
$ cd nginx-1.0.11/
$ wget 'http://sysoev.ru/nginx/nginx-1.2.1.tar.gz'
$ tar -xzvf nginx-1.2.1.tar.gz
$ cd nginx-1.2.1/
# Here we assume you would install you nginx under /opt/nginx/.
$ ./configure --prefix=/opt/nginx \
@ -1324,6 +1357,7 @@ Also, this module is included and enabled by default in the [http://openresty.or
The following versions of Nginx should work with this module:
* '''1.2.x''' (last tested: 1.2.1)
* '''1.1.x''' (last tested: 1.1.5)
* '''1.0.x''' (last tested: 1.0.11)
* '''0.9.x''' (last tested: 0.9.4)
@ -1366,242 +1400,32 @@ By design, all of this module's directives do not inherit between nested locatio
? }
</geshi>
= Community =
== English Mailing List ==
The [https://groups.google.com/group/openresty-en openresty-en] mailing list is for English speakers.
== Chinese Mailing List ==
The [https://groups.google.com/group/openresty openresty] mailing list is for Chinese speakers.
= Report Bugs =
Although a lot of effort has been put into testing and code tuning, there must be some serious bugs lurking somewhere in this module. So whenever you are bitten by any quirks, please don't hesitate to
# create a ticket on the [http://github.com/agentzh/echo-nginx-module/issues issue tracking interface] provided by GitHub,
# or send a bug report, questions, or even patches to the [http://mailman.nginx.org/mailman/listinfo/nginx nginx mailing list].
# or send a bug report, questions, or even patches to the [[#Community|OpenResty Community]].
= Source Repository =
Available on github at [http://github.com/agentzh/echo-nginx-module agentzh/echo-nginx-module].
= ChangeLog =
= Changes =
== v0.37 ==
The changes of every release of this module can be obtained from the ngx_openresty bundle's change logs:
January 13, 2012
* bugfix: data truncation might occur with [[#echo_after_body|echo_after_body]] in not-so-good networks (we should be prepared for <code>NGX_AGAIN</code> returned by downstream output filters). thanks 林青 (Kindy Lin) for reporting it.
* bugfix: we no longer check <code>sync</code> buffers for subrequests because it is incorrect.
* bugfix: fixed a bug when sending out response headers: we did not take into account the <code>NGX_ERROR</code> error code returned by <code>ngx_http_send_header</code>.
* bugfix: we did not work with HEAD http requests before.
* bugfix: now we carefully eliminate empty flush buffers in [[#echo_after_body|echo_after_body]] to work around a long-standing bug in the standard [[HttpGzipModule]].
* bugfix: we might send empty chain link in [[#echo_after_body|echo_after_body]] because it may trigger the infamous <code>"the http output chain is empty"</code> alert in <code>error.log</code> when the standard [[HttpSsiModule]] is disabled. thanks Sparsh Gupta.
* bugfix: we did not set subrequest's <code>Content-Length</code> request headers which could cause problems in the backends.
* bugfix: [[#echo_exec|echo_exec]] + named locations might cause weird issues and now we explicitly clear all the modules' contexts before calling <code>ngx_http_named_location</code>.
* bugfix: [[#echo_exec|echo_exec]] might hang when running after [[#echo_sleep|echo_sleep]] (or other I/O interruption calls): we should have called <code>ngx_http_finalize_request</code> on <code>NGX_DONE</code> to decrement <code>r->main->count</code> anyway.
* bugfix: there was a memory issue in both [[#echo_sleep|echo_sleep]] and [[#echo_blocking_sleep|echo_blocking_sleep]]: we should not pass <code>ngx_str_t</code> strings to <code>atof()</code> which expects C strings.
* bugfix: some users report that this module cannot be compiled with Nginx 1.0.x on their systems due to <code>ngx_time_update</code> (as in [https://github.com/agentzh/echo-nginx-module/issues/7 github issue #7]). this is a blind attemp to fix it because we could not reproduce it on our side.
* bugfix: fixed places in the source code that we did not check null pointers returned by the memory allocator.
== v0.36 ==
July 08, 2011
* now we back-ported the subrequest mechanism of ngx_lua to ngx_echo. this also helps some crazy test cases of mixing echo_location and echo_location_async pass now.
* now echo_location and its friends can work with ngx_xss (as well as other output filter modules) completely. thanks wd for reporting this issue.
* done some minor optimization when modifying subrequest's content-length header.
* now we always pad a trailing \0 to filepath in "echo_subrequest(_async) METHOD /path -f filepath" because ngx_open_cached_file requires a C string file name. thanks dr-dr xp.
* made our filter optimization works with nginx HUP by clearing the ngx_http_echo_filter_used flag at nginx pre-config callback. thanks Marcus Clyne.
== v0.35 ==
February 07, 2011
* added the <code>-f /path/to/file</code> option to the [[#echo_subrequest|echo_subrequest]] and [[#echo_subrequest_async|echo_subrequest_async]] directives to allow POST/PUT a disk file in the subrequest. thanks [https://github.com/dobe Bernd Dorn].
== v0.34 ==
September 14, 2010
* we no longer use the problematic <code>ngx_strXcmp</code> macros in our source because it may cause invalid reads and thus segmentation faults. thanks Piotr Sikora.
== v0.33 ==
June 08, 2010
* fixed compatibility with nginx 0.7.66+ because the ngx_time_update macro's parameter list has changed. thanks Guang Feng (蔡镜明).
== v0.32 ==
June 04, 2010
* we should have used <code>ngx_calloc_buf</code> instead of <code>ngx_alloc_buf</code> for the last chunk generated for [[#echo_after_body|echo_after_body]]. thanks valgrind's memcheck tool.
* we should initialize flags before feeding it into <code>ngx_http_parse_unsafe_uri</code>. thanks valgrind's memcheck tool.
* fixed a minor issue in the [[#echo_location|echo_location]]/[[#echo_subrequest|echo_subrequest]] implementation, which used to have race conditions.
== v0.31 ==
May 24, 2010
* the echo wev handler should not proceed if it is still waiting for some sequential subrequest or has just processed one to avoid bouncing issues.
* fixed a segfault for echo_exec for 0.7.x: we should check <code>r->done</code> before proceeding.
* no longer explicitly set <code>r->write_event_handler</code> to <code>ngx_http_request_empty_handler</code> because it's totally wrong for the state machine.
* fixed the sequential subrequest model bugs: we should ensure the <code>pr->write_event_handler</code> gets called immediately after the <code>post_subrequest</code> callback when the subrequest finalizes.
== v0.30 ==
May 06, 2010
* fixed the [[#echo_exec|echo_exec]] directive for nginx >= 0.8.11. we didn't get the <code>r->main->count</code> right in the previous version.
== v0.29 ==
May 05, 2010
* refactored the core of this module. now the implementation of [[#echo_location|echo_location]], [[#echo_subrequest|echo_subrequest]], [[#echo_sleep|echo_sleep]], and [[#echo_read_request_body|echo_read_request_body]] finally fit well with the nginx event model and Igor Sysoev's way of thinking.
== v0.28 ==
May 03, 2010
* added support for the <code>-n</code> and <code>--</code> options to the [[#echo|echo]], [[#echo_before_body|echo_before_body]], and [[#echo_after_body|echo_after_body]] directives.
== v0.27 ==
April 02, 2010
* applied the patch from Sergey A. Osokin to work with nginx 0.8.35.
== v0.26 ==
January 26, 2010
* bug fix: we should bypass upstream filters in our echo filters. an output filter should ever call <code>ngx_http_output_filter</code> nor <code>ngx_http_send_special</code>.
== v0.25 ==
January 15, 2010
* now we register a request cleanup handler to ensure our sleep event's timer will always get properly deleted even if the request is quit prematurely. this affects the echo_sleep directive.
* use ngx_null_string whenever possible in the source.
* sync'd the bundled test scaffold to Test::Nginx 0.07.
== v0.24 ==
December 28, 2009
* various source file name and coding style fixes. (the code now looks more like Igor Sysoev's.)
== v0.23 ==
December 04, 2009
* now the subrequest can read the client request body directly (for the main request) because we made subrequests inherit its parent's <code>r->header_in</code> as well. This affects the [[#echo_read_request_body|echo_read_request_body]] directive.
* fixed [[#echo_after_body|echo_after_body]] in subrequests by using a hack (checking <code>cl->buf->sync</code> for the last buf) for nginx 0.8.7+ only.
* added new varaible [[#$echo_response_status|$echo_response_status]] to help testing the status code of a subrequest. (The [[HttpMemcModule|memc]] module makes use of it.)
* use the <code>ngx_calloc_buf</code> macro to allocate new bufs in the code rather than explicit <code>ngx_pcalloc</code> calls for safety.
== v0.22 ==
November 25, 2009
* Now we allowed all the directives appear in the [[HttpRewriteModule|rewrite module]]'s [[HttpRewriteModule#if|if]] block. But so far I've only tested the [[#echo|echo]] directive.
== v0.21 ==
November 23, 2009
* Added a new directive named [[#echo_exec|echo_exec]] which does internal redirect to other (named) locations.
== v0.20 ==
November 20, 2009
* Fixed a bug in [[#echo_sleep|echo_sleep]]'s <code>r->main->count</code> handling for nginx 0.8.x. This bug will cause the server to hang when proxing a location with [[#echo_sleep|echo_sleep]].
* Applied the <code>ngx_str3cmp</code>, <code>ngx_str4cmp</code>, and <code>ngx_str6cmp</code> optimizing macros to the <code>parse_method_name</code> function, as suggested by Marcus Clyne.
* Added [[#TODO|TODO items]] regarding <code>$echo_random</code> and <code>echo_repeat</code> suggested by Marcus Clyne.
== v0.19 ==
November 19, 2009
* Fixed the CPS-style chained subrequest model for the [[#echo_location|echo_location]] and [[#echo_subrequest|echo_subrequest]] directives. they are now working perfectly and will not hang the server with the recent nginx 0.8.21 ~ 0.8.27 releases. To be specifically, the chained subrequest should call <code>ngx_http_finalize_request</code> on its parent request if the content handler of the parent request does not return <code>NGX_DONE</code>.
* Undeprecated the [[#echo_location|echo_location]] and [[#echo_subrequest|echo_subrequest]] directives.
== v0.18 ==
November 15, 2009
* Fixed the "zero size buf in output" alerts in error.log.
* Added the new directive [[#echo_request_body|echo_request_body]].
* Now we use the <code>ngx_http_parse_unsafe_uri</code> function to check the locations to [[#echo_location_async|echo_location_async]] and its friends. Thanks Arvind Jayaprakash for suggesting this fix.
* Deprecated the [[#echo_location|echo_location]] and [[#echo_subrequest|echo_subrequest]] directives.
* For HTTP 1.0 clients, use the buf length of the first chain link as the output header Content-Length.
* Implemented new variable [[#$echo_incr|$echo_incr]].
== v0.17 ==
October 26, 2009
* Added new directives [[#echo_foreach_split|echo_foreach_split]] and [[#echo_end|echo_end]]. Also introduced a "topic variable" named [[#$echo_it|$echo_it]].
* Added new variables [[#$echo_request_uri|$echo_request_uri]] and [[#$echo_cacheable_request_uri|$echo_cacheable_request_uri]].
== v0.16 ==
October 25, 2009
* Now the subrequests issued by the [[#echo_location|echo_location_async]] and [[#echo_location|echo_location]] directives no longer inherit cached variable values from its parent request. (The underlying <code>ngx_http_subrequest</code> function, however, does automatic cachable variable value inheritance.)
* Added an undocumented variable ''echo_cached_request_uri'' to help testing of this module.
== v0.15 ==
October 24, 2009
* Added new directives [[#echo_subrequest|echo_subrequest]] and [[#echo_subrequest_async|echo_subrequest_async]] for the full nginx subrequest API.
* Removed the <code>echo_client_request_headers</code> directive, and provided the [[#$echo_client_request_headers|$echo_client_request_headers]] variable instead.
* Added new variables [[#$echo_request_method|$echo_request_method]] and [[#$echo_client_request_method|$echo_client_request_method]].
== v0.14 ==
October 22, 2009
* Added new directive [[#echo_read_request_body|echo_read_request_body]] to explicitly read client request body so that the [[HttpCoreModule#$request_body]] variable will always have non-empty values.
* Now we shuffer test cases automatically in .t files and fixed bugs in the tests themselves which are hidden by config reload fallback in failure.
== v0.13 ==
October 21, 2009
* Fixed the special cases when the outputs of a [[#echo_duplicate|echo_duplicate]] directive is empty.
* Now we explicitly clear content length and accept ranges headers in the content handler.
== v0.12 ==
October 21, 2009
* Implemented the [[#echo_location|echo_location]] directive, which can issue chained GET subrequests in the Continuation Passing Style (CPS), rather than the parallel subrequest issued by the [[#echo_location_async|echo_location_async]] directive.
== v0.11 ==
October 20, 2009
* Implemented the [[#echo_duplicate|echo_duplicate]] directive to help generating large chunk of data for testing.
== v0.10 ==
October 20, 2009
* Fixed compilation regression against Nginx 0.7.21. This bug appears in version 0.09.
* Refactored the codebase by splitting source into various small files.
== v0.09 ==
October 19, 2009
* Reimplement the [[#echo_sleep|echo_sleep]] directive using per-request event and timer; the old implementation uses the global connection's read/write event to register timer, so it will break horribly when multiple subrequests "sleep" at the same time.
* Added the [[#echo_location_async|echo_location_async]] directive which can issue a GET subrequest and insert its contents herein.
== v0.08 ==
October 18, 2009
* [[#echo_sleep|echo_sleep]]: now we delete our <code>write event timer</code> in the <code>post_sleep</code> handle.
* Added <code>doc/manpage.wiki</code> which tracks changes in the [http://wiki.nginx.org/HttpEchoModule wiki page].
* Added the <code>util/wiki2pod.pl</code> script to convert <code>doc/manpage.wiki</code> to <code>README</code>.
* Disabled the <code>DDEBUG</code> macro in the C source by default.
http://openresty.org/#Changes
= Test Suite =
@ -1692,15 +1516,13 @@ You'll be very welcomed to submit patches to the [[#Author|author]] or just ask
= Author =
Zhang "agentzh" Yichun (章亦春) ''<agentzh@gmail.com>''
Yichun "agentzh" Zhang (章亦春) ''<agentzh@gmail.com>''
This wiki page is also maintained by the author himself, and everybody is encouraged to improve this page as well.
= Copyright & License =
Copyright (c) 2009, 2010, 2011, Taobao Inc., Alibaba Group ( http://www.taobao.com ).
Copyright (c) 2009, 2010, 2011, Zhang "agentzh" Yichun (章亦春) <agentzh@gmail.com>.
Copyright (c) 2009-2012, Yichun "agentzh" Zhang (章亦春) <agentzh@gmail.com>.
This module is licensed under the terms of the BSD license.

View file

@ -178,11 +178,10 @@ ngx_http_echo_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
dd("exec filter cmds for after body cmds");
rc = ngx_http_echo_exec_filter_cmds(r, ctx, conf->after_body_cmds,
&ctx->next_after_body_cmd);
&ctx->next_after_body_cmd);
if (rc == NGX_ERROR || rc > NGX_OK) {
dd("FAILED: exec filter cmds for after body cmds");
return rc;
return NGX_ERROR;
}
ctx->skip_filter = 1;
@ -197,11 +196,15 @@ ngx_http_echo_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
buf = ngx_calloc_buf(r->pool);
if (buf == NULL) {
return NGX_ERROR;
}
buf->last_buf = 1;
cl = ngx_alloc_chain_link(r->pool);
if (cl == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
return NGX_ERROR;
}
cl->next = NULL;
@ -228,16 +231,14 @@ ngx_http_echo_exec_filter_cmds(ngx_http_request_t *r,
/* evaluate arguments for the current cmd (if any) */
if (cmd->args) {
computed_args = ngx_array_create(r->pool, cmd->args->nelts,
sizeof(ngx_str_t));
sizeof(ngx_str_t));
if (computed_args == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
return NGX_ERROR;
}
opts = ngx_array_create(r->pool, 1, sizeof(ngx_str_t));
if (opts == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
return NGX_ERROR;
}
rc = ngx_http_echo_eval_cmd_args(r, cmd, computed_args, opts);

View file

@ -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;
}
@ -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 = 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;
}
return NGX_DONE;
ctx->waiting = 1;
ctx->done = 0;
}
return NGX_OK;
return NGX_DONE;
}

View file

@ -12,72 +12,55 @@
#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 = {
/* TODO we could add our own variables here... */
ngx_http_echo_handler_init, /* preconfiguration */
ngx_http_echo_filter_init, /* postconfiguration */
ngx_http_echo_handler_init, /* preconfiguration */
ngx_http_echo_filter_init, /* postconfiguration */
NULL, /* create main configuration */
NULL, /* init main configuration */
@ -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 */
};
@ -218,14 +201,21 @@ static ngx_command_t ngx_http_echo_commands[] = {
offsetof(ngx_http_echo_loc_conf_t, handler_cmds),
NULL },
{ ngx_string("echo_status"),
NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
ngx_conf_set_num_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_echo_loc_conf_t, status),
NULL },
ngx_null_command
};
ngx_module_t ngx_http_echo_module = {
NGX_MODULE_V1,
&ngx_http_echo_module_ctx, /* module context */
ngx_http_echo_commands, /* module directives */
&ngx_http_echo_module_ctx, /* module context */
ngx_http_echo_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init master */
NULL, /* init module */
@ -239,7 +229,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;
@ -256,17 +246,43 @@ ngx_http_echo_create_conf(ngx_conf_t *cf)
* conf->seen_trailing_output = 0
*/
conf->status = NGX_CONF_UNSET;
return conf;
}
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;
}
ngx_conf_merge_value(conf->status, prev->status, 200);
return NGX_CONF_OK;
}
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_http_core_loc_conf_t *clcf;
/* ngx_http_echo_loc_conf_t *elcf = conf; */
ngx_array_t **args_ptr;
ngx_http_script_compile_t sc;
ngx_str_t *raw_args;

View file

@ -82,6 +82,7 @@ typedef struct {
unsigned seen_leading_output;
ngx_int_t status;
} ngx_http_echo_loc_conf_t;

View file

@ -91,8 +91,6 @@ ngx_http_echo_send_chain_link(ngx_http_request_t* r,
ngx_http_echo_ctx_t *ctx, ngx_chain_t *in)
{
ngx_int_t rc;
size_t size;
ngx_chain_t *cl;
rc = ngx_http_echo_send_header_if_needed(r, ctx);
@ -104,30 +102,6 @@ ngx_http_echo_send_chain_link(ngx_http_request_t* r,
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
if (r->http_version < NGX_HTTP_VERSION_11 && !ctx->headers_sent) {
ctx->headers_sent = 1;
size = 0;
for (cl = in; cl; cl = cl->next) {
size += ngx_buf_size(cl->buf);
}
r->headers_out.content_length_n = (off_t) size;
if (r->headers_out.content_length) {
r->headers_out.content_length->hash = 0;
}
r->headers_out.content_length = NULL;
rc = ngx_http_send_header(r);
if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
return rc;
}
}
if (in == NULL) {
#if defined(nginx_version) && nginx_version <= 8004
@ -156,10 +130,12 @@ ngx_int_t
ngx_http_echo_send_header_if_needed(ngx_http_request_t* r,
ngx_http_echo_ctx_t *ctx)
{
/* ngx_int_t rc; */
ngx_http_echo_loc_conf_t *elcf;
if ( ! ctx->headers_sent ) {
r->headers_out.status = NGX_HTTP_OK;
if (!ctx->headers_sent) {
elcf = ngx_http_get_module_loc_conf(r, ngx_http_echo_module);
r->headers_out.status = (ngx_uint_t) elcf->status;
if (ngx_http_set_content_type(r) != NGX_OK) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
@ -168,10 +144,8 @@ ngx_http_echo_send_header_if_needed(ngx_http_request_t* r,
ngx_http_clear_content_length(r);
ngx_http_clear_accept_ranges(r);
if (r->http_version >= NGX_HTTP_VERSION_11) {
ctx->headers_sent = 1;
return ngx_http_send_header(r);
}
ctx->headers_sent = 1;
return ngx_http_send_header(r);
}
return NGX_OK;

View file

@ -90,6 +90,6 @@ elapsed 0\.0(2[6-9]|3[0-6]) sec\.$
--- request
GET /timer
--- response_body_like
^elapsed 0\.0(1[6-9]|2[0-5]) sec\.
^elapsed 0\.0(1[6-9]|2[0-9]) sec\.
elapsed 0\.0(2[6-9]|3[0-6]) sec\.$

View file

@ -302,9 +302,10 @@ helloworld
--- request
GET /main
--- response_headers
Content-Length: 6
!Content-Length
--- response_body
hello
world

View file

@ -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

142
debian/modules/nginx-echo/t/status.t vendored Normal file
View file

@ -0,0 +1,142 @@
# vi:filetype=
use lib 'lib';
use Test::Nginx::Socket;
repeat_each(1);
plan tests => repeat_each() * (2 * blocks());
#$Test::Nginx::LWP::LogLevel = 'debug';
run_tests();
__DATA__
=== TEST 1: 200
--- config
location /echo {
echo_status 200;
echo hello;
}
--- request
GET /echo
--- response_body
hello
--- error_code: 200
=== TEST 2: if location (200)
--- config
location /echo {
set $true 1;
if ($true) {
}
echo_status 200;
echo hello;
}
--- request
GET /echo
--- response_body
hello
--- error_code: 200
=== TEST 3: 404
--- config
location /echo {
echo_status 404;
echo hello;
}
--- request
GET /echo
--- response_body
hello
--- error_code: 404
=== TEST 4: if location (404)
--- config
location /echo {
set $true 1;
if ($true) {
}
echo_status 404;
echo hello;
}
--- request
GET /echo
--- response_body
hello
--- error_code: 404
=== TEST 5: 500
--- config
location /echo {
echo_status 500;
echo hello;
}
--- request
GET /echo
--- response_body
hello
--- error_code: 500
=== TEST 6: if location (500)
--- config
location /echo {
set $true 1;
if ($true) {
}
echo_status 500;
echo hello;
}
--- request
GET /echo
--- response_body
hello
--- error_code: 500
=== TEST 7: if location (500) no inherit
--- config
location /echo {
set $true 1;
if ($true) {
echo_status 503;
}
echo_status 500;
echo hello;
}
--- request
GET /echo
--- response_body
hello
--- error_code: 503
=== TEST 8: subrequest
--- config
location /echo {
echo_location /sub;
echo_status 503;
}
location /sub {
echo blah blah;
}
--- request
GET /echo
--- response_body
blah blah
--- error_code: 503

View file

@ -3,7 +3,9 @@
use lib 'lib';
use Test::Nginx::Socket;
plan tests => 2 * blocks();
repeat_each(2);
plan tests => repeat_each() * (blocks() * 2);
#$Test::Nginx::LWP::LogLevel = 'debug';

View file

@ -11,6 +11,7 @@ home=~
#--with-cc=gcc46 \
ngx-build $force $version \
--with-ld-opt="-L$PCRE_LIB -Wl,-rpath,$PCRE_LIB:$LIBDRIZZLE_LIB:$LUAJIT_LIB:/usr/local/lib" \
--with-cc-opt="-DDEBUG_MALLOC" \
--with-http_stub_status_module \
--without-mail_pop3_module \

View file

@ -1,3 +1,50 @@
{
<insert_a_suppression_name_here>
Memcheck:Leak
fun:malloc
fun:ngx_alloc
fun:(below main)
}
{
<insert_a_suppression_name_here>
Memcheck:Param
socketcall.sendmsg(msg.msg_iov[i])
fun:sendmsg
fun:ngx_write_channel
fun:ngx_signal_worker_processes
fun:ngx_master_process_cycle
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Param
socketcall.sendmsg(msg.msg_iov[i])
fun:__sendmsg_nocancel
fun:ngx_write_channel
fun:ngx_signal_worker_processes
fun:ngx_master_process_cycle
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Param
socketcall.sendmsg(msg.msg_iov[i])
fun:__sendmsg_nocancel
fun:ngx_write_channel
fun:ngx_master_process_cycle
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Param
socketcall.sendmsg(msg.msg_iov[i])
fun:__sendmsg_nocancel
fun:ngx_write_channel
fun:ngx_pass_open_channel
fun:ngx_start_worker_processes
fun:ngx_master_process_cycle
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr4