Interface HTTPResponder

All Known Subinterfaces:
HTTPServer

public interface HTTPResponder
A HTTPResponder is used for responding to HTTPRequests given a response and body.
Since:
1.2.1
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final byte[]
    A byte array with length zero.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    respond(HTTPRequest request, int status, byte[] data, String... headers)
    Responds to the given request with a new HTTP response with the given status, data and headers, if the request has not already received a response.
    void
    respond(HTTPRequest request, HTTPResponseData response)
    Responds to the given request with the given response, if the request has not already received a response.
  • Field Details

    • EMPTY_BYTE_ARRAY

      static final byte[] EMPTY_BYTE_ARRAY
      A byte array with length zero.
      Since:
      1.4.1
  • Method Details

    • respond

      void respond(HTTPRequest request, HTTPResponseData response)
      Responds to the given request with the given response, if the request has not already received a response.

      A responder may set additional, edit, or delete any headers in the HTTP response.

      Parameters:
      request - The request to respond to
      response - The response
      See Also:
    • respond

      void respond(HTTPRequest request, int status, byte[] data, String... headers)
      Responds to the given request with a new HTTP response with the given status, data and headers, if the request has not already received a response.

      In the headers array, each value at an even index (starting at 0) is a header key (name), followed by the values at odd indices. If the array length is not a multiple of 2, the last element is ignored. For example, an array like {"x-example", "123", "x-another-header", "value here"} will set two headers in the response with names "x-example" and "x-another-header" and values "123" and "value here", respectively.

      A responder may set additional, edit, or delete any headers in the HTTP response.

      Parameters:
      request - The request to respond to
      status - The status code of the response
      data - The data to send in the response
      headers - Headers to send in the response. See explanation in description
      See Also: