drogon
C++14/17-based HTTP application framework
Loading...
Searching...
No Matches
drogon Namespace Reference

Drogon Test is a minimal effort test framework developed because the major C++ test frameworks doesn't handle async programs well. Drogon Test's syntax is inspired by both Google Test and Catch2. More...

Classes

class  Attributes
 This class represents the attributes stored in the HTTP request. One can add/get any type of data to/from an Attributes object. More...
class  CallbackEntry
 A utility class for CacheMap. More...
class  CacheMap
 Cache Map. More...
 this class represents a cookie entity. More...
class  DrClassMap
 A map class which can create DrObjects from names. More...
class  DrObjectBase
 The base class for all drogon reflection classes. More...
struct  isAutoCreationClass
class  DrObject
class  DrTemplate
class  DrTemplateBase
 The templating engine class. More...
class  HttpAppFramework
class  HttpClient
 Asynchronous http client. More...
class  HttpControllerBase
 The base class for HTTP controllers. More...
class  HttpController
 The reflection base class template for HTTP controllers. More...
class  HttpFilterBase
 The abstract base class for filters For more details on the class, see the wiki site (the 'Filter' section). More...
class  HttpFilter
 The reflection base class template for filters. More...
class  HttpMiddlewareBase
 The abstract base class for middleware. More...
class  HttpMiddleware
 The reflection base class template for middlewares. More...
class  HttpOptionsMiddlewareImpl
 Simple middleware that tags OPTIONS requests. More...
class  HttpOptionsMiddlewareAuto
class  HttpOptionsMiddleware
class  HttpRequest
 Abstract class for webapp developer to get or set the Http request;. More...
struct  MultipartHeader
class  RequestStream
class  StreamError
class  RequestStreamReader
class  ResponseStream
class  HttpResponse
class  HttpSimpleControllerBase
 The abstract base class for HTTP simple controllers. More...
class  HttpSimpleController
 The reflection base class template for HTTP simple controllers. More...
class  HttpViewData
 This class represents the data set displayed in views. More...
class  IntranetIpFilter
 A filter that prohibit access from external networks. More...
class  IOThreadStorage
 Utility class for thread storage handling. More...
class  LocalHostFilter
 A filter that prohibit access from other hosts. More...
class  HttpFile
 This class represents a uploaded file by a HTTP request. More...
class  MultiPartParser
class  NotFound
 This class is used by the drogon to generate the 404 page. Users don't use this class directly. More...
class  Session
 This class represents a session stored in the framework. One can get or set any type of data to a session object. More...
class  UploadFile
class  WebSocketClient
 WebSocket client abstract class. More...
class  WebSocketConnection
 The WebSocket connection abstract class. More...
class  WebSocketControllerBase
 The abstract base class for WebSocket controllers. More...
class  WebSocketController
 The reflection base class template for WebSocket controllers. More...
class  Topic
 This class template presents an unnamed topic. More...
class  PubSubService
 This class template implements a publish-subscribe pattern with multiple named topics. More...
class  RateLimiter
 This class is used to limit the number of requests per second. More...
class  SafeRateLimiter
struct  await_result
struct  is_awaitable
struct  is_awaitable< T, std::void_t< decltype(internal::getAwaiter(std::declval< T >()))> >
struct  final_awaiter
 An awaiter for Task::promise_type::final_suspend(). Transfer execution back to the coroutine who is co_awaiting this Task. More...
struct  task_awaiter
 Convert Task to an awaiter when it is co_awaited. Following things will happen: More...
struct  Task
struct  Task< void >
struct  AsyncTask
struct  CallbackAwaiter
struct  CallbackAwaiter< void >
struct  is_resumable
struct  is_resumable< T, std::void_t< decltype(internal::getAwaiter(std::declval< T >()))> >
struct  is_resumable< AsyncTask, std::void_t< AsyncTask > >
class  Mutex
class  OStringStream
class  PluginBase
 The abstract base class for plugins. More...
struct  IsPlugin
class  Plugin
 The reflection base class for plugins. More...
class  RestfulController
 this class is a helper class for the implementation of restful api controllers generated by the drogon_ctl command. More...

Typedefs

