Erlang -- mod_esi

inets

Reference Manual

Version 7.4

- User's Guide
- Reference Manual
- Release Notes
- PDF
- Top

- Expand All
- Contract All

### Table of Contents

- inets
  - Top of manual page
  - service_names/0
  - services/0
  - services_info/0
  - start/0
  - start/1
  - start/2
  - start/3
  - stop/0
  - stop/2
- httpc
  - Top of manual page
  - cancel_request/1
  - cancel_request/2
  - cookie_header/1
  - cookie_header/2
  - cookie_header/3
  - get_options/1
  - get_options/2
  - info/0
  - info/1
  - request/1
  - request/2
  - request/4
  - request/5
  - reset_cookies/0
  - reset_cookies/1
  - set_options/1
  - set_options/2
  - store_cookies/2
  - store_cookies/3
  - stream_next/1
  - which_cookies/0
  - which_cookies/1
  - which_sessions/0
  - which_sessions/1
- httpd
  - Top of manual page
  - info/1
  - info/2
  - info/2
  - info/3
  - info/4
  - info/3
  - parse_query/1
  - reload_config/2
  - Module:do/1
  - Module:remove/1
  - Module:store/2
- httpd_custom_api
  - Top of manual page
  - request_header/1
  - response_default_headers/0
  - response_header/1
- httpd_socket
  - Top of manual page
  - deliver/3
  - peername/2
  - resolve/0
- httpd_util
  - Top of manual page
  - convert_request_date/1
  - create_etag/1
  - day/1
  - decode_hex/1
  - flatlength/1
  - hexlist_to_integer/1
  - integer_to_hexlist/1
  - lookup/2
  - lookup/3
  - lookup_mime/2
  - lookup_mime/3
  - lookup_mime_default/2
  - lookup_mime_default/3
  - message/3
  - month/1
  - multi_lookup/2
  - reason_phrase/1
  - rfc1123_date/0
  - rfc1123_date/1
  - split/3
  - split_path/1
  - split_script_path/1
  - strip/1
  - suffix/1
- mod_alias
  - Top of manual page
  - default_index/2
  - path/3
  - real_name/3
  - real_script_name/3
- mod_auth
  - Top of manual page
  - add_group_member/3
  - add_group_member/4
  - add_group_member/5
  - add_user/2
  - add_user/5
  - add_user/6
  - delete_group/2
  - delete_group/4
  - delete_group_member/3
  - delete_group_member/4
  - delete_group_member/5
  - delete_user/2
  - delete_user/3
  - delete_user/4
  - get_user/2
  - get_user/3
  - get_user/4
  - list_group_members/2
  - list_group_members/3
  - list_group_members/4
  - list_groups/1
  - list_groups/2
  - list_groups/3
  - list_users/1
  - list_users/2
  - list_users/3
  - update_password/5
  - update_password/6
- mod_esi
  - Top of manual page
  - deliver/2
  - Module:Function/3
  - Module:Function/2
- mod_security
  - Top of manual page
  - block_user/4
  - block_user/5
  - list_auth_users/1
  - list_auth_users/2
  - list_auth_users/2
  - list_auth_users/3
  - list_blocked_users/1
  - list_blocked_users/2
  - list_blocked_users/2
  - list_blocked_users/3
  - unblock_user/2
  - unblock_user/3
  - unblock_user/3
  - unblock_user/4
  - Module:event/4
  - Module:event/5
- http_uri
  - Top of manual page
  - decode/1
  - encode/1
  - parse/1
  - parse/2
  - scheme_defaults/0

# mod_esi

### Module

mod_esi

### Module Summary

Erlang Server Interface

### Description

This module defines the Erlang Server Interface (ESI) API. It is a more efficient way of writing Erlang scripts for your Inets web server than writing them as common CGI scripts.

### DATA TYPES

The following data types are used in the functions for mod_esi:

env() =

  {EnvKey()::atom(), Value::term()}

  Currently supported key value pairs

  {server_software, string()}

    Indicates the inets version.

  {server_name, string()}

    The local hostname.

  {gateway_interface, string()}

    Legacy string used in CGI, just ignore.

  {server_protocol, string()}

    HTTP version, currently "HTTP/1.1"

  {server_port, integer()}

    Servers port number.

  {request_method, "GET | "PUT" | "DELETE" | "POST" | "PATCH"}

    HTTP request method.

  {remote_adress, inet:ip_address()}

    The clients ip address.

  {peer_cert, undefined | no_peercert | DER:binary()}

    For TLS connections where client certificates are used this will be an ASN.1 DER-encoded X509-certificate as an Erlang binary. If client certificates are not used the value will be no_peercert, and if TLS is not used (HTTP or connection is lost due to network failure) the value will be undefined.

  {script_name, string()}

    Request URI

  {http_LowerCaseHTTPHeaderName, string()}

    example: {http_content_type, "text/html"}

### Exports

deliver(SessionID, Data) -> ok | {error, Reason} |

### Types

SessionID = term()
Data = string() | io_list() | binary()
Reason = term()

This function is only intended to be used from functions called by the Erl Scheme interface to deliver parts of the content to the user.

Sends data from an Erl Scheme script back to the client.

Note

If any HTTP header fields are added by the script, they must be in the first call to deliver/2, and the data in the call must be a string. Calls after the headers are complete can contain binary data to reduce copying overhead. Do not assume anything about the data type of SessionID. SessionID must be the value given as input to the ESI callback function that you implemented.

### ESI Callback Functions

### Exports

Module:Function(SessionID, Env, Input)-> {continue, State} | _ |

### Types

SessionID = term()
Env = env()
Input = string() | chunked_data()
chunked_data() = {first, Data::binary()} | {continue, Data::binary(), State::term()} | {last, Data::binary(), State::term()}
State = term()

Module must be found in the code path and export Function with an arity of three. An erlScriptAlias must also be set up in the configuration file for the web server.

mod_esi:deliver/2 shall be used to generate the response to the client and SessionID is an identifier that shall by used when calling this function, do not assume anything about the datatype. This function may be called several times to chunk the response data. Notice that the first chunk of data sent to the client must at least contain all HTTP header fields that the response will generate. If the first chunk does not contain the end of HTTP header, that is, "\r\n\r\n", the server assumes that no HTTP header fields will be generated.

Env environment data of the request see description above.

Input is query data of a GET request or the body of a PUT or POST request. The default behavior (legacy reasons) for delivering the body, is that the whole body is gathered and converted to a string. But if the httpd config parameter max_client_body_chunk is set, the body will be delivered as binary chunks instead. The maximum size of the chunks is either max_client_body_chunk or decide by the client if it uses HTTP chunked encoding to send the body. When using the chunking mechanism this callback must return {continue, State::term()} for all calls where Input is {first, Data::binary()} or {continue, Data::binary(), State::term()}. When Input is {last, Data::binary(), State::term()} the return value will be ignored.

Note

Note that if the body is small all data may be delivered in only one chunk and then the callback will be called with {last, Data::binary(), undefined} without getting called with {first, Data::binary()}.

The input State is the last returned State, in it the callback can include any data that it needs to keep track of when handling the chunks.

Module:Function(Env, Input)-> Response |

### Types

Env = env()
Input = string()
Response = string()

This callback format consumes much memory, as the whole response must be generated before it is sent to the user. This callback format is deprecated. For new development, use Module:Function/3.