Package org.eclipse.jetty.server
Class Response
- java.lang.Object
-
- org.eclipse.jetty.server.Response
-
- All Implemented Interfaces:
HttpServletResponse,ServletResponse
public class Response extends Object implements HttpServletResponse
Responseprovides 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 StringHTTP_ONLY_COMMENTIf this string is found within the comment of a cookie added withaddCookie(Cookie), then the cookie will be set as HTTP ONLY.static 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).-
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 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(Cookie cookie)voidaddCookie(org.eclipse.jetty.http.HttpCookie cookie)voidaddDateHeader(String name, long date)voidaddHeader(String name, String value)voidaddIntHeader(String name, int value)voidaddSetRFC2965Cookie(String name, String value, String domain, String path, long maxAge, String comment, boolean isSecure, boolean isHttpOnly, int version)Format a set cookie valuevoidaddSetRFC6265Cookie(String name, String value, String domain, String path, long maxAge, boolean isSecure, boolean isHttpOnly)Format a set cookie value by RFC6265voidcloseOutput()booleancontainsHeader(String name)StringencodeRedirectUrl(String url)Deprecated.StringencodeRedirectURL(String url)StringencodeUrl(String url)Deprecated.StringencodeURL(String url)voidflushBuffer()intgetBufferSize()StringgetCharacterEncoding()org.eclipse.jetty.http.MetaData.ResponsegetCommittedMetaData()Get the MetaData.Response committed for this response.longgetContentCount()longgetContentLength()StringgetContentType()StringgetHeader(String name)Collection<String>getHeaderNames()Collection<String>getHeaders(String name)HttpChannelgetHttpChannel()org.eclipse.jetty.http.HttpFieldsgetHttpFields()HttpOutputgetHttpOutput()LocalegetLocale()longgetLongContentLength()ServletOutputStreamgetOutputStream()StringgetReason()intgetStatus()Supplier<org.eclipse.jetty.http.HttpFields>getTrailers()PrintWritergetWriter()voidinclude()voidincluded()booleanisAllContentWritten(long written)booleanisCommitted()booleanisContentComplete(long written)booleanisIncluding()booleanisWriting()protected org.eclipse.jetty.http.MetaData.ResponsenewResponseMetaData()static voidputHeaders(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()voidreset()voidreset(boolean preserveCookies)voidresetBuffer()voidresetForForward()voidsendError(int sc)voidsendError(int code, String message)voidsendProcessing()Sends a 102-Processing response.voidsendRedirect(int code, String location)Sends a response with one of the 300 series redirection codes.voidsendRedirect(String location)voidsetBufferSize(int size)voidsetCharacterEncoding(String encoding)voidsetContentLength(int len)voidsetContentLengthLong(long length)voidsetContentType(String contentType)voidsetDateHeader(String name, long date)voidsetHeader(String name, String value)voidsetHeader(org.eclipse.jetty.http.HttpHeader name, String value)voidsetIntHeader(String name, int value)voidsetLocale(Locale locale)voidsetLongContentLength(long len)voidsetStatus(int sc)voidsetStatus(int sc, String sm)Deprecated.voidsetStatusWithReason(int sc, String sm)voidsetTrailers(Supplier<org.eclipse.jetty.http.HttpFields> trailers)StringtoString()
-
-
-
Field Detail
-
SET_INCLUDE_HEADER_PREFIX
public static final 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
-
HTTP_ONLY_COMMENT
public static final String HTTP_ONLY_COMMENT
If this string is found within the comment of a cookie added withaddCookie(Cookie), then the cookie will be set as HTTP ONLY.- 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()
-
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(Cookie cookie)
- Specified by:
addCookiein interfaceHttpServletResponse
-
addSetRFC6265Cookie
public void addSetRFC6265Cookie(String name, String value, String domain, String path, long maxAge, boolean isSecure, boolean isHttpOnly)
Format a set cookie value by RFC6265- Parameters:
name- the namevalue- the valuedomain- the domainpath- the pathmaxAge- the maximum ageisSecure- true if secure cookieisHttpOnly- true if for http only
-
addSetRFC2965Cookie
public void addSetRFC2965Cookie(String name, String value, String domain, String path, long maxAge, String comment, boolean isSecure, boolean isHttpOnly, int version)
Format a set cookie value- Parameters:
name- the namevalue- the valuedomain- the domainpath- the pathmaxAge- the maximum agecomment- the comment (only present on versions > 0)isSecure- true if secure cookieisHttpOnly- true if for http onlyversion- version of cookie logic to use (0 == default behavior)
-
containsHeader
public boolean containsHeader(String name)
- Specified by:
containsHeaderin interfaceHttpServletResponse
-
encodeURL
public String encodeURL(String url)
- Specified by:
encodeURLin interfaceHttpServletResponse
-
encodeRedirectURL
public String encodeRedirectURL(String url)
- Specified by:
encodeRedirectURLin interfaceHttpServletResponse
-
encodeUrl
@Deprecated public String encodeUrl(String url)
Deprecated.- Specified by:
encodeUrlin interfaceHttpServletResponse
-
encodeRedirectUrl
@Deprecated public String encodeRedirectUrl(String url)
Deprecated.- Specified by:
encodeRedirectUrlin interfaceHttpServletResponse
-
sendError
public void sendError(int sc) throws IOException- Specified by:
sendErrorin interfaceHttpServletResponse- Throws:
IOException
-
sendError
public void sendError(int code, String message) throws IOException- Specified by:
sendErrorin interfaceHttpServletResponse- Throws:
IOException
-
sendProcessing
public void sendProcessing() throws IOExceptionSends a 102-Processing response. If the connection is a 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
public void sendRedirect(int code, String location) throws IOExceptionSends a response with one of the 300 series redirection codes.- Parameters:
code- the redirect status codelocation- the location to send inLocationheaders- Throws:
IOException- if unable to send the redirect
-
sendRedirect
public void sendRedirect(String location) throws IOException
- Specified by:
sendRedirectin interfaceHttpServletResponse- Throws:
IOException
-
setDateHeader
public void setDateHeader(String name, long date)
- Specified by:
setDateHeaderin interfaceHttpServletResponse
-
addDateHeader
public void addDateHeader(String name, long date)
- Specified by:
addDateHeaderin interfaceHttpServletResponse
-
setHeader
public void setHeader(org.eclipse.jetty.http.HttpHeader name, String value)
-
setHeader
public void setHeader(String name, String value)
- Specified by:
setHeaderin interfaceHttpServletResponse
-
getHeaderNames
public Collection<String> getHeaderNames()
- Specified by:
getHeaderNamesin interfaceHttpServletResponse
-
getHeader
public String getHeader(String name)
- Specified by:
getHeaderin interfaceHttpServletResponse
-
getHeaders
public Collection<String> getHeaders(String name)
- Specified by:
getHeadersin interfaceHttpServletResponse
-
addHeader
public void addHeader(String name, String value)
- Specified by:
addHeaderin interfaceHttpServletResponse
-
setIntHeader
public void setIntHeader(String name, int value)
- Specified by:
setIntHeaderin interfaceHttpServletResponse
-
addIntHeader
public void addIntHeader(String name, int value)
- Specified by:
addIntHeaderin interfaceHttpServletResponse
-
setStatus
public void setStatus(int sc)
- Specified by:
setStatusin interfaceHttpServletResponse
-
setStatus
@Deprecated public void setStatus(int sc, String sm)
Deprecated.- Specified by:
setStatusin interfaceHttpServletResponse
-
setStatusWithReason
public void setStatusWithReason(int sc, String sm)
-
getCharacterEncoding
public String getCharacterEncoding()
- Specified by:
getCharacterEncodingin interfaceServletResponse
-
getContentType
public String getContentType()
- Specified by:
getContentTypein interfaceServletResponse
-
getOutputStream
public ServletOutputStream getOutputStream() throws IOException
- Specified by:
getOutputStreamin interfaceServletResponse- Throws:
IOException
-
isWriting
public boolean isWriting()
-
getWriter
public PrintWriter getWriter() throws IOException
- Specified by:
getWriterin interfaceServletResponse- Throws:
IOException
-
setContentLength
public void setContentLength(int len)
- Specified by:
setContentLengthin interfaceServletResponse
-
getContentLength
public long getContentLength()
-
isAllContentWritten
public boolean isAllContentWritten(long written)
-
isContentComplete
public boolean isContentComplete(long written)
-
closeOutput
public void closeOutput() throws IOException- Throws:
IOException
-
getLongContentLength
public long getLongContentLength()
-
setLongContentLength
public void setLongContentLength(long len)
-
setContentLengthLong
public void setContentLengthLong(long length)
- Specified by:
setContentLengthLongin interfaceServletResponse
-
setCharacterEncoding
public void setCharacterEncoding(String encoding)
- Specified by:
setCharacterEncodingin interfaceServletResponse
-
setContentType
public void setContentType(String contentType)
- Specified by:
setContentTypein interfaceServletResponse
-
setBufferSize
public void setBufferSize(int size)
- Specified by:
setBufferSizein interfaceServletResponse
-
getBufferSize
public int getBufferSize()
- Specified by:
getBufferSizein interfaceServletResponse
-
flushBuffer
public void flushBuffer() throws IOException- Specified by:
flushBufferin interfaceServletResponse- Throws:
IOException
-
reset
public void reset()
- Specified by:
resetin interfaceServletResponse
-
reset
public void reset(boolean preserveCookies)
-
resetForForward
public void resetForForward()
-
resetBuffer
public void resetBuffer()
- Specified by:
resetBufferin interfaceServletResponse
-
setTrailers
public void setTrailers(Supplier<org.eclipse.jetty.http.HttpFields> trailers)
-
getTrailers
public Supplier<org.eclipse.jetty.http.HttpFields> getTrailers()
-
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 interfaceServletResponse
-
setLocale
public void setLocale(Locale locale)
- Specified by:
setLocalein interfaceServletResponse
-
getLocale
public Locale getLocale()
- Specified by:
getLocalein interfaceServletResponse
-
getStatus
public int getStatus()
- Specified by:
getStatusin interfaceHttpServletResponse
-
getReason
public String getReason()
-
getHttpFields
public org.eclipse.jetty.http.HttpFields getHttpFields()
-
getContentCount
public long getContentCount()
-
putHeaders
public void putHeaders(org.eclipse.jetty.http.HttpContent content, long contentLength, boolean etag)
-
putHeaders
public static void putHeaders(HttpServletResponse response, org.eclipse.jetty.http.HttpContent content, long contentLength, boolean etag)
-
-