Module jls.net.http.HttpFilter

HTTP filter class.

A filter allows to process an HTTP exchange prior to call the handler. It can be used for tasks such as authentication, access control, logging.

Class HttpFilter

HttpFilter:new ([fn]) Creates an HTTP filter.
httpFilter:doFilter (exchange) Filters the specified exchange.
httpFilter:close () Closes this filter.
HttpFilter.filter (exchange, filters) Applies the specified filters in the specified order.
HttpFilter.multiple (...) Returns a filter applying all the specified filters.
HttpFilter.basicAuth (credentials[, realm]) Creates a basic authentication filter.
HttpFilter.session ([maxAge[, idleTimeout]]) Returns a session filter.
HttpFilter.byPath (filter[, patterns[, excludedPatterns]]) Returns a filter by path.


Class HttpFilter

A HttpFilter class.
HttpFilter:new ([fn])
Creates an HTTP filter.

Parameters:

  • fn function a function that will be call to filter the HTTP exchange (optional)
httpFilter:doFilter (exchange)
Filters the specified exchange. Called when the request headers have been received.

Parameters:

  • exchange HttpExchange the HTTP exchange to filter

Returns:

    boolean false to indicate the request must not handled.
httpFilter:close ()
Closes this filter. Do nothing by default. Must support to be called multiple times.
HttpFilter.filter (exchange, filters)
Applies the specified filters in the specified order.

Parameters:

  • exchange HttpExchange the HTTP exchange to filter
  • filters table the filters.

Returns:

    boolean false to indicate the request must not handled.
HttpFilter.multiple (...)
Returns a filter applying all the specified filters.

Parameters:

  • ... the filters.

Returns:

    HttpFilter a HttpFilter.
HttpFilter.basicAuth (credentials[, realm])
Creates a basic authentication filter.

Parameters:

  • credentials a table with user name and password pairs or a function. The function receives the user and the password and return true when they match an existing credential.
  • realm string an optional message. (optional)

Returns:

    HttpFilter a HttpFilter.
HttpFilter.session ([maxAge[, idleTimeout]])
Returns a session filter. This filter adds a session id cookie to the response and maintain the exchange session.

Parameters:

  • maxAge number the session max age in seconds, default to 12 hours. (optional)
  • idleTimeout number the session idle timeout in seconds, default to maxAge. (optional)

Returns:

    HttpFilter a HttpFilter.
HttpFilter.byPath (filter[, patterns[, excludedPatterns]])
Returns a filter by path. This filter allows to restrict a filter to a set of allowed or excluded path patterns.

Parameters:

  • filter HttpFilter the filter to apply depending on the allowed/excluded patterns.
  • patterns table a list of allowed patterns. (optional)
  • excludedPatterns table a list of excluded patterns. (optional)

Returns:

    HttpFilter a HttpFilter.
generated by LDoc 1.4.6