<!-- review: finished -->

<a id="external-echo"></a>

# Echo

The module adds `echo`, `sleep`, `time`, `exec`, and
other shell-style functions.

<a id="installation-8"></a>

## Installation

To [install](https://en.angie.software//angie/docs/installation/index.md#install-packages) the module, use one of the
following packages:

- Angie: `angie-module-echo`
- Angie PRO: `angie-pro-module-echo`

<a id="loading-the-module-8"></a>

## Loading the Module

To work with the module, it must be loaded in the `main{}` context:

```nginx
load_module modules/ngx_http_echo_module.so;
```

<a id="configuration-example-85"></a>

## Configuration Example

```nginx
server {
    listen       80;
    server_name  localhost;

    location /echo {
        echo_before_body 'These lines are inserted';
        echo_before_body 'by the echo_before_body directive';
        echo_after_body 'These lines are added';
        echo_after_body 'by the echo_after_body directive';
        proxy_pass $scheme://127.0.0.1:$server_port$request_uri/more;
    }

    location /echo/more {
        set $val 'value';
        echo '======== Start backend answer =========';
        echo 'Backend answer body';
        echo "val is set on $val";
        echo '======== End backend answer ===========';
    }

    location /echo_with_sleep {
        echo hello;
        echo_flush;
        echo_sleep   2.5;
        echo world;
    }

    location /dup {
        echo_duplicate 3 "--";
        echo_duplicate 1 " END ";
        echo_duplicate 3 "--";
        echo;
    }

    location /subr {
        echo_reset_timer;
        echo_location /sub1;
        echo_location /sub2;
        echo "took $echo_timer_elapsed sec for total.";
    }

    location /subr_async {
        echo_reset_timer;
        echo_location_async /sub1;
        echo_location_async /sub2;
        echo "took $echo_timer_elapsed sec for total.";
    }

    location /sub1 {
        echo_sleep 2;
        echo hello;
    }

    location /sub2 {
        echo_sleep 1;
        echo world;
    }
}
```

<a id="demonstration"></a>

## Demonstration

Let's make a few requests to demonstrate the module's functionality.

```console
$ curl localhost/echo

  These lines are inserted
  by the echo_before_body directive
  ======== Start backend answer =========
  Backend answer body
  val is set on value
  ======== End backend answer ==========
  These lines are added
  by the echo_after_body directive
```

```console
$ curl localhost/echo_with_sleep

  hello
  world
```

The strings "hello" and "world" will appear with an interval of 2.5 seconds.

```console
$ curl localhost/dup
------ END ------
```

```console
$ time curl localhost/subr

  hello
  world
  took 3.004 sec for total.

  real    0m3.027s
  user    0m0.015s
  sys     0m0.007s
```

```console
$ time curl localhost/subr_async

  hello
  world
  took 0.000 sec for total.

  real    0m2.023s
  user    0m0.001s
  sys     0m0.020s
```

<a id="additional-information-9"></a>

## Additional Information

Detailed documentation and source code are available at:
[https://github.com/openresty/echo-nginx-module](https://github.com/openresty/echo-nginx-module).
