#include <NoBodyResponse.h>
Public Member Functions | |
virtual void | setContentLength (int len) |
virtual void | setCharacterEncoding (const std::string &charset) |
virtual void | setContentType (const std::string &type) |
virtual std::string | getContentType () |
virtual std::ostream & | getOutputStream () |
virtual std::string | getCharacterEncoding () |
virtual void | setBufferSize (int size) |
virtual int | getBufferSize () |
virtual void | reset () |
virtual bool | isCommitted () |
virtual void | flushBuffer () |
virtual void | addCookie (const Cookie &cookie) |
virtual bool | containsHeader (const std::string &name) const |
virtual void | setStatus (int sc) |
virtual void | setHeader (const std::string &name, const std::string &value) |
virtual void | setIntHeader (const std::string &name, int value) |
virtual void | setDateHeader (const std::string &name, long date) |
virtual void | sendError (int sc, const std::string &msg) |
virtual void | sendError (int sc) |
virtual void | sendRedirect (const std::string &location) |
virtual std::string | encodeURL (const std::string &url) |
virtual std::string | encodeRedirectURL (const std::string &url) |
virtual void | addHeader (const std::string &name, const std::string &value) |
virtual void | addDateHeader (const std::string &name, long date) |
virtual void | addIntHeader (const std::string &name, int value) |
Private Member Functions | |
NoBodyResponse (HttpServletResponse &r) | |
virtual | ~NoBodyResponse () |
void | setContentLength () |
Private Attributes | |
HttpServletResponse & | resp |
onobodystream | no_body |
bool | didSetContentLength |
Friends | |
class | HttpServlet |
Definition at line 73 of file NoBodyResponse.h.
servlet::NoBodyResponse::NoBodyResponse | ( | HttpServletResponse & | r | ) | [private] |
Definition at line 60 of file NoBodyResponse.cpp.
virtual servlet::NoBodyResponse::~NoBodyResponse | ( | ) | [inline, private, virtual] |
Definition at line 79 of file NoBodyResponse.h.
void servlet::NoBodyResponse::addCookie | ( | const Cookie & | cookie | ) | [virtual] |
Adds the specified cookie to the response. This method can be called multiple times to set more than one cookie.
cookie | the Cookie to return to the client |
Implements servlet::HttpServletResponse.
Definition at line 165 of file NoBodyResponse.cpp.
References servlet::HttpServletResponse::addCookie(), and resp.
void servlet::NoBodyResponse::addDateHeader | ( | const std::string & | name, | |
long | date | |||
) | [virtual] |
Adds a response header with the given name and date-value. The date is specified in terms of milliseconds since the epoch. This method allows response headers to have multiple values.
name | the name of the header to set | |
date | the additional date value |
Implements servlet::HttpServletResponse.
Definition at line 249 of file NoBodyResponse.cpp.
References servlet::HttpServletResponse::addDateHeader(), and resp.
void servlet::NoBodyResponse::addHeader | ( | const std::string & | name, | |
const std::string & | value | |||
) | [virtual] |
Adds a response header with the given name and value. This method allows response headers to have multiple values.
name | the name of the header | |
value | the additional header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt) |
Implements servlet::HttpServletResponse.
Definition at line 242 of file NoBodyResponse.cpp.
References servlet::HttpServletResponse::addHeader(), and resp.
void servlet::NoBodyResponse::addIntHeader | ( | const std::string & | name, | |
int | value | |||
) | [virtual] |
Adds a response header with the given name and integer value. This method allows response headers to have multiple values.
name | the name of the header | |
value | the assigned integer value |
Implements servlet::HttpServletResponse.
Definition at line 256 of file NoBodyResponse.cpp.
References servlet::HttpServletResponse::addIntHeader(), and resp.
bool servlet::NoBodyResponse::containsHeader | ( | const std::string & | name | ) | const [virtual] |
Returns a boolean indicating whether the named response header has already been set.
name | the header name |
true
if the named response header has already been set; false
otherwise Implements servlet::HttpServletResponse.
Definition at line 172 of file NoBodyResponse.cpp.
References servlet::HttpServletResponse::containsHeader(), and resp.
std::string servlet::NoBodyResponse::encodeRedirectURL | ( | const std::string & | url | ) | [virtual] |
Encodes the specified URL for use in the sendRedirect
method or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is separated from the encodeURL
method.
All URLs sent to the HttpServletResponse.sendRedirect
method should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.
url | the url to be encoded. |
Implements servlet::HttpServletResponse.
Definition at line 235 of file NoBodyResponse.cpp.
References servlet::HttpServletResponse::encodeRedirectURL(), and resp.
std::string servlet::NoBodyResponse::encodeURL | ( | const std::string & | url | ) | [virtual] |
Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. For example, if the browser supports cookies, or session tracking is turned off, URL encoding is unnecessary.
For robust session tracking, all URLs emitted by a servlet should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.
url | the url to be encoded. |
Implements servlet::HttpServletResponse.
Definition at line 228 of file NoBodyResponse.cpp.
References servlet::HttpServletResponse::encodeURL(), and resp.
void servlet::NoBodyResponse::flushBuffer | ( | ) | [virtual] |
Forces any content in the buffer to be written to the client. A call to this method automatically commits the response, meaning the status code and headers will be written.
Implements servlet::ServletResponse.
Definition at line 146 of file NoBodyResponse.cpp.
References servlet::ServletResponse::flushBuffer(), and resp.
int servlet::NoBodyResponse::getBufferSize | ( | ) | [virtual] |
Returns the actual buffer size used for the response. If no buffering is used, this method returns 0.
Implements servlet::ServletResponse.
Definition at line 125 of file NoBodyResponse.cpp.
References servlet::ServletResponse::getBufferSize(), and resp.
std::string servlet::NoBodyResponse::getCharacterEncoding | ( | ) | [virtual] |
Returns the name of the character encoding (MIME charset) used for the body sent in this response. The character encoding may have been specified explicitly using the setCharacterEncoding or setContentType methods, or implicitly using the setLocale method. Explicit specifications take precedence over implicit specifications. Calls made to these methods after getWriter
has been called or after the response has been committed have no effect on the character encoding. If no character encoding has been specified, ISO-8859-1
is returned.
See RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt) for more information about character encoding and MIME.
String
specifying the name of the character encoding, for example, UTF-8
Implements servlet::ServletResponse.
Definition at line 111 of file NoBodyResponse.cpp.
References servlet::ServletResponse::getCharacterEncoding(), and resp.
std::string servlet::NoBodyResponse::getContentType | ( | ) | [virtual] |
Returns the content type used for the MIME body sent in this response. The content type proper must have been specified using setContentType before the response is committed. If no content type has been specified, this method returns null. If a content type has been specified and a character encoding has been explicitly or implicitly specified as described in getCharacterEncoding, the charset parameter is included in the string returned. If no character encoding has been specified, the charset parameter is omitted.
String
specifying the content type, for example, text/html; charset=UTF-8
, or nullImplements servlet::ServletResponse.
Definition at line 97 of file NoBodyResponse.cpp.
References servlet::ServletResponse::getContentType(), and resp.
std::ostream & servlet::NoBodyResponse::getOutputStream | ( | ) | [virtual] |
Returns a std::ostream suitable for writing binary data in the response. The servlet container does not encode the binary data.
Calling flush() on the output stream commits the response.
Either this method or getWriter may be called to write the body, not both.
IllegalStateException | if the getWriter method has been called on this response | |
IOException | if an input or output exception occurred |
Implements servlet::ServletResponse.
Definition at line 104 of file NoBodyResponse.cpp.
References no_body.
bool servlet::NoBodyResponse::isCommitted | ( | ) | [virtual] |
Returns a boolean indicating if the response has been committed. A committed response has already had its status code and headers written.
Implements servlet::ServletResponse.
Definition at line 139 of file NoBodyResponse.cpp.
References servlet::ServletResponse::isCommitted(), and resp.
void servlet::NoBodyResponse::reset | ( | ) | [virtual] |
Clears any data that exists in the buffer as well as the status code and headers. If the response has been committed, this method throws an IllegalStateException
.
IllegalStateException | if the response has already been committed |
Implements servlet::ServletResponse.
Definition at line 132 of file NoBodyResponse.cpp.
References servlet::ServletResponse::reset(), and resp.
void servlet::NoBodyResponse::sendError | ( | int | sc | ) | [virtual] |
Sends an error response to the client using the specified status code and clearing the buffer.
If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.
sc | the error status code |
IOException | If an input or output exception occurs | |
IllegalStateException | If the response was committed before this method call |
Implements servlet::HttpServletResponse.
Definition at line 214 of file NoBodyResponse.cpp.
References resp, and servlet::HttpServletResponse::sendError().
void servlet::NoBodyResponse::sendError | ( | int | sc, | |
const std::string & | msg | |||
) | [virtual] |
Sends an error response to the client using the specified status. The server defaults to creating the response to look like an HTML-formatted server error page containing the specified message, setting the content type to "text/html", leaving cookies and other headers unmodified.
If an error-page declaration has been made for the web application corresponding to the status code passed in, it will be served back in preference to the suggested msg parameter.
If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.
sc | the error status code | |
msg | the descriptive message |
IOException | If an input or output exception occurs | |
IllegalStateException | If the response was committed |
Implements servlet::HttpServletResponse.
Definition at line 207 of file NoBodyResponse.cpp.
References resp, and servlet::HttpServletResponse::sendError().
void servlet::NoBodyResponse::sendRedirect | ( | const std::string & | location | ) | [virtual] |
Sends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root.
If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.
location | the redirect location URL |
IOException | If an input or output exception occurs | |
IllegalStateException | If the response was committed or if a partial URL is given and cannot be converted into a valid URL |
Implements servlet::HttpServletResponse.
Definition at line 221 of file NoBodyResponse.cpp.
References resp, and servlet::HttpServletResponse::sendRedirect().
void servlet::NoBodyResponse::setBufferSize | ( | int | size | ) | [virtual] |
Sets the preferred buffer size for the body of the response. The servlet container will use a buffer at least as large as the size requested. The actual buffer size used can be found using getBufferSize
.
A larger buffer allows more content to be written before anything is actually sent, thus providing the servlet with more time to set appropriate status codes and headers. A smaller buffer decreases server memory load and allows the client to start receiving data more quickly.
This method must be called before any response body content is written; if content has been written or the response object has been committed, this method throws an IllegalStateException
.
size | the preferred buffer size |
IllegalStateException | if this method is called after content has been written |
Implements servlet::ServletResponse.
Definition at line 118 of file NoBodyResponse.cpp.
References resp, and servlet::ServletResponse::setBufferSize().
void servlet::NoBodyResponse::setCharacterEncoding | ( | const std::string & | charset | ) | [virtual] |
Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8. If the character encoding has already been set by setContentType or setLocale, this method overrides it. Calling setContentType with the String
of text/html
and calling this method with the String
of UTF-8
is equivalent with calling setContentType
with the String
of text/html; charset=UTF-8
.
This method can be called repeatedly to change the character encoding. This method has no effect if it is called after getWriter
has been called or after the response has been committed.
Containers must communicate the character encoding used for the servlet response's writer to the client if the protocol provides a way for doing so. In the case of HTTP, the character encoding is communicated as part of the Content-Type
header for text media types. Note that the character encoding cannot be communicated via HTTP headers if the servlet does not specify a content type; however, it is still used to encode text written via the servlet response's writer.
charset | a String specifying only the character set defined by IANA Character Sets (http://www.iana.org/assignments/character-sets) |
Implements servlet::ServletResponse.
Definition at line 83 of file NoBodyResponse.cpp.
References resp, and servlet::ServletResponse::setCharacterEncoding().
void servlet::NoBodyResponse::setContentLength | ( | int | len | ) | [virtual] |
Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.
len | an integer specifying the length of the content being returned to the client; sets the Content-Length header |
Implements servlet::ServletResponse.
Definition at line 75 of file NoBodyResponse.cpp.
References didSetContentLength, resp, and servlet::ServletResponse::setContentLength().
void servlet::NoBodyResponse::setContentLength | ( | ) | [private] |
Definition at line 67 of file NoBodyResponse.cpp.
References didSetContentLength, servlet::onobodystream::get_context_length(), no_body, resp, and servlet::ServletResponse::setContentLength().
Referenced by servlet::HttpServlet::doHead().
void servlet::NoBodyResponse::setContentType | ( | const std::string & | type | ) | [virtual] |
Sets the content type of the response being sent to the client, if the response has not been committed yet. The given content type may include a character encoding specification, for example, text/html;charset=UTF-8
. The response's character encoding is only set from the given content type if this method is called before getWriter
is called.
This method may be called repeatedly to change content type and character encoding. This method has no effect if called after the response has been committed. It does not set the response's character encoding if it is called after getWriter
has been called or after the response has been committed.
Containers must communicate the content type and the character encoding used for the servlet response's writer to the client if the protocol provides a way for doing so. In the case of HTTP, the Content-Type
header is used.
type | a String specifying the MIME type of the content |
getWriter
Implements servlet::ServletResponse.
Definition at line 90 of file NoBodyResponse.cpp.
References resp, and servlet::ServletResponse::setContentType().
void servlet::NoBodyResponse::setDateHeader | ( | const std::string & | name, | |
long | date | |||
) | [virtual] |
Sets a response header with the given name and date-value. The date is specified in terms of milliseconds since the epoch. If the header had already been set, the new value overwrites the previous one. The containsHeader
method can be used to test for the presence of a header before setting its value.
name | the name of the header to set | |
date | the assigned date value |
Implements servlet::HttpServletResponse.
Definition at line 200 of file NoBodyResponse.cpp.
References resp, and servlet::HttpServletResponse::setDateHeader().
void servlet::NoBodyResponse::setHeader | ( | const std::string & | name, | |
const std::string & | value | |||
) | [virtual] |
Sets a response header with the given name and value. If the header had already been set, the new value overwrites the previous one. The containsHeader
method can be used to test for the presence of a header before setting its value.
name | the name of the header | |
value | the header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt) |
Implements servlet::HttpServletResponse.
Definition at line 186 of file NoBodyResponse.cpp.
References resp, and servlet::HttpServletResponse::setHeader().
void servlet::NoBodyResponse::setIntHeader | ( | const std::string & | name, | |
int | value | |||
) | [virtual] |
Sets a response header with the given name and integer value. If the header had already been set, the new value overwrites the previous one. The containsHeader
method can be used to test for the presence of a header before setting its value.
name | the name of the header | |
value | the assigned integer value |
Implements servlet::HttpServletResponse.
Definition at line 193 of file NoBodyResponse.cpp.
References resp, and servlet::HttpServletResponse::setIntHeader().
void servlet::NoBodyResponse::setStatus | ( | int | sc | ) | [virtual] |
Sets the status code for this response. This method is used to set the return status code when there is no error (for example, for the status codes SC_OK or SC_MOVED_TEMPORARILY). If there is an error, and the caller wishes to invoke an error-page defined in the web application, the sendError
method should be used instead.
The container clears the buffer and sets the Location header, preserving cookies and other headers.
sc | the status code |
Implements servlet::HttpServletResponse.
Definition at line 179 of file NoBodyResponse.cpp.
References resp, and servlet::HttpServletResponse::setStatus().
friend class HttpServlet [friend] |
Definition at line 114 of file NoBodyResponse.h.
bool servlet::NoBodyResponse::didSetContentLength [private] |
Definition at line 75 of file NoBodyResponse.h.
Referenced by getOutputStream(), and setContentLength().
HttpServletResponse& servlet::NoBodyResponse::resp [private] |
Definition at line 74 of file NoBodyResponse.h.
Referenced by addCookie(), addDateHeader(), addHeader(), addIntHeader(), containsHeader(), encodeRedirectURL(), encodeURL(), flushBuffer(), getBufferSize(), getCharacterEncoding(), getContentType(), isCommitted(), reset(), sendError(), sendRedirect(), setBufferSize(), setCharacterEncoding(), setContentLength(), setContentType(), setDateHeader(), setHeader(), setIntHeader(), and setStatus().