• HttpReply
  • HttpReply Class

    (nymeaserver::HttpReply)

    Represents a reply of the nymea webserver to a HttpRequest. More...

    Header: #include <HttpReply>
    Inherits:

    Public Types

    enum HttpHeaderType { ContentTypeHeader, ContentLenghtHeader, ConnectionHeader, LocationHeader, ..., ServerHeader }
    enum HttpStatusCode { Ok, Created, Accepted, NoContent, ..., HttpVersionNotSupported }
    enum Type { TypeSync, TypeAsync }

    Public Functions

    HttpReply(QObject * parent = 0)
    HttpReply(const HttpStatusCode & statusCode = HttpStatusCode::Ok, const Type & type = TypeSync, QObject * parent = 0)
    void clear()
    QUuid clientId() const
    bool closeConnection() const
    QByteArray data() const
    QByteArray httpReasonPhrase() const
    HttpStatusCode httpStatusCode() const
    bool isEmpty() const
    void packReply()
    QByteArray payload() const
    QByteArray rawHeader() const
    QHash<QByteArray, QByteArray> rawHeaderList() const
    void setClientId(const QUuid & clientId)
    void setCloseConnection(const bool & close)
    void setHeader(const HttpHeaderType & headerType, const QByteArray & value)
    void setHttpStatusCode(const HttpStatusCode & statusCode)
    void setPayload(const QByteArray & data)
    void setRawHeader(const QByteArray headerType, const QByteArray & value)
    bool timedOut() const
    Type type() const

    Public Slots

    void startWait()

    Signals

    void finished()

    Detailed Description

    Represents a reply of the nymea webserver to a HttpRequest.

    This class holds the header and the payload data of a network reply and represents a response from the nymea webserver to a HttpRequest.

    Note: RFC 7231 HTTP/1.1 Semantics and Content -> http://tools.ietf.org/html/rfc7231

    Member Type Documentation

    enum HttpReply::HttpHeaderType

    This enum type specifies the known type of a header in a HTTP webserver reply. You can find more information here: http://tools.ietf.org/html/rfc7231#section-5

    ConstantValueDescription
    nymeaserver::HttpReply::ContentTypeHeader0The content type header i.e. application/json.
    nymeaserver::HttpReply::ContentLenghtHeader1The length of the sent content.
    nymeaserver::HttpReply::ConnectionHeader2The connection header.
    nymeaserver::HttpReply::LocationHeader3The location header.
    nymeaserver::HttpReply::UserAgentHeader4The user agent of the client.
    nymeaserver::HttpReply::CacheControlHeader5The cache control header.
    nymeaserver::HttpReply::AllowHeader6The allowed methods header.
    nymeaserver::HttpReply::DateHeader7The server date header.
    nymeaserver::HttpReply::ServerHeader8The name of the server i.e. "Server: nymea/0.6.0"

    enum HttpReply::HttpStatusCode

    This enum type specifies the status code of a HTTP webserver reply.

    You can find more information here: http://tools.ietf.org/html/rfc7231#section-6.1

    ConstantValueDescription
    nymeaserver::HttpReply::Ok200The request was understood and everything is Ok.
    nymeaserver::HttpReply::Created201The resource was created successfully.
    nymeaserver::HttpReply::Accepted202The resource was accepted.
    nymeaserver::HttpReply::NoContent204The request has no content but it was expected.
    nymeaserver::HttpReply::Found302The resource was found.
    nymeaserver::HttpReply::PermanentRedirect308The resource redirects permanent to given url.
    nymeaserver::HttpReply::BadRequest400The request was bad formatted. Also if a Param was not understood or the header is not correct.
    nymeaserver::HttpReply::Forbidden403The request tries to get access to a forbidden space.
    nymeaserver::HttpReply::NotFound404The requested resource could not be found.
    nymeaserver::HttpReply::MethodNotAllowed405The request method is not allowed. See "Allowed-Methods" header for the allowed methods.
    nymeaserver::HttpReply::RequestTimeout408The request method timed out. Default timeout = 5s.
    nymeaserver::HttpReply::Conflict409The request resource conflicts with an other.
    nymeaserver::HttpReply::InternalServerError500There was an internal server error.
    nymeaserver::HttpReply::NotImplemented501The requestet method call is not implemented.
    nymeaserver::HttpReply::BadGateway502The gateway is not correct.
    nymeaserver::HttpReply::ServiceUnavailable503The service is not available at the moment.
    nymeaserver::HttpReply::GatewayTimeout504The gateway timed out.
    nymeaserver::HttpReply::HttpVersionNotSupported505The HTTP version is not supported. The only supported version is HTTP/1.1.

    enum HttpReply::Type

    This enum type describes the type of this HttpReply. There are two types:

    ConstantValueDescription
    nymeaserver::HttpReply::TypeSync0The HttpReply can be responded imediatly.
    nymeaserver::HttpReply::TypeAsync1The HttpReply is asynchron and has to be responded later.

    Member Function Documentation

    HttpReply::HttpReply(QObject * parent = 0)

    Construct an empty HttpReply with the given parent.

    HttpReply::HttpReply(const HttpStatusCode & statusCode = HttpStatusCode::Ok, const Type & type = TypeSync, QObject * parent = 0)

    Construct a HttpReply with the given statusCode, type and parent.

    void HttpReply::clear()

    Clears all data of this HttpReply.

    QUuid HttpReply::clientId() const

    Returns the clientId of this HttpReply.

    See also setClientId().

    bool HttpReply::closeConnection() const

    Returns the connection close parameter of this HttpReply. If close is true, the connection of the client will be closed after this reply was sent.

    See also setCloseConnection().

    QByteArray HttpReply::data() const

    Returns the current raw data (header + payload) of this HttpReply.

    [signal] void HttpReply::finished()

    This signal is emitted when this async HttpReply is finished.

    QByteArray HttpReply::httpReasonPhrase() const

    Returns the error code reason phrase for the current HttpStatusCode.

    HttpStatusCode HttpReply::httpStatusCode() const

    Returns the status code of this HttpReply.

    See also setHttpStatusCode().

    bool HttpReply::isEmpty() const

    Returns true if the raw header and the payload of this HttpReply is empty.

    void HttpReply::packReply()

    Packs the whole reply data of this HttpReply. The data can be accessed with HttpReply::data().

    See also data().

    QByteArray HttpReply::payload() const

    Returns the payload of this HttpReply.

    See also setPayload().

    QByteArray HttpReply::rawHeader() const

    Returns the raw headers of this HttpReply.

    Note: The header will be empty until the method packReply() was called.

    See also setRawHeader() and packReply().

    QHash<QByteArray, QByteArray> HttpReply::rawHeaderList() const

    Returns the list of all set headers in this HttpReply.

    void HttpReply::setClientId(const QUuid & clientId)

    Set the clientId of this HttpReply.

    See also clientId().

    void HttpReply::setCloseConnection(const bool & close)

    Sets the close parameter of this HttpReply. If close is true, the connection of the client will be closed after this reply was sent.

    See also closeConnection().

    void HttpReply::setHeader(const HttpHeaderType & headerType, const QByteArray & value)

    This method appends a known header to the header list of this HttpReply. The Header will be set to headerType : value.

    void HttpReply::setHttpStatusCode(const HttpStatusCode & statusCode)

    Set the HttpStatusCode of this HttpReply to the given statusCode.

    See also httpStatusCode().

    void HttpReply::setPayload(const QByteArray & data)

    Set the payload of this HttpReply to the given data.

    See also payload().

    void HttpReply::setRawHeader(const QByteArray headerType, const QByteArray & value)

    This method appends a raw header to the header list of this HttpReply. The Header will be set to headerType : value.

    See also rawHeader().

    [slot] void HttpReply::startWait()

    Starts the timer for an async HttpReply.

    See also finished().

    bool HttpReply::timedOut() const

    Return true if the response took to long for the request.

    Type HttpReply::type() const

    Returns the type of this HttpReply.

    See also Type.