libcex  1.0.0
Modern C++11 embedded webserver library
Public Member Functions | Public Attributes | Friends | List of all members
cex::Request Class Reference

Contains the current request and all of its preparsed properties. More...

#include <core.hpp>

Public Member Functions

 Request (evhtp_request *req)
 Constructs a new Response object. More...
 
Method getMethod ()
 Returns the request's HTTP method.
 
Protocol getProtocol ()
 Returns the HTTP protocol version (1.0 or 1.1)
 
int getPort ()
 Returns the port, if present in the URI.
 
const char * getHost ()
 Returns the hostname of the request.
 
const char * getUrl ()
 Returns the full URL of the request.
 
const char * getPath ()
 Returns the path-portion of the URL of the request.
 
const char * getFile ()
 Returns the file-portion of the URL of the request.
 
const char * getMiddlewarePath ()
 
void eachHeader (PairCallbackFunction cb)
 Iterates all HTTP headers of the request with the given callback function. More...
 
const char * get (const char *name)
 Returns the value of a HTTP header. More...
 
void eachQueryParam (PairCallbackFunction cb)
 Iterates all URL query parameters of the request with the given callback function. More...
 
const char * getQueryParam (const char *name)
 Returns the value of a URL query parameter. More...
 
const char * getBody ()
 
size_t getBodyLength ()
 

Public Attributes

PropertyList properties
 A list of properties of the current request. More...
 

Friends

class Server
 
class Response
 
class Middleware
 

Detailed Description

Contains the current request and all of its preparsed properties.

Contains several accessor methods for retrieving header information, URL parameters or request bodies.

Example:

app.use("/content", [](cex::Request* req, cex::Response* res, std::function<void()> next)
{
printf("Protocol: [%d], Method [%d], port [%d], host [%s], url [%s], path [%s], file [%s], user [%s], password [%s]\n",
req->getProtocol(),
req->getMethod(),
req->getPort(),
req->getHost(),
req->getUrl(),
req->getPath(),
req->getFile(),
req->properties.getString("basicUsername").c_str(), req->properties.getString("basicPassword").c_str());
req->eachQueryParam([](const char* key, const char* value)
{
printf("PARAM: [%s] = [%s]\n", key, value);
return true;
});
const char* body= req->getBody();
res->end(200);
});

Constructor & Destructor Documentation

◆ Request()

cex::Request::Request ( evhtp_request *  req)

Constructs a new Response object.

Parameters
reqThe underlying libevhtp request object

Member Function Documentation

◆ eachHeader()

void cex::Request::eachHeader ( PairCallbackFunction  cb)

Iterates all HTTP headers of the request with the given callback function.

Parameters
cbA PairCallbackFunction which is called for each header. If the callback function returns true, iteration is stopped.

◆ eachQueryParam()

void cex::Request::eachQueryParam ( PairCallbackFunction  cb)

Iterates all URL query parameters of the request with the given callback function.

Parameters
cbA PairCallbackFunction which is called for each parameter. If the callback function returns true, iteration is stopped.

◆ get()

const char * cex::Request::get ( const char *  name)

Returns the value of a HTTP header.

Parameters
nameName of the HTTP header to retrieve

◆ getBody()

const char * cex::Request::getBody ( )

Returns the RAW body contents of the request (unparsed, can be binary data)

◆ getBodyLength()

size_t cex::Request::getBodyLength ( )

Returns the length of RAW body contents (number of bytes)

◆ getMiddlewarePath()

const char * cex::Request::getMiddlewarePath ( )

Returns the path of the currently matched Middleware

◆ getQueryParam()

const char * cex::Request::getQueryParam ( const char *  name)

Returns the value of a URL query parameter.

Parameters
nameName of the parameter to retrieve

Member Data Documentation

◆ properties

PropertyList cex::Request::properties

A list of properties of the current request.

Some properties are filled by libcex:

  • basicUsername - The username, if the request was made with HTTP basic authentication
  • basicPassword - The password, if the request was made with HTTP basic authentication
  • [sessionid] - The session ID of the current request. Its created by the cex::sessionHandler middleware function, and the name of the property corresponds to the name of the cookie/sessionID as given in the middleware options

The documentation for this class was generated from the following files: