http-echo #

Brings "echo", "sleep", "time", "exec" and other shell-style helpers into the nginx config language — handy for quick endpoints, test rigs and concatenating subrequests.

Source: upstream source

Directives

echo #

syntax: echo any args;  ·  context: location, location-if

Name ==== ngx_echo - Brings "echo", "sleep", "time", "exec" and more shell-style goodies to Nginx config file. This module is not distributed with the Nginx source. See the installation instructions.

echo_abort_parent #

syntax: echo_abort_parent no args;  ·  context: location, location-if

Aborts the parent request of the current subrequest, terminating it immediately with the given status.

echo_after_body #

syntax: echo_after_body any args;  ·  context: location, location-if

Appends the specified output to the end of the original response body generated by the underlying content handler.

echo_before_body #

syntax: echo_before_body any args;  ·  context: location, location-if

Prepends the specified output to the beginning of the original response body generated by the underlying content handler.

echo_blocking_sleep #

syntax: echo_blocking_sleep 1 arg;  ·  context: location, location-if

This operation is non-blocking on server side, so unlike the echo_blocking_sleep directive, it won't block the whole Nginx worker process.

echo_duplicate #

syntax: echo_duplicate 2+ args;  ·  context: location, location-if

Outputs a duplication of the given string a specified number of times, without appending a trailing newline.

echo_end #

syntax: echo_end no args;  ·  context: location, location-if

For instance: Accessing /main yields As seen in the previous example, this directive should always be accompanied by an echo_end directive.

echo_exec #

syntax: echo_exec 1 arg;  ·  context: location, location-if

See also echo_read_request_body and the chunkin module. Back to TOC echo_exec --------- syntax: echo_exec <location> [<query_string>] syntax: echo_exec <named_location> default: no context: location, location if phase: content Does an internal redirect to the location specified.

echo_flush #

syntax: echo_flush no args;  ·  context: location, location-if

To force the output data flushed immediately, use the echo_flush command just after echo, as in When no argument is specified, echo emits the trailing newline alone, just like the echo command in shell.

echo_foreach_split #

syntax: echo_foreach_split 2+ args;  ·  context: location, location-if

This directive was first introduced in the release v0.15. Back to TOC echo_foreach_split ------------------ syntax: echo_foreach_split <delimiter> <string> default: no context: location, location if phase: content Split the second argument string using the delimiter specified in the first argument, and then iterate through the resulting items.

echo_location #

syntax: echo_location 1 arg;  ·  context: location, location-if

The same is true for its brother, the echo_location directive.

echo_location_async #

syntax: echo_location_async 1 arg;  ·  context: location, location-if

The outputs of /main that are sent after echo_location_async will be postponed and buffered firmly.

echo_read_request_body #

syntax: echo_read_request_body no args;  ·  context: location, location-if

See also echo_read_request_body and the chunkin module. Back to TOC echo_exec --------- syntax: echo_exec <location> [<query_string>] syntax: echo_exec <named_location> default: no context: location, location if phase: content Does an internal redirect to the location specified.

echo_request_body #

syntax: echo_request_body no args;  ·  context: location, location-if

This directive was first introduced in the release v0.17. Back to TOC echo_request_body ----------------- syntax: echo_request_body default: no context: location, location if phase: content Outputs the contents of the request body previous read.

echo_reset_timer #

syntax: echo_reset_timer no args;  ·  context: location, location-if

Resets the elapsed-time timer's begin time to the moment this command executes during the request.

echo_sleep #

syntax: echo_sleep 1 arg;  ·  context: location, location-if

See also echo, echo_sleep, and echo_location_async. Back to TOC echo_sleep ---------- syntax: echo_sleep <seconds> default: no context: location, location if phase: content Sleeps for the time period specified by the argument, which is in seconds.

echo_status #

syntax: echo_status 1 arg (integer);  ·  context: location, location-if

This directive was first introduced in the v0.21 release. Back to TOC echo_status ----------- syntax: echo_status <status-num> default: echo_status 200 context: location, location if phase: content Specify the default response status code.

echo_subrequest #

syntax: echo_subrequest 2+ args;  ·  context: location, location-if

Here's the result in action on my machine: This directive is logically equivalent to the GET version of echo_subrequest.

echo_subrequest_async #

syntax: echo_subrequest_async 2+ args;  ·  context: location, location-if

This directive is logically equivalent to the GET version of echo_subrequest_async.

Example

    location /abort {
        echo hello;
        echo_flush;
        echo_location_async '/foo';
        echo_location_async '/bar';
        echo_location_async '/baz';
        echo world;
        echo_flush;
    }

    location /proxy {
        proxy_pass "http://127.0.0.1:$server_port/sleep?$query_string";
    }

    location /sleep {
        echo_sleep $arg_sleep;
        echo $arg_echo;
        echo_flush;
    }

    location /foo {
        echo_location '/proxy?sleep=1&echo=foo';
        #echo_flush;
        echo_abort_parent;
    }

    location /bar {
        proxy_pass 'http://127.0.0.1:$server_port/sleep_bar';
    }

    location /baz {
        proxy_pass 'http://127.0.0.1:$server_port/sleep_baz';
    }

    location /sleep_bar {
        echo_sleep 2;
        echo bar;
    }

    location /sleep_baz {
        echo_sleep 3;
        echo baz;
    }

↑ back to index