|
|
|
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
|
|
/* Copyright 2022 Ivan Polyakov */
|
|
|
|
|
|
|
|
#ifndef RAPIDA_REQUEST_HXX_ENTRY
|
|
|
|
#define RAPIDA_REQUEST_HXX_ENTRY
|
|
|
|
|
|
|
|
#include "Query.hxx"
|
|
|
|
#include "request.h"
|
|
|
|
|
|
|
|
namespace rpd {
|
|
|
|
/*!
|
|
|
|
* \brief C++ request wrapper.
|
|
|
|
*/
|
|
|
|
class Request {
|
|
|
|
public:
|
|
|
|
/*!
|
|
|
|
* \brief Constructor.
|
|
|
|
*
|
|
|
|
* Creates C++ wrapper from original C request.
|
|
|
|
*
|
|
|
|
* \param req C request implementation.
|
|
|
|
*/
|
|
|
|
Request(rpd_req *req)
|
|
|
|
{
|
|
|
|
this->req = req;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Gets request method.
|
|
|
|
*
|
|
|
|
* \return Request method.
|
|
|
|
*/
|
|
|
|
rpd_req_methods method() const
|
|
|
|
{
|
|
|
|
return req->method;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Gets requested URL.
|
|
|
|
*
|
|
|
|
* \return Request URL.
|
|
|
|
*/
|
|
|
|
const rpd_url *path() const
|
|
|
|
{
|
|
|
|
return &req->path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Gets query parameters.
|
|
|
|
*
|
|
|
|
* \return Query parameters.
|
|
|
|
*/
|
|
|
|
Query query() const
|
|
|
|
{
|
|
|
|
return &req->query;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Gets URL parameters.
|
|
|
|
*
|
|
|
|
* If you specify route like <b>/some/:dynamic/route</b>,
|
|
|
|
* middle route segment can be accesed by the _dynamic_ key.
|
|
|
|
*
|
|
|
|
* \return URL parameters as key-value pairs.
|
|
|
|
*/
|
|
|
|
KeyVal params() const
|
|
|
|
{
|
|
|
|
return &req->params;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Gets the request header.
|
|
|
|
*
|
|
|
|
* \params key Header key.
|
|
|
|
*
|
|
|
|
* \return Found header or NULL.
|
|
|
|
*/
|
|
|
|
const char *header(const char *key) const;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Gets all request headers.
|
|
|
|
*
|
|
|
|
* \return Key-value pairs.
|
|
|
|
*/
|
|
|
|
KeyVal headers() const
|
|
|
|
{
|
|
|
|
return &req->headers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Gets request body content.
|
|
|
|
*
|
|
|
|
* \return Body content.
|
|
|
|
*/
|
|
|
|
const char *body() const
|
|
|
|
{
|
|
|
|
return req->body;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Destructor.
|
|
|
|
*/
|
|
|
|
virtual ~Request() { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
rpd_req *req; //< Composition with C implementation.
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // RAPIDA_REQUEST_HXX_ENTRY
|