Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
Loading...
Searching...
No Matches
orbit::testing::RequestBuilder Class Reference

One request, built fluently and run with send(). More...

#include <Client.hpp>

Collaboration diagram for orbit::testing::RequestBuilder:

Public Member Functions

RequestBuilder & header (std::string name, std::string value)
 
RequestBuilder & body (std::string body, std::string content_type="text/plain")
 The body and, unless content_type is empty, its Content-Type.
 
RequestBuilder & json (const nlohmann::json &value)
 A JSON body (Content-Type: application/json).
 
RequestBuilder & cookie (std::string name, std::string value)
 A cookie for this request only, on top of the client's cookie jar.
 
RequestBuilder & client_ip (std::string ip)
 The client address the application sees (default 127.0.0.1).
 
Response send (std::chrono::milliseconds timeout=std::chrono::seconds(5))
 Runs the request through the application and waits until the response is complete, or timeout passes (a coroutine handler still waiting, an endless SSE stream). Never throws for an application error: that is a 500 (or what on_error answers).
 

Private Member Functions

 RequestBuilder (Client &client, http::HttpMethod method, std::string target)
 

Private Attributes

Client & client_
 
http::HttpMethod method_
 
std::string target_
 
std::vector< std::pair< std::string, std::string > > headers_
 
std::string body_
 
std::unordered_map< std::string, std::string > cookies_
 
std::string client_ip_ = "127.0.0.1"
 

Friends

class Client
 

Detailed Description

One request, built fluently and run with send().

Constructor & Destructor Documentation

◆ RequestBuilder()

orbit::testing::RequestBuilder::RequestBuilder ( Client &  client,
http::HttpMethod  method,
std::string  target 
)
private

Member Function Documentation

◆ body()

RequestBuilder & orbit::testing::RequestBuilder::body ( std::string  body,
std::string  content_type = "text/plain" 
)

The body and, unless content_type is empty, its Content-Type.

◆ client_ip()

RequestBuilder & orbit::testing::RequestBuilder::client_ip ( std::string  ip)

The client address the application sees (default 127.0.0.1).

◆ cookie()

RequestBuilder & orbit::testing::RequestBuilder::cookie ( std::string  name,
std::string  value 
)

A cookie for this request only, on top of the client's cookie jar.

◆ header()

RequestBuilder & orbit::testing::RequestBuilder::header ( std::string  name,
std::string  value 
)

◆ json()

RequestBuilder & orbit::testing::RequestBuilder::json ( const nlohmann::json &  value)

A JSON body (Content-Type: application/json).

◆ send()

Response orbit::testing::RequestBuilder::send ( std::chrono::milliseconds  timeout = std::chrono::seconds(5))

Runs the request through the application and waits until the response is complete, or timeout passes (a coroutine handler still waiting, an endless SSE stream). Never throws for an application error: that is a 500 (or what on_error answers).

Friends And Related Symbol Documentation

◆ Client

friend class Client
friend

Member Data Documentation

◆ body_

std::string orbit::testing::RequestBuilder::body_
private

◆ client_

Client& orbit::testing::RequestBuilder::client_
private

◆ client_ip_

std::string orbit::testing::RequestBuilder::client_ip_ = "127.0.0.1"
private

◆ cookies_

std::unordered_map<std::string, std::string> orbit::testing::RequestBuilder::cookies_
private

◆ headers_

std::vector<std::pair<std::string, std::string> > orbit::testing::RequestBuilder::headers_
private

◆ method_

http::HttpMethod orbit::testing::RequestBuilder::method_
private

◆ target_

std::string orbit::testing::RequestBuilder::target_
private

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