C++ edjLibrary SDK
Loading...
Searching...
No Matches
response.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <vector>
5#include <map>
6#include <string>
7
8#include "http.hpp"
9#include "stream.hpp"
10#include "error.hpp"
11
12namespace edjx {
13
15namespace response {
16
30 struct HttpResponse {
38 std::vector<uint8_t> body;
39
47
56 HttpResponse(const std::string & text);
57
66 HttpResponse(const std::vector<uint8_t> & bytes);
67
78 HttpResponse(const uint8_t * mem, size_t size);
79
87
94
102
109
120 const std::string & header_name,
121 const std::string & value
122 );
123
134 const std::string & header_name,
135 const std::vector<std::string> & values
136 );
137
149 const std::string & header_name,
150 const std::string & value
151 );
152
163 );
164
171
178 HttpResponse & set_body(const std::string & text);
179
186 HttpResponse & set_body(const std::vector<uint8_t> & bytes);
187
195 HttpResponse & set_body(const uint8_t * mem, size_t size);
196
202 const std::vector<uint8_t> & get_body() const;
203
211
224 };
225
226}}
This class represents a write stream.
Definition: stream.hpp:68
HttpError
Enum describing return values of functions that correspond to HTTP modules.
Definition: error.hpp:14
HttpVersion
Enum containing an HTTP version.
Definition: http.hpp:18
uint16_t HttpStatusCode
HTTP status code (e.g., value 200 means OK, value 404 means Not Found)
Definition: http.hpp:60
std::map< std::string, std::vector< std::string >, CaseInsensitiveKeys > HttpHeaders
A map of HttpHeaders where keys are case-insensitive header names.
Definition: http.hpp:54
Definition: error.hpp:5
An HTTP response which may include body, headers, and status code.
Definition: response.hpp:30
HttpResponse & set_status(edjx::http::HttpStatusCode status)
Sets the HTTP status code of the client response.
const std::vector< uint8_t > & get_body() const
Returns a constant reference to the body.
HttpResponse(const std::string &text)
Creates an HttpResponse for the client.
HttpResponse & append_header(const std::string &header_name, const std::string &value)
Sets a response header to the given value.
edjx::http::HttpVersion get_version() const
Returns the HTTP version of this response.
HttpResponse & set_version(edjx::http::HttpVersion version)
Sets the HTTP version of this response.
edjx::http::HttpVersion version
HTTP version.
Definition: response.hpp:34
edjx::http::HttpHeaders headers
HTTP headers.
Definition: response.hpp:36
HttpResponse(const uint8_t *mem, size_t size)
Creates an HttpResponse for the client.
edjx::http::HttpStatusCode get_status() const
Returns the HTTP status code of the response.
std::vector< uint8_t > body
Body of the response.
Definition: response.hpp:38
HttpResponse & set_body(const std::vector< uint8_t > &bytes)
Sets the body to be bytes.
edjx::error::HttpError send_streaming(edjx::stream::WriteStream &write_stream)
Sends the response to the client using streaming.
edjx::http::HttpStatusCode status
HTTP status code.
Definition: response.hpp:32
const edjx::http::HttpHeaders & get_headers() const
Returns a constant reference to the response header map.
HttpResponse()
Creates an HttpResponse for the client.
HttpResponse & set_body(const uint8_t *mem, size_t size)
Sets the body to contain size bytes from address mem.
HttpResponse(const std::vector< uint8_t > &bytes)
Creates an HttpResponse for the client.
HttpResponse & set_headers(const edjx::http::HttpHeaders &headers)
Set the response headers to the given values.
edjx::error::HttpError send()
Sends the response to the client.
HttpResponse & set_header(const std::string &header_name, const std::vector< std::string > &values)
Sets a response header to the given values.
HttpResponse & set_body(const std::string &text)
Sets the body to be text.
HttpResponse & set_header(const std::string &header_name, const std::string &value)
Sets a response header to the given value.