- java.lang.Object
-
- org.eclipse.jetty.server.Response
-
- All Implemented Interfaces:
jakarta.servlet.http.HttpServletResponse,jakarta.servlet.ServletResponse
public class Response extends java.lang.Object implements jakarta.servlet.http.HttpServletResponseResponseprovides the implementation forHttpServletResponse.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classResponse.OutputType
-
Field Summary
Fields Modifier and Type Field Description static intNO_CONTENT_LENGTHstatic java.lang.StringSET_INCLUDE_HEADER_PREFIXIf 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 intUSE_KNOWN_CONTENT_LENGTH-
Fields inherited from interface jakarta.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 Constructor Description Response(HttpChannel channel, HttpOutput out)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddCookie(jakarta.servlet.http.Cookie cookie)voidaddCookie(org.eclipse.jetty.http.HttpCookie cookie)voidaddDateHeader(java.lang.String name, long date)voidaddHeader(java.lang.String name, java.lang.String value)voidaddIntHeader(java.lang.String name, int value)voidcloseOutput()voidcompleteOutput()Deprecated.UsecloseOutput()voidcompleteOutput(org.eclipse.jetty.util.Callback callback)booleancontainsHeader(java.lang.String name)java.lang.StringencodeRedirectUrl(java.lang.String url)Deprecated.java.lang.StringencodeRedirectURL(java.lang.String url)java.lang.StringencodeUrl(java.lang.String url)Deprecated.java.lang.StringencodeURL(java.lang.String url)voiderrorClose()voidflushBuffer()intgetBufferSize()java.lang.StringgetCharacterEncoding()org.eclipse.jetty.http.MetaData.ResponsegetCommittedMetaData()Get the MetaData.Response committed for this response.longgetContentCount()longgetContentLength()java.lang.StringgetContentType()java.lang.StringgetHeader(java.lang.String name)java.util.Collection<java.lang.String>getHeaderNames()java.util.Collection<java.lang.String>getHeaders(java.lang.String name)HttpChannelgetHttpChannel()org.eclipse.jetty.http.HttpFields.MutablegetHttpFields()HttpOutputgetHttpOutput()java.util.LocalegetLocale()longgetLongContentLength()jakarta.servlet.ServletOutputStreamgetOutputStream()java.lang.StringgetReason()intgetStatus()java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.String>>getTrailerFields()java.util.function.Supplier<org.eclipse.jetty.http.HttpFields>getTrailers()java.io.PrintWritergetWriter()voidinclude()voidincluded()booleanisAllContentWritten(long written)booleanisCommitted()booleanisContentComplete(long written)booleanisIncluding()booleanisStreaming()booleanisWriting()booleanisWritingOrStreaming()protected org.eclipse.jetty.http.MetaData.ResponsenewResponseMetaData()static voidputHeaders(jakarta.servlet.http.HttpServletResponse response, org.eclipse.jetty.http.HttpContent content, long contentLength, boolean etag)voidputHeaders(org.eclipse.jetty.http.HttpContent content, long contentLength, boolean etag)protected voidrecycle()voidreopen()voidreplaceCookie(org.eclipse.jetty.http.HttpCookie cookie)Replace (or add) a cookie.voidreset()voidresetBuffer()voidresetContent()voidresetForForward()voidsendError(int sc)voidsendError(int code, java.lang.String message)Send an error response.voidsendProcessing()Sends a 102-Processing response.voidsendRedirect(int code, java.lang.String location)Sends a response with one of the 300 series redirection codes.voidsendRedirect(int code, java.lang.String location, boolean consumeAll)Sends a response with a given redirection code.voidsendRedirect(java.lang.String location)voidsendRedirect(java.lang.String location, boolean consumeAll)Sends a response with a HTTP version appropriate 30x redirection.voidsetBufferSize(int size)voidsetCharacterEncoding(java.lang.String encoding)voidsetContentLength(int len)voidsetContentLengthLong(long length)voidsetContentType(java.lang.String contentType)voidsetDateHeader(java.lang.String name, long date)voidsetHeader(java.lang.String name, java.lang.String value)voidsetHeader(org.eclipse.jetty.http.HttpHeader name, java.lang.String value)voidsetIntHeader(java.lang.String name, int value)voidsetLocale(java.util.Locale locale)voidsetLongContentLength(long len)voidsetStatus(int sc)voidsetStatus(int sc, java.lang.String message)Deprecated.voidsetStatusWithReason(int sc, java.lang.String message)voidsetTrailerFields(java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.String>> trailers)voidsetTrailers(java.util.function.Supplier<org.eclipse.jetty.http.HttpFields> trailers)java.lang.StringtoString()static jakarta.servlet.http.HttpServletResponseunwrap(jakarta.servlet.ServletResponse servletResponse)
-
-
-
Field Detail
-
NO_CONTENT_LENGTH
public static final int NO_CONTENT_LENGTH
- See Also:
- Constant Field Values
-
USE_KNOWN_CONTENT_LENGTH
public static final int USE_KNOWN_CONTENT_LENGTH
- See Also:
- Constant Field Values
-
SET_INCLUDE_HEADER_PREFIX
public static final java.lang.String 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:
- Constant Field Values
-
-
Constructor Detail
-
Response
public Response(HttpChannel channel, HttpOutput out)
-
-
Method Detail
-
getHttpChannel
public HttpChannel getHttpChannel()
-
recycle
protected void recycle()
-
getHttpOutput
public HttpOutput getHttpOutput()
-
reopen
public void reopen()
-
errorClose
public void errorClose()
-
isIncluding
public boolean isIncluding()
-
include
public void include()
-
included
public void included()
-
addCookie
public void addCookie(org.eclipse.jetty.http.HttpCookie cookie)
-
addCookie
public void addCookie(jakarta.servlet.http.Cookie cookie)
- Specified by:
addCookiein interfacejakarta.servlet.http.HttpServletResponse
-
replaceCookie
public void replaceCookie(org.eclipse.jetty.http.HttpCookie cookie)
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
-
containsHeader
public boolean containsHeader(java.lang.String name)
- Specified by:
containsHeaderin interfacejakarta.servlet.http.HttpServletResponse
-
encodeURL
public java.lang.String encodeURL(java.lang.String url)
- Specified by:
encodeURLin interfacejakarta.servlet.http.HttpServletResponse
-
encodeRedirectURL
public java.lang.String encodeRedirectURL(java.lang.String url)
- Specified by:
encodeRedirectURLin interfacejakarta.servlet.http.HttpServletResponse
-
encodeUrl
@Deprecated(since="Servlet API 2.1") public java.lang.String encodeUrl(java.lang.String url)
Deprecated.- Specified by:
encodeUrlin interfacejakarta.servlet.http.HttpServletResponse
-
encodeRedirectUrl
@Deprecated(since="Servlet API 2.1") public java.lang.String encodeRedirectUrl(java.lang.String url)
Deprecated.- Specified by:
encodeRedirectUrlin interfacejakarta.servlet.http.HttpServletResponse
-
sendError
public void sendError(int sc) throws java.io.IOException- Specified by:
sendErrorin interfacejakarta.servlet.http.HttpServletResponse- Throws:
java.io.IOException
-
sendError
public void sendError(int code, java.lang.String message) throws java.io.IOExceptionSend 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:
sendErrorin interfacejakarta.servlet.http.HttpServletResponse- Parameters:
code- The error codemessage- The message- Throws:
java.io.IOException- If an IO problem occurred sending the error response.
-
sendProcessing
public void sendProcessing() throws java.io.IOExceptionSends 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:
java.io.IOException- if unable to send the 102 response- See Also:
HttpServletResponse.sendError(int)
-
sendRedirect
public void sendRedirect(int code, java.lang.String location) throws java.io.IOExceptionSends a response with one of the 300 series redirection codes.- Parameters:
code- the redirect status codelocation- the location to send inLocationheaders- Throws:
java.io.IOException- if unable to send the redirect
-
sendRedirect
public void sendRedirect(java.lang.String location, boolean consumeAll) throws java.io.IOExceptionSends a response with a HTTP version appropriate 30x redirection.- Parameters:
location- the location to send inLocationheadersconsumeAll- 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:
java.io.IOException- if unable to send the redirect
-
sendRedirect
public void sendRedirect(int code, java.lang.String location, boolean consumeAll) throws java.io.IOExceptionSends a response with a given redirection code.- Parameters:
code- the redirect status codelocation- the location to send inLocationheadersconsumeAll- 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:
java.io.IOException- if unable to send the redirect
-
sendRedirect
public void sendRedirect(java.lang.String location) throws java.io.IOException- Specified by:
sendRedirectin interfacejakarta.servlet.http.HttpServletResponse- Throws:
java.io.IOException
-
setDateHeader
public void setDateHeader(java.lang.String name, long date)- Specified by:
setDateHeaderin interfacejakarta.servlet.http.HttpServletResponse
-
addDateHeader
public void addDateHeader(java.lang.String name, long date)- Specified by:
addDateHeaderin interfacejakarta.servlet.http.HttpServletResponse
-
setHeader
public void setHeader(org.eclipse.jetty.http.HttpHeader name, java.lang.String value)
-
setHeader
public void setHeader(java.lang.String name, java.lang.String value)- Specified by:
setHeaderin interfacejakarta.servlet.http.HttpServletResponse
-
getHeaderNames
public java.util.Collection<java.lang.String> getHeaderNames()
- Specified by:
getHeaderNamesin interfacejakarta.servlet.http.HttpServletResponse
-
getHeader
public java.lang.String getHeader(java.lang.String name)
- Specified by:
getHeaderin interfacejakarta.servlet.http.HttpServletResponse
-
getHeaders
public java.util.Collection<java.lang.String> getHeaders(java.lang.String name)
- Specified by:
getHeadersin interfacejakarta.servlet.http.HttpServletResponse
-
addHeader
public void addHeader(java.lang.String name, java.lang.String value)- Specified by:
addHeaderin interfacejakarta.servlet.http.HttpServletResponse
-
setIntHeader
public void setIntHeader(java.lang.String name, int value)- Specified by:
setIntHeaderin interfacejakarta.servlet.http.HttpServletResponse
-
addIntHeader
public void addIntHeader(java.lang.String name, int value)- Specified by:
addIntHeaderin interfacejakarta.servlet.http.HttpServletResponse
-
setStatus
public void setStatus(int sc)
- Specified by:
setStatusin interfacejakarta.servlet.http.HttpServletResponse
-
setStatus
@Deprecated(since="Servlet API 2.1") public void setStatus(int sc, java.lang.String message)Deprecated.- Specified by:
setStatusin interfacejakarta.servlet.http.HttpServletResponse
-
setStatusWithReason
public void setStatusWithReason(int sc, java.lang.String message)
-
getCharacterEncoding
public java.lang.String getCharacterEncoding()
- Specified by:
getCharacterEncodingin interfacejakarta.servlet.ServletResponse
-
getContentType
public java.lang.String getContentType()
- Specified by:
getContentTypein interfacejakarta.servlet.ServletResponse
-
getOutputStream
public jakarta.servlet.ServletOutputStream getOutputStream() throws java.io.IOException- Specified by:
getOutputStreamin interfacejakarta.servlet.ServletResponse- Throws:
java.io.IOException
-
isWriting
public boolean isWriting()
-
isStreaming
public boolean isStreaming()
-
isWritingOrStreaming
public boolean isWritingOrStreaming()
-
getWriter
public java.io.PrintWriter getWriter() throws java.io.IOException- Specified by:
getWriterin interfacejakarta.servlet.ServletResponse- Throws:
java.io.IOException
-
setContentLength
public void setContentLength(int len)
- Specified by:
setContentLengthin interfacejakarta.servlet.ServletResponse
-
getContentLength
public long getContentLength()
-
isAllContentWritten
public boolean isAllContentWritten(long written)
-
isContentComplete
public boolean isContentComplete(long written)
-
closeOutput
public void closeOutput() throws java.io.IOException- Throws:
java.io.IOException
-
completeOutput
@Deprecated public void completeOutput() throws java.io.IOExceptionDeprecated.UsecloseOutput()close the output- Throws:
java.io.IOException
-
completeOutput
public void completeOutput(org.eclipse.jetty.util.Callback callback)
-
getLongContentLength
public long getLongContentLength()
-
setLongContentLength
public void setLongContentLength(long len)
-
setContentLengthLong
public void setContentLengthLong(long length)
- Specified by:
setContentLengthLongin interfacejakarta.servlet.ServletResponse
-
setCharacterEncoding
public void setCharacterEncoding(java.lang.String encoding)
- Specified by:
setCharacterEncodingin interfacejakarta.servlet.ServletResponse
-
setContentType
public void setContentType(java.lang.String contentType)
- Specified by:
setContentTypein interfacejakarta.servlet.ServletResponse
-
setBufferSize
public void setBufferSize(int size)
- Specified by:
setBufferSizein interfacejakarta.servlet.ServletResponse
-
getBufferSize
public int getBufferSize()
- Specified by:
getBufferSizein interfacejakarta.servlet.ServletResponse
-
flushBuffer
public void flushBuffer() throws java.io.IOException- Specified by:
flushBufferin interfacejakarta.servlet.ServletResponse- Throws:
java.io.IOException
-
reset
public void reset()
- Specified by:
resetin interfacejakarta.servlet.ServletResponse
-
resetContent
public void resetContent()
-
resetForForward
public void resetForForward()
-
resetBuffer
public void resetBuffer()
- Specified by:
resetBufferin interfacejakarta.servlet.ServletResponse
-
getTrailers
public java.util.function.Supplier<org.eclipse.jetty.http.HttpFields> getTrailers()
-
setTrailers
public void setTrailers(java.util.function.Supplier<org.eclipse.jetty.http.HttpFields> trailers)
-
getTrailerFields
public java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.String>> getTrailerFields()
- Specified by:
getTrailerFieldsin interfacejakarta.servlet.http.HttpServletResponse
-
setTrailerFields
public void setTrailerFields(java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.String>> trailers)
- Specified by:
setTrailerFieldsin interfacejakarta.servlet.http.HttpServletResponse
-
newResponseMetaData
protected org.eclipse.jetty.http.MetaData.Response newResponseMetaData()
-
getCommittedMetaData
public org.eclipse.jetty.http.MetaData.Response 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:
isCommittedin interfacejakarta.servlet.ServletResponse
-
setLocale
public void setLocale(java.util.Locale locale)
- Specified by:
setLocalein interfacejakarta.servlet.ServletResponse
-
getLocale
public java.util.Locale getLocale()
- Specified by:
getLocalein interfacejakarta.servlet.ServletResponse
-
getStatus
public int getStatus()
- Specified by:
getStatusin interfacejakarta.servlet.http.HttpServletResponse
-
getReason
public java.lang.String getReason()
-
getHttpFields
public org.eclipse.jetty.http.HttpFields.Mutable getHttpFields()
-
getContentCount
public long getContentCount()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
putHeaders
public void putHeaders(org.eclipse.jetty.http.HttpContent content, long contentLength, boolean etag)
-
putHeaders
public static void putHeaders(jakarta.servlet.http.HttpServletResponse response, org.eclipse.jetty.http.HttpContent content, long contentLength, boolean etag)
-
unwrap
public static jakarta.servlet.http.HttpServletResponse unwrap(jakarta.servlet.ServletResponse servletResponse)
-
-