Package org.eclipse.jetty.server
Class Response
java.lang.Object
org.eclipse.jetty.server.Response
- All Implemented Interfaces:
javax.servlet.http.HttpServletResponse
,javax.servlet.ServletResponse
Response
provides the implementation for HttpServletResponse
.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enum
static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final HttpField
private static final EnumSet<Response.EncodingFrom>
private static final EnumSet<Response.EncodingFrom>
private static final int
private final HttpChannel
private String
private long
private String
private Response.EncodingFrom
private final AtomicBiInteger
private final HttpFields
private Locale
private MimeTypes.Type
private final HttpOutput
private Response.OutputType
private String
private int
private Supplier<HttpFields>
private ResponseWriter
private static final Logger
static final int
static final String
If a header name starts with this string, the header (stripped of the prefix) can be set during include using onlysetHeader(String, String)
oraddHeader(String, String)
.static final int
Fields inherited from interface javax.servlet.http.HttpServletResponse
SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CONFLICT, SC_CONTINUE, SC_CREATED, SC_EXPECTATION_FAILED, SC_FORBIDDEN, SC_FOUND, SC_GATEWAY_TIMEOUT, SC_GONE, SC_HTTP_VERSION_NOT_SUPPORTED, SC_INTERNAL_SERVER_ERROR, SC_LENGTH_REQUIRED, SC_METHOD_NOT_ALLOWED, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_MULTIPLE_CHOICES, SC_NO_CONTENT, SC_NON_AUTHORITATIVE_INFORMATION, SC_NOT_ACCEPTABLE, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_PARTIAL_CONTENT, SC_PAYMENT_REQUIRED, SC_PRECONDITION_FAILED, SC_PROXY_AUTHENTICATION_REQUIRED, SC_REQUEST_ENTITY_TOO_LARGE, SC_REQUEST_TIMEOUT, SC_REQUEST_URI_TOO_LONG, SC_REQUESTED_RANGE_NOT_SATISFIABLE, SC_RESET_CONTENT, SC_SEE_OTHER, SC_SERVICE_UNAVAILABLE, SC_SWITCHING_PROTOCOLS, SC_TEMPORARY_REDIRECT, SC_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE, SC_USE_PROXY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCookie
(javax.servlet.http.Cookie cookie) void
addCookie
(HttpCookie cookie) void
addDateHeader
(String name, long date) void
void
addIntHeader
(String name, int value) private HttpCookie
checkSameSite
(HttpCookie cookie) Check that samesite is set on the cookie.void
void
Deprecated.void
completeOutput
(Callback callback) boolean
containsHeader
(String name) encodeRedirectUrl
(String url) Deprecated.encodeRedirectURL
(String url) Deprecated.void
void
int
Get the MetaData.Response committed for this response.long
long
getHeaders
(String name) long
javax.servlet.ServletOutputStream
int
void
include()
void
included()
boolean
isAllContentWritten
(long written) boolean
boolean
isContentComplete
(long written) boolean
private boolean
boolean
boolean
boolean
protected MetaData.Response
static void
putHeaders
(javax.servlet.http.HttpServletResponse response, HttpContent content, long contentLength, boolean etag) void
putHeaders
(HttpContent content, long contentLength, boolean etag) protected void
recycle()
void
reopen()
void
replaceCookie
(HttpCookie cookie) Replace (or add) a cookie.void
reset()
void
void
void
void
sendError
(int sc) void
Send an error response.void
Sends a 102-Processing response.void
sendRedirect
(int code, String location) Sends a response with one of the 300 series redirection codes.void
sendRedirect
(int code, String location, boolean consumeAll) Sends a response with a given redirection code.void
sendRedirect
(String location) void
sendRedirect
(String location, boolean consumeAll) Sends a response with a HTTP version appropriate 30x redirection.void
setBufferSize
(int size) void
setCharacterEncoding
(String encoding) private void
setCharacterEncoding
(String encoding, Response.EncodingFrom from) void
setContentLength
(int len) void
setContentLengthLong
(long length) void
setContentType
(String contentType) void
setDateHeader
(String name, long date) private void
setErrorSent
(boolean errorSent) void
void
setHeader
(HttpHeader name, String value) void
setIntHeader
(String name, int value) void
void
setLongContentLength
(long len) void
setStatus
(int sc) void
Deprecated.void
setStatusWithReason
(int sc, String sm) void
setTrailers
(Supplier<HttpFields> trailers) toString()
static javax.servlet.http.HttpServletResponse
unwrap
(javax.servlet.ServletResponse servletResponse) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface javax.servlet.http.HttpServletResponse
getTrailerFields, setTrailerFields
-
Field Details
-
LOG
-
__MIN_BUFFER_SIZE
private static final int __MIN_BUFFER_SIZE- See Also:
-
__EXPIRES_01JAN1970
-
NO_CONTENT_LENGTH
public static final int NO_CONTENT_LENGTH- See Also:
-
USE_KNOWN_CONTENT_LENGTH
public static final int USE_KNOWN_CONTENT_LENGTH- See Also:
-
SET_INCLUDE_HEADER_PREFIX
If a header name starts with this string, the header (stripped of the prefix) can be set during include using onlysetHeader(String, String)
oraddHeader(String, String)
.- See Also:
-
_channel
-
_fields
-
_errorSentAndIncludes
-
_out
-
_status
private int _status -
_reason
-
_locale
-
_mimeType
-
_characterEncoding
-
_encodingFrom
-
_contentType
-
_outputType
-
_writer
-
_contentLength
private long _contentLength -
_trailers
-
__localeOverride
-
__explicitCharset
-
-
Constructor Details
-
Response
-
-
Method Details
-
getHttpChannel
-
recycle
protected void recycle() -
getHttpOutput
-
reopen
public void reopen() -
errorClose
public void errorClose() -
isMutable
private boolean isMutable()- Returns:
- true if the response is mutable, ie not errorSent and not included
-
setErrorSent
private void setErrorSent(boolean errorSent) -
isIncluding
public boolean isIncluding() -
include
public void include() -
included
public void included() -
addCookie
-
checkSameSite
Check that samesite is set on the cookie. If not, use a context default value, if one has been set.- Parameters:
cookie
- the cookie to check- Returns:
- either the original cookie, or a new one that has the samesit default set
-
replaceCookie
Replace (or add) a cookie. Using name, path and domain, look for a matching set-cookie header and replace it.- Parameters:
cookie
- The cookie to add/replace
-
addCookie
public void addCookie(javax.servlet.http.Cookie cookie) - Specified by:
addCookie
in interfacejavax.servlet.http.HttpServletResponse
-
containsHeader
- Specified by:
containsHeader
in interfacejavax.servlet.http.HttpServletResponse
-
encodeURL
- Specified by:
encodeURL
in interfacejavax.servlet.http.HttpServletResponse
-
encodeRedirectURL
- Specified by:
encodeRedirectURL
in interfacejavax.servlet.http.HttpServletResponse
-
encodeUrl
Deprecated.- Specified by:
encodeUrl
in interfacejavax.servlet.http.HttpServletResponse
-
encodeRedirectUrl
Deprecated.- Specified by:
encodeRedirectUrl
in interfacejavax.servlet.http.HttpServletResponse
-
sendError
- Specified by:
sendError
in interfacejavax.servlet.http.HttpServletResponse
- Throws:
IOException
-
sendError
Send an error response.In addition to the servlet standard handling, this method supports some additional codes:
- 102
- Send a partial PROCESSING response and allow additional responses
- -1
- Abort the HttpChannel and close the connection/stream
- Specified by:
sendError
in interfacejavax.servlet.http.HttpServletResponse
- Parameters:
code
- The error codemessage
- The message- Throws:
IOException
- If an IO problem occurred sending the error response.
-
sendProcessing
Sends a 102-Processing response. If the connection is an HTTP connection, the version is 1.1 and the request has a Expect header starting with 102, then a 102 response is sent. This indicates that the request still be processed and real response can still be sent. This method is called by sendError if it is passed 102.- Throws:
IOException
- if unable to send the 102 response- See Also:
-
HttpServletResponse.sendError(int)
-
sendRedirect
Sends a response with one of the 300 series redirection codes.- Parameters:
code
- the redirect status codelocation
- the location to send inLocation
headers- Throws:
IOException
- if unable to send the redirect
-
sendRedirect
Sends a response with a HTTP version appropriate 30x redirection.- Parameters:
location
- the location to send inLocation
headersconsumeAll
- if True, consume any HTTP/1 request input before doing the redirection. If the input cannot be consumed without blocking, then add a `Connection: close` header to the response.- Throws:
IOException
- if unable to send the redirect
-
sendRedirect
Sends a response with a given redirection code.- Parameters:
code
- the redirect status codelocation
- the location to send inLocation
headersconsumeAll
- if True, consume any HTTP/1 request input before doing the redirection. If the input cannot be consumed without blocking, then add a `Connection: close` header to the response.- Throws:
IOException
- if unable to send the redirect
-
sendRedirect
- Specified by:
sendRedirect
in interfacejavax.servlet.http.HttpServletResponse
- Throws:
IOException
-
setDateHeader
- Specified by:
setDateHeader
in interfacejavax.servlet.http.HttpServletResponse
-
addDateHeader
- Specified by:
addDateHeader
in interfacejavax.servlet.http.HttpServletResponse
-
setHeader
-
setHeader
- Specified by:
setHeader
in interfacejavax.servlet.http.HttpServletResponse
-
getHeaderNames
- Specified by:
getHeaderNames
in interfacejavax.servlet.http.HttpServletResponse
-
getHeader
- Specified by:
getHeader
in interfacejavax.servlet.http.HttpServletResponse
-
getHeaders
- Specified by:
getHeaders
in interfacejavax.servlet.http.HttpServletResponse
-
addHeader
- Specified by:
addHeader
in interfacejavax.servlet.http.HttpServletResponse
-
setIntHeader
- Specified by:
setIntHeader
in interfacejavax.servlet.http.HttpServletResponse
-
addIntHeader
- Specified by:
addIntHeader
in interfacejavax.servlet.http.HttpServletResponse
-
setStatus
public void setStatus(int sc) - Specified by:
setStatus
in interfacejavax.servlet.http.HttpServletResponse
-
setStatus
Deprecated.- Specified by:
setStatus
in interfacejavax.servlet.http.HttpServletResponse
-
setStatusWithReason
-
getCharacterEncoding
- Specified by:
getCharacterEncoding
in interfacejavax.servlet.ServletResponse
-
getContentType
- Specified by:
getContentType
in interfacejavax.servlet.ServletResponse
-
getOutputStream
- Specified by:
getOutputStream
in interfacejavax.servlet.ServletResponse
- Throws:
IOException
-
isWriting
public boolean isWriting() -
isStreaming
public boolean isStreaming() -
isWritingOrStreaming
public boolean isWritingOrStreaming() -
getWriter
- Specified by:
getWriter
in interfacejavax.servlet.ServletResponse
- Throws:
IOException
-
setContentLength
public void setContentLength(int len) - Specified by:
setContentLength
in interfacejavax.servlet.ServletResponse
-
getContentLength
public long getContentLength() -
isAllContentWritten
public boolean isAllContentWritten(long written) -
isContentComplete
public boolean isContentComplete(long written) -
closeOutput
- Throws:
IOException
-
completeOutput
Deprecated.UsecloseOutput()
close the output- Throws:
IOException
-
completeOutput
-
getLongContentLength
public long getLongContentLength() -
setLongContentLength
public void setLongContentLength(long len) -
setContentLengthLong
public void setContentLengthLong(long length) - Specified by:
setContentLengthLong
in interfacejavax.servlet.ServletResponse
-
setCharacterEncoding
- Specified by:
setCharacterEncoding
in interfacejavax.servlet.ServletResponse
-
setCharacterEncoding
-
setContentType
- Specified by:
setContentType
in interfacejavax.servlet.ServletResponse
-
setBufferSize
public void setBufferSize(int size) - Specified by:
setBufferSize
in interfacejavax.servlet.ServletResponse
-
getBufferSize
public int getBufferSize()- Specified by:
getBufferSize
in interfacejavax.servlet.ServletResponse
-
flushBuffer
- Specified by:
flushBuffer
in interfacejavax.servlet.ServletResponse
- Throws:
IOException
-
reset
public void reset()- Specified by:
reset
in interfacejavax.servlet.ServletResponse
-
resetContent
public void resetContent() -
resetForForward
public void resetForForward() -
resetBuffer
public void resetBuffer()- Specified by:
resetBuffer
in interfacejavax.servlet.ServletResponse
-
setTrailers
-
getTrailers
-
newResponseMetaData
-
getCommittedMetaData
Get the MetaData.Response committed for this response. This may differ from the meta data in this response for exceptional responses (eg 4xx and 5xx responses generated by the container) and the committedMetaData should be used for logging purposes.- Returns:
- The committed MetaData or a
newResponseMetaData()
if not yet committed.
-
isCommitted
public boolean isCommitted()- Specified by:
isCommitted
in interfacejavax.servlet.ServletResponse
-
setLocale
- Specified by:
setLocale
in interfacejavax.servlet.ServletResponse
-
getLocale
- Specified by:
getLocale
in interfacejavax.servlet.ServletResponse
-
getStatus
public int getStatus()- Specified by:
getStatus
in interfacejavax.servlet.http.HttpServletResponse
-
getReason
-
getHttpFields
-
getContentCount
public long getContentCount() -
toString
-
putHeaders
-
putHeaders
public static void putHeaders(javax.servlet.http.HttpServletResponse response, HttpContent content, long contentLength, boolean etag) -
unwrap
public static javax.servlet.http.HttpServletResponse unwrap(javax.servlet.ServletResponse servletResponse)
-
closeOutput()