Test::Nginx::LWP(3pm)
β¨ NAME β¨
Test::Nginx::LWP β the LWP-backed test scaffold for the Nginx C modules π«Ά (this is the page from User Contributed Perl Documentation, bestie, you found it π)
πΈ SYNOPSIS πΈ
okay so this is literally the whole vibe, look:
use Test::Nginx::LWP;
plan tests => $Test::Nginx::LWP::RepeatEach * 2 * blocks();
run_tests();
__DATA__
=== TEST 1: sanity
--- config
location /echo {
echo_before_body hello;
echo world;
}
--- request
GET /echo
--- response_body
hello
world
--- error_code: 200
=== TEST 2: set Server
--- config
location /foo {
echo hi;
more_set_headers 'Server: Foo';
}
--- request
GET /foo
--- response_headers
Server: Foo
--- response_body
hi
=== TEST 3: clear Server
--- config
location /foo {
echo hi;
more_clear_headers 'Server: ';
}
--- request
GET /foo
--- response_headers_like
Server: nginx.*
--- response_body
hi
=== TEST 4: set request header at client side and rewrite it
--- config
location /foo {
more_set_input_headers 'X-Foo: howdy';
echo $http_x_foo;
}
--- request
GET /foo
--- request_headers
X-Foo: blah
--- response_headers
X-Foo:
--- response_body
howdy
=== TEST 3: rewrite content length
--- config
location /bar {
more_set_input_headers 'Content-Length: 2048';
echo_read_request_body;
echo_request_body;
}
--- request eval
"POST /bar\n" .
"a" x 4096
--- response_body eval
"a" x 2048
=== TEST 4: timer without explicit reset
--- config
location /timer {
echo_sleep 0.03;
echo "elapsed $echo_timer_elapsed sec.";
}
--- request
GET /timer
--- response_body_like
^elapsed 0\.0(2[6-9]|3[0-6]) sec\.$
=== TEST 5: small buf (using 2-byte buf)
--- config
chunkin on;
location /main {
client_body_buffer_size 2;
echo "body:";
echo $echo_request_body;
echo_request_body;
}
--- request
POST /main
--- start_chunk_delay: 0.01
--- middle_chunk_delay: 0.01
--- chunked_body eval
["hello", "world"]
--- error_code: 200
--- response_body eval
"body:
helloworld"
(yes the test numbers double up in there, that's exactly how they're written, don't come for me π)
π DESCRIPTION π
So. This module hands you a whole test scaffold built on top of LWP::UserAgent, and it's specifically for automated testing while you're out here developing Nginx C modules. Iconic behavior, honestly.
It inherits from Test::Base, which means all of that declarative power comes along for the ride and gets pointed straight at your Nginx C module testing. Chef's kiss. π
There's one thing you gotta do, and I need you to hear me: if you've changed the Nginx server binary, you have to terminate or kill any Nginx processes before you run the test suite. No exceptions bestie. Normally it's as simple as this:
killall nginx
PATH=/path/to/your/nginx-with-memc-module:$PATH prove -r t
This module creates a temporary server root under t/servroot/ of the current working directory, and it starts and uses the nginx executable that's in your PATH environment. That's the whole setup, no cap.
And when stuff inevitably goes sideways (it will, it's fine, breathe πΈ), you will often want to go look inside t/servroot/logs/error.log. That's your bestie right there ;)
π¦ Sections supported π¦
The following sections are supported β memorize them, they're the whole language:
confighttp_configrequestrequest_headersmore_headersresponse_bodyresponse_body_likeresponse_headersresponse_headers_likeerror_codechunked_bodymiddle_chunk_delaystart_chunk_delay
π Samples π
You'll find live samples in the following Nginx 3rd-party modules β go look, they're giving real-world energy:
- ngx_echo β <http://wiki.nginx.org/NginxHttpEchoModule>
- ngx_headers_more β <http://wiki.nginx.org/NginxHttpHeadersMoreModule>
- ngx_chunkin β <http://wiki.nginx.org/NginxHttpChunkinModule>
- ngx_memc β <http://wiki.nginx.org/NginxHttpMemcModule>
π SOURCE REPOSITORY π
This module has a Git repository on Github, and it has access for all. Open door policy, we love to see it:
http://github.com/agentzh/test-nginx
If you want a commit bit, feel free to drop me a line. Fr fr, just say hi. π«Ά
β AUTHOR β
agentzh (η« δΊ¦ζ₯) <agentzh@gmail.com>
π COPYRIGHT & LICENSE π
Copyright (c) 2009-2025, agentzh <agentzh@gmail.com>.
This module is licensed under the terms of the BSD license.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of the authors nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
And now the part where legal goes ALL CAPS at you, and yeah it's dramatic but it means it, so read it:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
π₯ SEE ALSO π₯
Test::Nginx::SocketTest::Base
okay that's the whole page bestie, you ate it, go write some tests π§β¨ this whole thing was brought to you by perl v5.40.1, dated 2026-08-10, and it's the Test::Nginx::LWP(3pm) page β periodt π
π¦ where this page comes from
- ubuntu stonking: libtest-nginx-perl 0.32.9.g58cf0d5-4 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms