class Poco::Net::HTTPServerResponseImpl

Overview

This subclass of HTTPServerResponse is used for representing server-side HTTP responses. More…

#include <HTTPServerResponseImpl.h>

class HTTPServerResponseImpl: public Poco::Net::HTTPServerResponse
{
public:
    // construction

    HTTPServerResponseImpl(HTTPServerSession& session);

    // methods

    virtual
    void
    sendContinue();

    virtual
    std::ostream&
    send();

    virtual
    void
    sendFile(
        const std::string& path,
        const std::string& mediaType
        );

    virtual
    void
    sendBuffer(
        const void* pBuffer,
        std::size_t length
        );

    virtual
    void
    redirect(
        const std::string& uri,
        HTTPStatus status = HTTP_FOUND
        );

    virtual
    void
    requireAuthentication(const std::string& realm);

    virtual
    bool
    sent() const;

protected:
    // methods

    void
    attachRequest(HTTPServerRequestImpl* pRequest);
};

Inherited Members

public:
    // typedefs

    typedef Poco::ListMap<std::string, std::string> HeaderMap;
    typedef HeaderMap::Iterator Iterator;
    typedef HeaderMap::ConstIterator ConstIterator;

    // enums

    enum HTTPStatus;

    // fields

    static const std::string HTTP_1_0;
    static const std::string HTTP_1_1;
    static const std::string IDENTITY_TRANSFER_ENCODING;
    static const std::string CHUNKED_TRANSFER_ENCODING;
    static const int UNKNOWN_CONTENT_LENGTH;
    static const std::string UNKNOWN_CONTENT_TYPE;
    static const std::string CONTENT_LENGTH;
    static const std::string CONTENT_TYPE;
    static const std::string TRANSFER_ENCODING;
    static const std::string CONNECTION;
    static const std::string CONNECTION_KEEP_ALIVE;
    static const std::string CONNECTION_CLOSE;
    static const std::string EMPTY;
    static const std::string HTTP_REASON_CONTINUE;
    static const std::string HTTP_REASON_SWITCHING_PROTOCOLS;
    static const std::string HTTP_REASON_OK;
    static const std::string HTTP_REASON_CREATED;
    static const std::string HTTP_REASON_ACCEPTED;
    static const std::string HTTP_REASON_NONAUTHORITATIVE;
    static const std::string HTTP_REASON_NO_CONTENT;
    static const std::string HTTP_REASON_RESET_CONTENT;
    static const std::string HTTP_REASON_PARTIAL_CONTENT;
    static const std::string HTTP_REASON_MULTIPLE_CHOICES;
    static const std::string HTTP_REASON_MOVED_PERMANENTLY;
    static const std::string HTTP_REASON_FOUND;
    static const std::string HTTP_REASON_SEE_OTHER;
    static const std::string HTTP_REASON_NOT_MODIFIED;
    static const std::string HTTP_REASON_USEPROXY;
    static const std::string HTTP_REASON_TEMPORARY_REDIRECT;
    static const std::string HTTP_REASON_BAD_REQUEST;
    static const std::string HTTP_REASON_UNAUTHORIZED;
    static const std::string HTTP_REASON_PAYMENT_REQUIRED;
    static const std::string HTTP_REASON_FORBIDDEN;
    static const std::string HTTP_REASON_NOT_FOUND;
    static const std::string HTTP_REASON_METHOD_NOT_ALLOWED;
    static const std::string HTTP_REASON_NOT_ACCEPTABLE;
    static const std::string HTTP_REASON_PROXY_AUTHENTICATION_REQUIRED;
    static const std::string HTTP_REASON_REQUEST_TIMEOUT;
    static const std::string HTTP_REASON_CONFLICT;
    static const std::string HTTP_REASON_GONE;
    static const std::string HTTP_REASON_LENGTH_REQUIRED;
    static const std::string HTTP_REASON_PRECONDITION_FAILED;
    static const std::string HTTP_REASON_REQUESTENTITYTOOLARGE;
    static const std::string HTTP_REASON_REQUESTURITOOLONG;
    static const std::string HTTP_REASON_UNSUPPORTEDMEDIATYPE;
    static const std::string HTTP_REASON_REQUESTED_RANGE_NOT_SATISFIABLE;
    static const std::string HTTP_REASON_EXPECTATION_FAILED;
    static const std::string HTTP_REASON_INTERNAL_SERVER_ERROR;
    static const std::string HTTP_REASON_NOT_IMPLEMENTED;
    static const std::string HTTP_REASON_BAD_GATEWAY;
    static const std::string HTTP_REASON_SERVICE_UNAVAILABLE;
    static const std::string HTTP_REASON_GATEWAY_TIMEOUT;
    static const std::string HTTP_REASON_VERSION_NOT_SUPPORTED;
    static const std::string HTTP_REASON_UNKNOWN;
    static const std::string DATE;
    static const std::string SET_COOKIE;

    // methods

    NameValueCollection&
    operator=(const NameValueCollection& nvc);

    void
    swap(NameValueCollection& nvc);

    const std::string&
    operator[](const std::string& name) const;

    void
    set(
        const std::string& name,
        const std::string& value
        );

    void
    add(
        const std::string& name,
        const std::string& value
        );

    const std::string&
    get(const std::string& name) const;

    const std::string&
    get(
        const std::string& name,
        const std::string& defaultValue
        ) const;

    bool
    has(const std::string& name) const;

    ConstIterator
    find(const std::string& name) const;

    ConstIterator
    begin() const;

    ConstIterator
    end() const;

    bool
    empty() const;

    std::size_t
    size() const;

    void
    erase(const std::string& name);

    void
    clear();

    MessageHeader&
    operator=(const MessageHeader& messageHeader);

    virtual
    void
    write(std::ostream& ostr) const;

    virtual
    void
    read(std::istream& istr);

    int
    getFieldLimit() const;

    void
    setFieldLimit(int limit);

    bool
    hasToken(
        const std::string& fieldName,
        const std::string& token
        ) const;

    static
    void
    splitElements(
        const std::string& s,
        std::vector<std::string>& elements,
        bool ignoreEmpty = true
        );

    static
    void
    splitParameters(
        const std::string& s,
        std::string& value,
        NameValueCollection& parameters
        );

    static
    void
    splitParameters(
        const std::string::const_iterator& begin,
        const std::string::const_iterator& end,
        NameValueCollection& parameters
        );

    static
    void
    quote(
        const std::string& value,
        std::string& result,
        bool allowSpace = false
        );

    void
    setVersion(const std::string& version);

    const std::string&
    getVersion() const;

    void
    setContentLength(std::streamsize length);

    std::streamsize
    getContentLength() const;

    bool
    hasContentLength() const;

    void
    setTransferEncoding(const std::string& transferEncoding);

    const std::string&
    getTransferEncoding() const;

    void
    setChunkedTransferEncoding(bool flag);

    bool
    getChunkedTransferEncoding() const;

    void
    setContentType(const std::string& mediaType);

    void
    setContentType(const MediaType& mediaType);

    const std::string&
    getContentType() const;

    void
    setKeepAlive(bool keepAlive);

    bool
    getKeepAlive() const;

    void
    setStatus(HTTPStatus status);

    HTTPStatus
    getStatus() const;

    void
    setStatus(const std::string& status);

    void
    setReason(const std::string& reason);

    const std::string&
    getReason() const;

    void
    setStatusAndReason(
        HTTPStatus status,
        const std::string& reason
        );

    void
    setStatusAndReason(HTTPStatus status);

    void
    setDate(const Poco::Timestamp& dateTime);

    Poco::Timestamp
    getDate() const;

    void
    addCookie(const HTTPCookie& cookie);

    void
    getCookies(std::vector<HTTPCookie>& cookies) const;

    virtual
    void
    write(std::ostream& ostr) const;

    virtual
    void
    read(std::istream& istr);

    static
    const std::string&
    getReasonForStatus(HTTPStatus status);

    virtual
    void
    sendContinue() = 0;

    virtual
    std::ostream&
    send() = 0;

    virtual
    void
    sendFile(
        const std::string& path,
        const std::string& mediaType
        ) = 0;

    virtual
    void
    sendBuffer(
        const void* pBuffer,
        std::size_t length
        ) = 0;

    virtual
    void
    redirect(
        const std::string& uri,
        HTTPStatus status = HTTP_FOUND
        ) = 0;

    virtual
    void
    requireAuthentication(const std::string& realm) = 0;

    virtual
    bool
    sent() const = 0;

