- All Known Implementing Classes:
WebMap.Info
public interface HttpServerResponse
Servlet-compatibility interface for HTTP responses.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCookie
(ServerCookie cookie) Add a cookie to the response headers.default void
addDateHeader
(String name, long date) Add a date header.void
Add a header.default void
addIntHeader
(String name, int value) Add an integer header.boolean
containsHeader
(String name) Determine if a response header with the specified name exists.encodeRedirectURL
(String url) Encode a URL for use insendRedirect(String)
.Encode a URL so that it includes a session ID if necessary.Get the names of the current response header names.getHeaders
(String name) Get the headers with a given name.Get the output stream for responses.boolean
Determine if this response has been committed.void
sendError
(int rc) Sends a response with a given HTML response code for an error with no content.void
sendRedirect
(String location) Sends an HTTP redirect response with a given location.void
sendResponseHeaders
(int code, long length) Set the response code and content length.default void
setDateHeader
(String name, long date) Add a date header.void
setEncoding
(String encoding) Set whether or not a response uses compression or some other transfer encoding.void
Set the specified header.default void
setIntHeader
(String name, int value) Set an integer header.
-
Method Details
-
addCookie
Add a cookie to the response headers.- Parameters:
cookie
- the cookie- Throws:
IllegalStateException
- an implementation-dependent error occurred (forWebMap.Info
the constructor was not given an instance ofWebMap.RequestInfo
)
-
addDateHeader
Add a date header.- Parameters:
name
- the name of the headerdate
- the date provided in milliseconds since 00:00:00 January 1, 1970 GMT.- Throws:
IllegalStateException
- an implementation-dependent error occurred (forWebMap.Info
the constructor was not given an instance ofWebMap.RequestInfo
)
-
addHeader
Add a header. This method is used when multiple headers with the same name are needed.- Parameters:
name
- the name of the headervalue
- the value of the header- Throws:
IllegalStateException
- an implementation-dependent error occurred (forWebMap.Info
the constructor was not given an instance ofWebMap.RequestInfo
)
-
addIntHeader
Add an integer header.- Parameters:
name
- the ename of the headervalue
- the value of the header- Throws:
IllegalStateException
- an implementation-dependent error occurred (forWebMap.Info
the constructor was not given an instance ofWebMap.RequestInfo
)
-
containsHeader
Determine if a response header with the specified name exists.- Parameters:
name
- the header name- Returns:
- true if the header exists; false otherwise
- Throws:
IllegalStateException
- an implementation-dependent error occurred (forWebMap.Info
the constructor was not given an instance ofWebMap.RequestInfo
)
-
encodeRedirectURL
Encode a URL for use insendRedirect(String)
. This method is needed by the Servlet specification where encoding may be necessary to include a session ID.- Parameters:
url
- the URL- Returns:
- the encoded URL
-
encodeURL
Encode a URL so that it includes a session ID if necessary. This method is needed by the Servlet specification where encoding may be necessary to include a session ID.- Parameters:
url
- the URL- Returns:
- the encoded URL
-
getHeaderNames
Get the names of the current response header names.- Returns:
- a collection of the response header names
- Throws:
IllegalStateException
- an implementation-dependent error occurred (forWebMap.Info
the constructor was not given an instance ofWebMap.RequestInfo
)
-
getHeaders
Get the headers with a given name.- Parameters:
name
- the name- Returns:
- a collection of the header values for a given name
- Throws:
IllegalStateException
- an implementation-dependent error occurred (forWebMap.Info
the constructor was not given an instance ofWebMap.RequestInfo
)
-
sendError
Sends a response with a given HTML response code for an error with no content. If this method is called,sendResponseHeaders(int,long)
should not be called.- Parameters:
rc
- the response code- Throws:
IllegalStateException
- an implementation-dependent error occurred (forWebMap.Info
the constructor was not given an instance ofWebMap.RequestInfo
)IOException
- an IO error occurred
-
sendRedirect
Sends an HTTP redirect response with a given location.- Parameters:
location
- a URL providing the location- Throws:
IllegalStateException
- an implementation-dependent error occurred (forWebMap.Info
the constructor was not given an instance ofWebMap.RequestInfo
)IOException
- an IO error occurred
-
setDateHeader
Add a date header.- Parameters:
name
- the name of the headerdate
- the date provided in milliseconds since 00:00:00 January 1, 1970 GMT.- Throws:
IllegalStateException
- an implementation-dependent error occurred (forWebMap.Info
the constructor was not given an instance ofWebMap.RequestInfo
)
-
setHeader
Set the specified header.- Parameters:
name
- the name of the headervalue
- the value for the header- Throws:
IllegalStateException
- an implementation-dependent error occurred (forWebMap.Info
the constructor was not given an instance ofWebMap.RequestInfo
)
-
setIntHeader
Set an integer header.- Parameters:
name
- the ename of the headervalue
- the value of the header- Throws:
IllegalStateException
- an implementation-dependent error occurred (forWebMap.Info
the constructor was not given an instance ofWebMap.RequestInfo
)
-
setEncoding
Set whether or not a response uses compression or some other transfer encoding.- Parameters:
encoding
- the encoding ("identity", "gzip", "compress", and "deflate" are standard values); null defaults to "identity"
-
sendResponseHeaders
Set the response code and content length. If the length is 0, indicating that the length is not known, chunked transfer encoding is automatically used. As a result, one should generally avoid the explicit use of the transfer-encoding header.If this method is called,
sendError(int)
should not be called.When used in a servlet, this method should call the one-argument servlet-response method setStatus, and also call setContentLength or setContentLengthLong. Headers may not be modified after this method is called.
- Parameters:
code
- the response codelength
- the length of the response; 0 if the length is not known, and -1 if there is no response.- Throws:
IllegalStateException
- an implementation-dependent error occurred (forWebMap.Info
the constructor was not given an instance ofWebMap.RequestInfo
)
-
getOutputStream
Get the output stream for responses.- Returns:
- the output stream.
- Throws:
IllegalStateException
- an implementation-dependent error occurred (forWebMap.Info
the constructor was not given an instance ofWebMap.RequestInfo
)IOException
- an IO error occurred
-
isCommitted
boolean isCommitted()Determine if this response has been committed. A response is committed if its status code and headers have been written.- Returns:
- true if this response has been committed; false otherwise
-