using AttributesPtr = std::shared_ptr<Attributes>
using CallbackEntryPtr = std::shared_ptr<CallbackEntry>
using WeakCallbackEntryPtr = std::weak_ptr<CallbackEntry>
using CallbackBucket = std::unordered_set<CallbackEntryPtr>
using CallbackBucketQueue = std::deque<CallbackBucket>
using DrAllocFunc = std::function<DrObjectBase *()>
using DrSharedAllocFunc = std::function<std::shared_ptr<DrObjectBase>()>
using DrTemplateData = HttpViewData
using ExceptionHandler
using DefaultHandler
using HttpHandlerInfo = std::tuple<std::string, HttpMethod, std::string>
using HttpClientPtr = std::shared_ptr<HttpClient>
using HttpRequestPtr = std::shared_ptr<HttpRequest>
using RequestStreamReaderPtr = std::shared_ptr<RequestStreamReader>
using RequestStreamPtr = std::shared_ptr<RequestStream>
using HttpResponsePtr = std::shared_ptr<HttpResponse>
using ResponseStreamPtr = std::unique_ptr<ResponseStream>
using FileUpload = MultiPartParser
 In order to be compatible with old interfaces.
using SessionPtr = std::shared_ptr<Session>
using WebSocketClientPtr = std::shared_ptr<WebSocketClient>
using WebSocketRequestCallback
using WebSocketConnectionPtr = std::shared_ptr<WebSocketConnection>
using WebSocketControllerBasePtr = std::shared_ptr<WebSocketControllerBase>
using AdviceCallback = std::function<void(const HttpResponsePtr &)>
using AdviceChainCallback = std::function<void()>
using AdviceStartSessionCallback = std::function<void(const std::string &)>
using AdviceDestroySessionCallback = std::function<void(const std::string &)>
using FilterCallback = std::function<void(const HttpResponsePtr &)>
using FilterChainCallback = std::function<void()>
using HttpReqCallback = std::function<void(ReqResult, const HttpResponsePtr &)>
using MiddlewareCallback = std::function<void(const HttpResponsePtr &)>
using MiddlewareNextCallback
using SubscriberID = uint64_t
using RateLimiterPtr = std::shared_ptr<RateLimiter>
template<typename T>
using await_result_t = typename await_result<T>::type
template<typename T>
using SafeStringMap

Enumerations

