Class HttpResponse

java.lang.Object
com.yahoo.container.jdisc.HttpResponse
Direct Known Subclasses:
AsyncHttpResponse, ByteArrayResponse, EmptyResponse, JacksonJsonResponse, JsonResponse, SlimeJsonResponse

public abstract class HttpResponse extends Object
An HTTP response as an opaque payload with headers and content type.
Author:
hmusum, Steinar Knutsen
  • Field Details

    • DEFAULT_MIME_TYPE

      public static final String DEFAULT_MIME_TYPE
      Default response content type; text/plain.
      See Also:
    • DEFAULT_CHARACTER_ENCODING

      public static final String DEFAULT_CHARACTER_ENCODING
      Default encoding/character set of a HTTP response; UTF-8.
      See Also:
  • Constructor Details

    • HttpResponse

      public HttpResponse(int status)
      Creates a new HTTP response
      Parameters:
      status - the HTTP status code to return with this response (may be changed later)
      See Also:
      • Response
  • Method Details

    • render

      public abstract void render(OutputStream outputStream) throws IOException
      Marshals this response to the network layer. The caller is responsible for flushing and closing outputStream.
      Throws:
      IOException
    • maxPendingBytes

      public long maxPendingBytes()
      The amount of content bytes this response may have in-flight (if positive) before response rendering blocks.
    • getStatus

      public int getStatus()
      Returns the numeric HTTP status code, e.g. 200, 404 and so on.
      Returns:
      the numeric HTTP status code
    • setStatus

      public void setStatus(int status)
      Sets the numeric HTTP status code this will return.
    • headers

      public com.yahoo.jdisc.HeaderFields headers()
      The response headers.
      Returns:
      a mutable, thread-unsafe view of the response headers
    • getJdiscResponse

      public com.yahoo.jdisc.Response getJdiscResponse()
      The underlying JDisc response.
      Returns:
      the actual response which will be used by the JDisc layer
    • getContentType

      public String getContentType()
      The MIME type of the response contents or null. If null is returned, no content type header is added to the HTTP response.
      Returns:
      by default DEFAULT_MIME_TYPE
    • getCharacterEncoding

      public String getCharacterEncoding()
      The name of the encoding for the response contents, if applicable. Return null if character set is not applicable to the response in question (e.g. binary formats). If null is returned, not "charset" element is added to the content type header.
      Returns:
      by default DEFAULT_CHARACTER_ENCODING
    • populateAccessLogEntry

      public void populateAccessLogEntry(AccessLogEntry accessLogEntry)
      Override this method to add information from the response to the access log. Remember to also invoke super if you override it.
      Parameters:
      accessLogEntry - the access log entry to add information to.
    • complete

      public void complete()
      Complete creation of this response. This is called by the container once just before writing the response header back to the caller, so this is the last moment at which status and headers can be determined. This default implementation does nothing.
    • getLogValues

      public Iterable<Execution.Trace.LogValue> getLogValues()
    • setRequestType

      public void setRequestType(com.yahoo.jdisc.Request.RequestType requestType)
      Sets the type classification of this request for metric collection purposes
    • getRequestType

      public com.yahoo.jdisc.Request.RequestType getRequestType()
      Returns the type classification of this request for metric collection purposes, or null if not set. When not set, the request type will be "read" for GET requests and "write" for other request methods.