Package com.yahoo.container.jdisc
Class HttpResponse
- java.lang.Object
-
- com.yahoo.container.jdisc.HttpResponse
-
- Direct Known Subclasses:
AsyncHttpResponse
,EmptyResponse
public abstract class HttpResponse extends java.lang.Object
An HTTP response as an opaque payload with headers and content type.- Author:
- hmusum, Steinar Knutsen
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_CHARACTER_ENCODING
Default encoding/character set of a HTTP response; UTF-8.static java.lang.String
DEFAULT_MIME_TYPE
Default response content type; text/plain.
-
Constructor Summary
Constructors Constructor Description HttpResponse(int status)
Creates a new HTTP response
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
complete()
Complete creation of this response.java.lang.String
getCharacterEncoding()
The name of the encoding for the response contents, if applicable.java.lang.String
getContentType()
The MIME type of the response contents or null.com.yahoo.jdisc.Response
getJdiscResponse()
The underlying JDisc response.java.lang.Iterable<com.yahoo.processing.execution.Execution.Trace.LogValue>
getLogValues()
com.yahoo.jdisc.Request.RequestType
getRequestType()
Returns the type classification of this request for metric collection purposes, or null if not set.int
getStatus()
Returns the numeric HTTP status code, e.g.com.yahoo.jdisc.HeaderFields
headers()
The response headers.void
populateAccessLogEntry(com.yahoo.container.logging.AccessLogEntry accessLogEntry)
Override this method to add information from the response to the access log.abstract void
render(java.io.OutputStream outputStream)
Marshals this response to the network layer.void
setRequestType(com.yahoo.jdisc.Request.RequestType requestType)
Sets the type classification of this request for metric collection purposesvoid
setStatus(int status)
Sets the numeric HTTP status code this will return.
-
-
-
Field Detail
-
DEFAULT_MIME_TYPE
public static final java.lang.String DEFAULT_MIME_TYPE
Default response content type; text/plain.- See Also:
- Constant Field Values
-
DEFAULT_CHARACTER_ENCODING
public static final java.lang.String DEFAULT_CHARACTER_ENCODING
Default encoding/character set of a HTTP response; UTF-8.- See Also:
- Constant Field Values
-
-
Method Detail
-
render
public abstract void render(java.io.OutputStream outputStream) throws java.io.IOException
Marshals this response to the network layer. The caller is responsible for flushing and closing outputStream.- Throws:
java.io.IOException
-
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 java.lang.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 java.lang.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(com.yahoo.container.logging.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 java.lang.Iterable<com.yahoo.processing.execution.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.
-
-