enum class  StreamErrorCode { kNone = 0 , kBadRequest , kConnectionBroken }
enum  HttpStatusCode {
  kUnknown = 0 , k100Continue = 100 , k101SwitchingProtocols = 101 , k102Processing = 102 ,
  k103EarlyHints = 103 , k200OK = 200 , k201Created = 201 , k202Accepted = 202 ,
  k203NonAuthoritativeInformation = 203 , k204NoContent = 204 , k205ResetContent = 205 , k206PartialContent = 206 ,
  k207MultiStatus = 207 , k208AlreadyReported = 208 , k226IMUsed = 226 , k300MultipleChoices = 300 ,
  k301MovedPermanently = 301 , k302Found = 302 , k303SeeOther = 303 , k304NotModified = 304 ,
  k305UseProxy = 305 , k306Unused = 306 , k307TemporaryRedirect = 307 , k308PermanentRedirect = 308 ,
  k400BadRequest = 400 , k401Unauthorized = 401 , k402PaymentRequired = 402 , k403Forbidden = 403 ,
  k404NotFound = 404 , k405MethodNotAllowed = 405 , k406NotAcceptable = 406 , k407ProxyAuthenticationRequired = 407 ,
  k408RequestTimeout = 408 , k409Conflict = 409 , k410Gone = 410 , k411LengthRequired = 411 ,
  k412PreconditionFailed = 412 , k413RequestEntityTooLarge = 413 , k414RequestURITooLarge = 414 , k415UnsupportedMediaType = 415 ,
  k416RequestedRangeNotSatisfiable = 416 , k417ExpectationFailed = 417 , k418ImATeapot = 418 , k421MisdirectedRequest = 421 ,
  k422UnprocessableEntity = 422 , k423Locked = 423 , k424FailedDependency = 424 , k425TooEarly = 425 ,
  k426UpgradeRequired = 426 , k428PreconditionRequired = 428 , k429TooManyRequests = 429 , k431RequestHeaderFieldsTooLarge = 431 ,
  k451UnavailableForLegalReasons = 451 , k500InternalServerError = 500 , k501NotImplemented = 501 , k502BadGateway = 502 ,
  k503ServiceUnavailable = 503 , k504GatewayTimeout = 504 , k505HTTPVersionNotSupported = 505 , k506VariantAlsoNegotiates = 506 ,
  k507InsufficientStorage = 507 , k508LoopDetected = 508 , k510NotExtended = 510 , k511NetworkAuthenticationRequired = 511
}
enum class  Version { kUnknown = 0 , kHttp10 , kHttp11 }
enum  ContentType {
  CT_NONE = 0 , CT_APPLICATION_JSON , CT_TEXT_PLAIN , CT_TEXT_HTML ,
  CT_APPLICATION_X_FORM , CT_APPLICATION_X_JAVASCRIPT , CT_TEXT_JAVASCRIPT , CT_TEXT_CSS ,
  CT_TEXT_CSV , CT_TEXT_XML , CT_APPLICATION_XML , CT_TEXT_XSL ,
  CT_APPLICATION_WASM , CT_APPLICATION_OCTET_STREAM , CT_APPLICATION_FONT_WOFF , CT_APPLICATION_FONT_WOFF2 ,
  CT_APPLICATION_GZIP , CT_APPLICATION_JAVA_ARCHIVE , CT_APPLICATION_PDF , CT_APPLICATION_MSWORD ,
  CT_APPLICATION_MSWORDX , CT_APPLICATION_VND_MS_FONTOBJ , CT_APPLICATION_VND_RAR , CT_APPLICATION_XHTML ,
  CT_APPLICATION_X_7Z , CT_APPLICATION_X_BZIP , CT_APPLICATION_X_BZIP2 , CT_APPLICATION_X_HTTPD_PHP ,
  CT_APPLICATION_X_FONT_TRUETYPE , CT_APPLICATION_X_FONT_OPENTYPE , CT_APPLICATION_X_TAR , CT_APPLICATION_X_TGZ ,
  CT_APPLICATION_X_XZ , CT_APPLICATION_ZIP , CT_AUDIO_AAC , CT_AUDIO_AC3 ,
  CT_AUDIO_AIFF , CT_AUDIO_FLAC , CT_AUDIO_MATROSKA , CT_AUDIO_MPEG ,
  CT_AUDIO_MPEG4 , CT_AUDIO_OGG , CT_AUDIO_WAVE , CT_AUDIO_WEBM ,
  CT_AUDIO_X_APE , CT_AUDIO_X_MS_WMA , CT_AUDIO_X_TTA , CT_AUDIO_X_WAVPACK ,
  CT_IMAGE_APNG , CT_IMAGE_AVIF , CT_IMAGE_BMP , CT_IMAGE_GIF ,
  CT_IMAGE_ICNS , CT_IMAGE_JPG , CT_IMAGE_JP2 , CT_IMAGE_PNG ,
  CT_IMAGE_SVG_XML , CT_IMAGE_TIFF , CT_IMAGE_WEBP , CT_IMAGE_X_MNG ,
  CT_IMAGE_X_TGA , CT_IMAGE_XICON , CT_VIDEO_APG , CT_VIDEO_AV1 ,
  CT_VIDEO_QUICKTIME , CT_VIDEO_MATROSKA , CT_VIDEO_MP4 , CT_VIDEO_MPEG ,
  CT_VIDEO_MPEG2TS , CT_VIDEO_OGG , CT_VIDEO_WEBM , CT_VIDEO_X_M4V ,
  CT_VIDEO_X_MSVIDEO , CT_MULTIPART_FORM_DATA , CT_CUSTOM
}
enum  FileType {
  FT_UNKNOWN = 0 , FT_CUSTOM , FT_DOCUMENT , FT_ARCHIVE ,
  FT_AUDIO , FT_MEDIA , FT_IMAGE
}
enum  HttpMethod {
  Get = 0 , Post , Head , Put ,
  Delete , Options , Patch , Propfind ,
  Mkcol , Copy , Move , Invalid
}
enum class  ReqResult {
  Ok = 0 , BadResponse , NetworkFailure , BadServerAddress ,
  Timeout , HandshakeError , InvalidCertificate , EncryptionFailure
}
enum class  WebSocketMessageType {
  Text = 0 , Binary , Ping , Pong ,
  Close , Unknown
}
enum class  CloseCode {
  kNormalClosure = 1000 , kEndpointGone = 1001 , kProtocolError = 1002 , kInvalidMessage = 1003 ,
  kNone = 1005 , kAbnormally = 1006 , kWrongMessageContent = 1007 , kViolation = 1008 ,
  kMessageTooBig = 1009 , kNeedMoreExtensions = 1010 , kUnexpectedCondition = 1011 , kTLSFailed = 1015
}
enum class  PluginStatus { None , Initializing , Initialized }

Functions

DROGON_EXPORT std::string getVersion ()
DROGON_EXPORT std::string getGitCommit ()
HttpAppFrameworkapp ()
 A wrapper of the instance() method.