Detailed Documentation

This subclass of HTTPServerResponse is used for representing server-side HTTP responses.

A HTTPServerResponse is passed to the handleRequest() method of HTTPRequestHandler.

handleRequest() must set a status code and optional reason phrase, set headers as necessary, and provide a message body.

Construction

HTTPServerResponseImpl(HTTPServerSession& session)

Creates the HTTPServerResponseImpl.

Methods

virtual
void
sendContinue()

Sends a 100 Continue response to the client.

virtual
std::ostream&
send()

Sends the response header to the client and returns an output stream for sending the response body.

The returned stream is valid until the response object is destroyed.

Must not be called after sendFile(), sendBuffer() or redirect() has been called.

virtual
void
sendFile(
    const std::string& path,
    const std::string& mediaType
    )

Sends the response header to the client, followed by the content of the given file.

Must not be called after send(), sendBuffer() or redirect() has been called.

Throws a FileNotFoundException if the file cannot be found, or an OpenFileException if the file cannot be opened.

virtual
void
sendBuffer(
    const void* pBuffer,
    std::size_t length
    )

Sends the response header to the client, followed by the contents of the given buffer.

The Content-Length header of the response is set to length and chunked transfer encoding is disabled.

If both the HTTP message header and body (from the given buffer) fit into one single network packet, the complete response can be sent in one network packet.

Must not be called after send(), sendFile() or redirect() has been called.

virtual
void
redirect(
    const std::string& uri,
    HTTPStatus status = HTTP_FOUND
    )

Sets the status code, which must be one of HTTP_MOVED_PERMANENTLY (301), HTTP_FOUND (302), or HTTP_SEE_OTHER (303), and sets the “Location” header field to the given URI, which according to the HTTP specification, must be absolute.

Must not be called after send() has been called.

virtual
void
requireAuthentication(const std::string& realm)

Sets the status code to 401 (Unauthorized) and sets the “WWW-Authenticate” header field according to the given realm.

virtual
bool
sent() const

Returns true if the response (header) has been sent.