<!-- review: finished -->

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

# Echo

O módulo adiciona `echo`, `sleep`, `time`, `exec` e
outras funções no estilo shell.

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

## Instalação

Para [instalar](https://pt.angie.software//angie/docs/installation/index.md#install-packages) o módulo, use um dos
seguintes pacotes:

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

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

## Carregando o Módulo

Para trabalhar com o módulo, ele deve ser carregado no contexto `main{}`:

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

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

## Exemplo de Configuração

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

## Demonstração

Vamos fazer algumas requisições para demonstrar a funcionalidade do módulo.

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

As strings "hello" e "world" aparecerão com um intervalo de 2,5 segundos.

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

## Informações Adicionais

Documentação detalhada e código fonte estão disponíveis em:
[https://github.com/openresty/echo-nginx-module](https://github.com/openresty/echo-nginx-module).