template<typename T>
fromRequest (const HttpRequest &)
 This template is used to convert a request object to a custom type object. Users must specialize the template for a particular type.
template<typename T>
HttpRequestPtr toRequest (T &&)
 This template is used to create a request object from a custom type object by calling the newCustomHttpRequest(). Users must specialize the template for a particular type.
template<>
HttpRequestPtr toRequest< const Json::Value & > (const Json::Value &pJson)
template<>
HttpRequestPtr toRequest (Json::Value &&pJson)
template<>
HttpRequestPtr toRequest< Json::Value & > (Json::Value &pJson)
template<>
std::shared_ptr< Json::Value > fromRequest (const HttpRequest &req)
template<>
HttpRequestPtr toRequest< const Json::Value & > (const Json::Value &pJson)
template<>
HttpRequestPtr toRequest (Json::Value &&pJson)
template<>
std::shared_ptr< Json::Value > fromRequest (const HttpRequest &req)
template<typename T>
fromResponse (const HttpResponse &)
 This template is used to convert a response object to a custom type object. Users must specialize the template for a particular type.
template<typename T>
HttpResponsePtr toResponse (T &&)
 This template is used to create a response object from a custom type object by calling the newCustomHttpResponse(). Users must specialize the template for a particular type.
template<>
HttpResponsePtr toResponse< const Json::Value & > (const Json::Value &pJson)
template<>
HttpResponsePtr toResponse (Json::Value &&pJson)
template<>
HttpResponsePtr toResponse< Json::Value & > (Json::Value &pJson)
template<>
HttpResponsePtr toResponse< const Json::Value & > (const Json::Value &pJson)
template<>
HttpResponsePtr toResponse (Json::Value &&pJson)
template<>
std::shared_ptr< Json::Value > fromResponse (const HttpResponse &resp)
std::string_view to_string_view (drogon::ReqResult result)
std::string to_string (drogon::ReqResult result)
std::ostream & operator<< (std::ostream &out, drogon::ReqResult result)
trantor::LogStream & operator<< (trantor::LogStream &out, drogon::ReqResult result)
std::string_view to_string_view (drogon::HttpMethod method)
std::string to_string (drogon::HttpMethod method)
trantor::EventLoop * getIOThreadStorageLoop (size_t index) noexcept(false)
RateLimiterType stringToRateLimiterType (const std::string &type)
template<typename Await>
auto sync_wait (Await &&await)
template<typename Await>
auto co_future (Await &&await) noexcept -> std::future< await_result_t< Await > >
internal::TimerAwaiter sleepCoro (trantor::EventLoop *loop, const std::chrono::duration< double > &delay) noexcept
internal::TimerAwaiter sleepCoro (trantor::EventLoop *loop, double delay) noexcept
internal::LoopAwaiter queueInLoopCoro (trantor::EventLoop *workLoop, std::function< void()> taskFunc, trantor::EventLoop *resumeLoop=nullptr)
internal::SwitchThreadAwaiter switchThreadCoro (trantor::EventLoop *loop) noexcept
internal::EndAwaiter untilQuit (trantor::EventLoop *loop)
template<typename Coro>
void async_run (Coro &&coro)
 Runs a coroutine from a regular function.
template<typename Coro>
std::function< void()> async_func (Coro &&coro)
 returns a function that calls a coroutine
template<typename T>
internal::EventLoopAwaiter< T > queueInLoopCoro (trantor::EventLoop *loop, std::function< T()> task)
 Run a task in a given event loop and returns a resumable object that can be co_awaited in a coroutine.
template<typename... Tasks>
internal::WhenAllAwaiter< Tasks... > when_all (Tasks... tasks)
template<typename T>
internal::WhenAllAwaiter< std::vector< Task< T > > > when_all (std::vector< Task< T > > tasks)
internal::WhenAllAwaiter< std::vector< Task< void > > > when_all (std::vector< Task< void > > tasks)
DROGON_EXPORT const std::string_view & statusCodeToString (int code)
 Get the HTTP messages corresponding to the HTTP status codes.

Variables

template<typename T>
DrObject< T >::DrAllocator DrObject< T >::alloc_
const char banner []
template<typename T, bool AutoCreation>
HttpController< T, AutoCreation >::methodRegistrator HttpController< T, AutoCreation >::registrator_
template<typename T, bool AutoCreation>
HttpSimpleController< T, AutoCreation >::pathRegistrator HttpSimpleController< T, AutoCreation >::registrator_
template<typename T, bool AutoCreation>
WebSocketController< T, AutoCreation >::pathRegistrator WebSocketController< T, AutoCreation >::registrator_
class DROGON_EXPORT RateLimiter
template<typename T>
constexpr bool is_awaitable_v = is_awaitable<T>::value
template<typename T>
constexpr bool is_resumable_v = is_resumable<T>::value

