ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
ascii_query::HttpRequest Struct Reference

Parsed HTTP request. More...

#include <src/tooling/query/http_server.h>

Public Member Functions

std::string param (const std::string &name, const std::string &default_value="") const
 Get a query parameter value.
 
bool hasParam (const std::string &name) const
 Check if a query parameter exists (flag-style, like &break)
 
int paramInt (const std::string &name, int default_value=0) const
 Get a query parameter as integer.
 
std::string header (const std::string &name, const std::string &default_value="") const
 Get a header value.
 

Data Fields

std::string method
 GET, POST, etc.
 
std::string path
 Request path (without query string)
 
std::string query_string
 Query string (after ?)
 
std::unordered_map< std::string, std::string > headers
 Request headers.
 
std::unordered_map< std::string, std::string > params
 Parsed query parameters.
 
std::string body
 Request body.
 

Detailed Description

Parsed HTTP request.

Definition at line 37 of file http_server.h.

Member Function Documentation

◆ hasParam()

bool ascii_query::HttpRequest::hasParam ( const std::string &  name) const
inline

Check if a query parameter exists (flag-style, like &break)

Parameters
nameParameter name
Returns
true if parameter is present

Definition at line 61 of file http_server.h.

61 {
62 return params.find(name) != params.end();
63 }
std::unordered_map< std::string, std::string > params
Parsed query parameters.
Definition http_server.h:42

References params.

◆ header()

std::string ascii_query::HttpRequest::header ( const std::string &  name,
const std::string &  default_value = "" 
) const

Get a header value.

Parameters
nameHeader name (case-insensitive)
default_valueDefault if not found
Returns
Header value or default

Definition at line 41 of file http_server.cpp.

41 {
42 // Case-insensitive header lookup
43 std::string lower_name = name;
44 std::transform(lower_name.begin(), lower_name.end(), lower_name.begin(),
45 [](unsigned char c) { return std::tolower(c); });
46
47 for (const auto &[key, value] : headers) {
48 std::string lower_key = key;
49 std::transform(lower_key.begin(), lower_key.end(), lower_key.begin(),
50 [](unsigned char c) { return std::tolower(c); });
51 if (lower_key == lower_name) {
52 return value;
53 }
54 }
55 return default_value;
56}
std::unordered_map< std::string, std::string > headers
Request headers.
Definition http_server.h:41

References headers.

◆ param()

std::string ascii_query::HttpRequest::param ( const std::string &  name,
const std::string &  default_value = "" 
) const
inline

Get a query parameter value.

Parameters
nameParameter name
default_valueDefault if not found
Returns
Parameter value or default

Definition at line 51 of file http_server.h.

51 {
52 auto it = params.find(name);
53 return (it != params.end()) ? it->second : default_value;
54 }

References params.

◆ paramInt()

int ascii_query::HttpRequest::paramInt ( const std::string &  name,
int  default_value = 0 
) const
inline

Get a query parameter as integer.

Parameters
nameParameter name
default_valueDefault if not found or not a number
Returns
Parameter value or default

Definition at line 71 of file http_server.h.

71 {
72 auto it = params.find(name);
73 if (it == params.end())
74 return default_value;
75 try {
76 return std::stoi(it->second);
77 } catch (...) {
78 return default_value;
79 }
80 }

References params.

Field Documentation

◆ body

std::string ascii_query::HttpRequest::body

Request body.

Definition at line 43 of file http_server.h.

◆ headers

std::unordered_map<std::string, std::string> ascii_query::HttpRequest::headers

Request headers.

Definition at line 41 of file http_server.h.

Referenced by header().

◆ method

std::string ascii_query::HttpRequest::method

GET, POST, etc.

Definition at line 38 of file http_server.h.

◆ params

std::unordered_map<std::string, std::string> ascii_query::HttpRequest::params

Parsed query parameters.

Definition at line 42 of file http_server.h.

Referenced by hasParam(), param(), and paramInt().

◆ path

std::string ascii_query::HttpRequest::path

Request path (without query string)

Definition at line 39 of file http_server.h.

◆ query_string

std::string ascii_query::HttpRequest::query_string

Query string (after ?)

Definition at line 40 of file http_server.h.


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