libzeep

PrevUpHomeNext

Request and Reply

An implementation of the HTTP standard will need various data types. There are HTTP requests and HTTP replies. And these contain HTTP headers but the method specifier (which was changed to a std::string in a recent update to libzeep).

The HTTP specification for request and reply are sufficiently similar to allow for a common message parsing class. The parser for requests supports chunked transfer encoding.

request

The request encapsulates what was received. The standard HTTP request contains a method, like GET or POST. In this version of libzeep only a limited subset of methods are supported.

The next part is the uri that was requested.

Then we have the version, usually 1.0 or 1.1. Libzeep does not currently support anything else. When 1.1 was used, libzeep will honour the keep-alive flag.

Headers are stored in an array and can be accessed using get_header.

Cookies stored in the headers can be accessed using get_cookie.

A request may also contain a payload, usually only in case of a POST or PUT.

Requests can have parameters. These can be passed url-encoded in the uri, or they can be encoded in the payload using application/x-www-form-urlencoded or multipart/form-data encoding. The various get_parameter members allow retrieving these parameters by name, optinally passing in a default value in case the parameter was not part of the request.

A special case are file parameters, these are retrieved using get_file_parameter. This returns a file_param struct that contains information about the uploaded file. Using the char_streambuf class you can efficiently read the contents of such a file:

zeep::file_param f = req.get_file_parameter("upoad");
zeep::char_streambuf sb(f.data, f.length);
std::istream is(&sb);

Many other convenience accessors are available but data is also directly accessible since this is a struct.

There are some functions to set data. Those are probably only useful if you write your own code to send out HTTP requests to other servers.

reply

The reply object is the object you need to fill in. Replies contain a status line, headers and optionally a payload.

There is a static member called stock_reply that allows you to create a complete reply from a status code and an optional message.

The set_header and set_cookie member functions take care of setting headers and cookies respectively.

The content of the payload can be set using the various set_content methods. They will set the content type header according to the data passed in. If you specify a std::istream* as content, and the version is set to 1.1 then the data stream will be sent in chunked transfer-encoding.


PrevUpHomeNext