Class HttpRequest

java.lang.Object
org.jdrupes.httpcodec.protocols.http.HttpMessageHeader
org.jdrupes.httpcodec.protocols.http.HttpRequest
All Implemented Interfaces:
MessageHeader

public class HttpRequest extends HttpMessageHeader
Represents an HTTP request header.
  • Field Details

  • Constructor Details

    • HttpRequest

      public HttpRequest(String method, URI requestUri, HttpConstants.HttpProtocol httpProtocol, boolean hasPayload)
      Creates a new request with basic data.

      The host() and port() values are initialized with the values from the requestUri.

      Parameters:
      method - the method
      requestUri - the requested resource
      httpProtocol - the HTTP protocol version
      hasPayload - indicates that the message has a payload body
  • Method Details

    • setField

      public HttpRequest setField(HttpField<?> value)
      Description copied from class: HttpMessageHeader
      Sets a header field for the message.
      Overrides:
      setField in class HttpMessageHeader
      Parameters:
      value - the header field’s value
      Returns:
      the message header for easy chaining
    • setField

      public <T> HttpRequest setField(String name, T value)
      Description copied from class: HttpMessageHeader
      Sets a header field for the message.

      The converter for the field is looked up using HttpField.lookupConverter(String).

      Overrides:
      setField in class HttpMessageHeader
      Type Parameters:
      T - the type of the value
      Parameters:
      name - the field name
      value - the header field’s value
      Returns:
      the message header for easy chaining
    • setHasPayload

      public HttpRequest setHasPayload(boolean hasPayload)
      Description copied from class: HttpMessageHeader
      Set the flag that indicates whether this header is followed by a body.
      Overrides:
      setHasPayload in class HttpMessageHeader
      Parameters:
      hasPayload - new value
      Returns:
      the message for easy chaining
    • method

      public String method()
      Return the method.
      Returns:
      the method
    • requestUri

      public URI requestUri()
      Return the URI of the requested resource.
      Returns:
      the requestUri
    • setHostAndPort

      public HttpRequest setHostAndPort(String host, int port)
      Set the host and port attributes.
      Parameters:
      host - the host
      port - the port
      Returns:
      the request for easy chaining
    • host

      public String host()
      Returns:
      the host
    • port

      public int port()
      Returns:
      the port
    • setResponse

      Associates the request with a response.

      This method is invoked by the request decoder that initializes the response with basic information that can be derived from the request (e.g. by default the HTTP version is copied). The status code of the preliminary response is 501 “Not implemented”.

      Although not strictly required, users of the API are encouraged to modify this prepared request and use it when building the response.

      Parameters:
      response - the prepared response
      Returns:
      the request for easy chaining
    • response

      Returns the prepared response.
      Returns:
      the prepared response
      See Also:
    • queryData

      Returns the decoded query data from the request URI.

      The result is a lazily created (and cached) unmodifiable map.

      Parameters:
      charset - the charset to use for decoding
      Returns:
      the data
      Throws:
      UnsupportedEncodingException - the unsupported encoding exception
    • queryData

      Short for invoking queryData(Charset) with UTF-8 as charset.
      Returns:
      the map
    • toString

      public String toString()
      Overrides:
      toString in class Object