Detailed Description

Drogon Test is a minimal effort test framework developed because the major C++ test frameworks doesn't handle async programs well. Drogon Test's syntax is inspired by both Google Test and Catch2.

Attribute.h armst.nosp@m.rong.nosp@m.@swee.nosp@m.lia..nosp@m.com

Copyright 2018, An Tao. All rights reserved. https://github.com/an-tao/drogon Use of this source code is governed by a MIT license that can be found in the License file.

Drogon

DrTemplate.h An Tao

Copyright 2018, An Tao. All rights reserved. https://github.com/an-tao/drogon Use of this source code is governed by a MIT license that can be found in the License file.

Drogon

The classes in the file are internal tool classes. Do not include this file directly and use any of these classes directly.

UploadFile.h An Tao

Copyright 2018, An Tao. All rights reserved. https://github.com/an-tao/drogon Use of this source code is governed by a MIT license that can be found in the License file.

Drogon

drogon_callbacks.h An Tao

Copyright 2018, An Tao. All rights reserved. https://github.com/an-tao/drogon Use of this source code is governed by a MIT license that can be found in the License file.

Drogon

FunctionTraits.h An Tao

Copyright 2018, An Tao. All rights reserved. https://github.com/an-tao/drogon Use of this source code is governed by a MIT license that can be found in the License file.

Drogon

HttpConstraint.h An Tao

Copyright 2018, An Tao. All rights reserved. https://github.com/an-tao/drogon Use of this source code is governed by a MIT license that can be found in the License file.

Drogon

OStringStream.h An Tao

Copyright 2018, An Tao. All rights reserved. https://github.com/an-tao/drogon Use of this source code is governed by a MIT license that can be found in the License file.

Drogon

AccessLogger.h

RealIpResolver.h

ResultIterator.h An Tao

Copyright 2018, An Tao. All rights reserved. https://github.com/an-tao/drogon Use of this source code is governed by a MIT license that can be found in the License file.

Drogon

RowIterator.h An Tao

Copyright 2018, An Tao. All rights reserved. https://github.com/an-tao/drogon Use of this source code is governed by a MIT license that can be found in the License file.

Drogon

Typedef Documentation

◆ DefaultHandler

using drogon::DefaultHandler
Initial value:
std::function<void(const HttpRequestPtr &,
std::function<void(const HttpResponsePtr &)> &&)>

◆ ExceptionHandler

using drogon::ExceptionHandler
Initial value:
std::function<void(const std::exception &,
const HttpRequestPtr &,
std::function<void(const HttpResponsePtr &)> &&)>

◆ MiddlewareNextCallback

using drogon::MiddlewareNextCallback
Initial value:
std::function<void(std::function<void(const HttpResponsePtr &)> &&)>

◆ SafeStringMap

template<typename T>
using drogon::SafeStringMap
Initial value:
std::unordered_map<std::string, T, utils::internal::SafeStringHash>

◆ WebSocketRequestCallback

using drogon::WebSocketRequestCallback
Initial value:
std::function<
void(ReqResult, const HttpResponsePtr &, const WebSocketClientPtr &)>

Function Documentation

◆ async_func()

template<typename Coro>
std::function< void()> drogon::async_func ( Coro && coro)

returns a function that calls a coroutine

Parameters
coroA coroutine that is awaitable

◆ async_run()

template<typename Coro>
void drogon::async_run ( Coro && coro)

Runs a coroutine from a regular function.

Parameters
coroA coroutine that is awaitable

◆ statusCodeToString()

DROGON_EXPORT const std::string_view & drogon::statusCodeToString ( int code)

Get the HTTP messages corresponding to the HTTP status codes.

Parameters
codeHTTP status code
Returns
the corresponding message

Variable Documentation

◆ banner

const char drogon::banner[]
Initial value:
=
" _ \n"
" __| |_ __ ___ __ _ ___ _ __ \n"
" / _` | '__/ _ \\ / _` |/ _ \\| '_ \\ \n"
"| (_| | | | (_) | (_| | (_) | | | |\n"
" \\__,_|_| \\___/ \\__, |\\___/|_| |_|\n"
" |___/ \n"