Class HttpResponse

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

public class HttpResponse extends HttpMessageHeader
Represents an HTTP response header.
  • Constructor Details

  • Method Details

    • setField

      public HttpResponse 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> HttpResponse 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 HttpResponse 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
    • statusCode

      public int statusCode()
      Returns:
      the responseCode
    • setStatusCode

      public HttpResponse setStatusCode(int statusCode)
      Parameters:
      statusCode - the responseCode to set
      Returns:
      the response for easy chaining
    • reasonPhrase

      public String reasonPhrase()
      Returns:
      the reason phrase
    • setReasonPhrase

      public HttpResponse setReasonPhrase(String reasonPhrase)
      Parameters:
      reasonPhrase - the reason phrase to set
      Returns:
      the response for easy chaining
    • setStatus

      Sets both status code and reason phrase from the given http status value.
      Parameters:
      status - the status value
      Returns:
      the response for easy chaining
    • setContentType

      Convenience method for setting the “Content-Type” header using the given media type.

      Also sets the “has payload” flag.

      Parameters:
      mediaType - the media type
      Returns:
      the response for easy chaining
    • setContentType

      public HttpResponse setContentType(String type, String subtype) throws ParseException
      Convenience method for setting the “Content-Type” header from the given values.

      Also sets the “has payload” flag.

      Parameters:
      type - the type
      subtype - the subtype
      Returns:
      the response for easy chaining
      Throws:
      ParseException - if the values cannot be parsed
    • setContentType

      public HttpResponse setContentType(String type, String subtype, String charset) throws ParseException
      A convenience method for setting the “Content-Type” header (usually of type “text”) together with its charset parameter.

      Also sets the “has payload” flag.

      Parameters:
      type - the type
      subtype - the subtype
      charset - the charset
      Returns:
      the response for easy chaining
      Throws:
      ParseException - if the values cannot be parsed
    • setContentType

      public HttpResponse setContentType(URI requestUri)
      Convenience method for setting the “Content-Type” header using the path information of the given request.

      Also sets the “has payload” flag.

      Parameters:
      requestUri - the requested resource
      Returns:
      the response for easy chaining
    • contentType

      public static MediaType contentType(URI requestUri)
      Derives a media type from the given URI.
      Parameters:
      requestUri - the uri
      Returns:
      the media type
    • setContentLength

      public HttpResponse setContentLength(long length)
      A convenience method for setting the “Content-Length” header.
      Parameters:
      length - the length
      Returns:
      the response for easy chaining
    • setRequest

      Associates the response with the request that it responds to.

      This method is invoked by the request decoder when it creates the prepared response for a request. The relationship with the request is required because information from the request headers may be needed when encoding the response.

      Parameters:
      request - the request
      Returns:
      the response for easy chaining
      See Also:
    • request

      Returns the request that this response responds to.
      Returns:
      the request
      See Also: