class EE::Network::Http::Response

Overview

Define a HTTP response. More…

#include <http.hpp>

class Response {
public:
    // typedefs

    typedef std::map<std::string, std::string> FieldTable;

    // enums

    enum Status;

    // methods

    static const char* statusToString(const Status& status);
    static Status intAsStatus(const int& value);
    static Response createFakeResponse(const FieldTable& fields, Status& status, const std::string& body, unsigned int majorVersion = 1, unsigned int minorVersion = 1);
    FieldTable getHeaders();
    const std::string& getField(const std::string& field) const;
    bool hasField(const std::string& field) const;
    Status getStatus() const;
    const char* getStatusDescription() const;
    unsigned int getMajorHttpVersion() const;
    unsigned int getMinorHttpVersion() const;
    const std::string& getBody() const;
};

Detailed Documentation

Define a HTTP response.

Methods

static const char* statusToString(const Status& status)

Returns:

The status string

static Status intAsStatus(const int& value)

Returns:

True if the value is a valid Status

static Response createFakeResponse(const FieldTable& fields, Status& status, const std::string& body, unsigned int majorVersion = 1, unsigned int minorVersion = 1)

Creates a faked response. Useful for testing.

const std::string& getField(const std::string& field) const

Get the value of a field If the field field is not found in the response header, the empty string is returned. This function uses case-insensitive comparisons.

Parameters:

field

Name of the field to get

Returns:

Value of the field, or empty string if not found

bool hasField(const std::string& field) const

Returns:

If the field is found in the response headers.

Status getStatus() const

Get the response status code The status code should be the first thing to be checked after receiving a response, it defines whether it is a success, a failure or anything else (see the Status enumeration).

Returns:

Status code of the response

const char* getStatusDescription() const

Get the response status description.

unsigned int getMajorHttpVersion() const

Get the major HTTP version number of the response.

Returns:

Major HTTP version number

See also:

GetMinorHttpVersion

unsigned int getMinorHttpVersion() const

Get the minor HTTP version number of the response.

Returns:

Minor HTTP version number

See also:

GetMajorHttpVersion

const std::string& getBody() const

Get the body of the response The body of a response may contain:

  • the requested page (for GET requests)

  • a response from the server (for POST requests)

  • nothing (for HEAD requests)

  • an error message (in case of an error)

Returns:

The response body