C++ edjLibrary SDK
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
edjx::response::HttpResponse Struct Reference

An HTTP response which may include body, headers, and status code. More...

#include <response.hpp>

Public Member Functions

 HttpResponse ()
 Creates an HttpResponse for the client. More...
 
 HttpResponse (const std::string &text)
 Creates an HttpResponse for the client. More...
 
 HttpResponse (const std::vector< uint8_t > &bytes)
 Creates an HttpResponse for the client. More...
 
 HttpResponse (const uint8_t *mem, size_t size)
 Creates an HttpResponse for the client. More...
 
HttpResponseset_status (edjx::http::HttpStatusCode status)
 Sets the HTTP status code of the client response. More...
 
edjx::http::HttpStatusCode get_status () const
 Returns the HTTP status code of the response. More...
 
HttpResponseset_version (edjx::http::HttpVersion version)
 Sets the HTTP version of this response. More...
 
edjx::http::HttpVersion get_version () const
 Returns the HTTP version of this response. More...
 
HttpResponseset_header (const std::string &header_name, const std::string &value)
 Sets a response header to the given value. More...
 
HttpResponseset_header (const std::string &header_name, const std::vector< std::string > &values)
 Sets a response header to the given values. More...
 
HttpResponseappend_header (const std::string &header_name, const std::string &value)
 Sets a response header to the given value. More...
 
HttpResponseset_headers (const edjx::http::HttpHeaders &headers)
 Set the response headers to the given values. More...
 
const edjx::http::HttpHeadersget_headers () const
 Returns a constant reference to the response header map. More...
 
HttpResponseset_body (const std::string &text)
 Sets the body to be text. More...
 
HttpResponseset_body (const std::vector< uint8_t > &bytes)
 Sets the body to be bytes. More...
 
HttpResponseset_body (const uint8_t *mem, size_t size)
 Sets the body to contain size bytes from address mem. More...
 
const std::vector< uint8_t > & get_body () const
 Returns a constant reference to the body. More...
 
edjx::error::HttpError send ()
 Sends the response to the client. More...
 
edjx::error::HttpError send_streaming (edjx::stream::WriteStream &write_stream)
 Sends the response to the client using streaming. More...
 

Public Attributes

edjx::http::HttpStatusCode status
 HTTP status code. More...
 
edjx::http::HttpVersion version
 HTTP version. More...
 
edjx::http::HttpHeaders headers
 HTTP headers. More...
 
std::vector< uint8_t > body
 Body of the response. More...
 

Detailed Description

An HTTP response which may include body, headers, and status code.

Each serverless function can send only one response to the client.

Normally, these methods do not need to be used explicitly. EDJX sample C++ Serverless Application code file (main.cpp) uses one of these methods to process Responses and relay to the client.

The HTTP response consists of a status, version, a set of header fields, and a body.

Constructor & Destructor Documentation

◆ HttpResponse() [1/4]

edjx::response::HttpResponse::HttpResponse ( )

Creates an HttpResponse for the client.

The response is created with status code 200 OK, version as HTTP/1.1, no headers, and an empty body.

◆ HttpResponse() [2/4]

edjx::response::HttpResponse::HttpResponse ( const std::string &  text)

Creates an HttpResponse for the client.

The response is created with status code 200 OK, version as HTTP/1.1, no headers, and text as body.

Parameters
textA string that will be used as the body

◆ HttpResponse() [3/4]

edjx::response::HttpResponse::HttpResponse ( const std::vector< uint8_t > &  bytes)

Creates an HttpResponse for the client.

The response is created with status code 200 OK, version as HTTP/1.1, no headers, and bytes as body.

Parameters
bytesA sequence of bytes that will be used as the body

◆ HttpResponse() [4/4]

edjx::response::HttpResponse::HttpResponse ( const uint8_t *  mem,
size_t  size 
)

Creates an HttpResponse for the client.

The response is created with status code 200 OK, version as HTTP/1.1, no headers, and a body created from bytes in a memory buffer.

Parameters
memPointer to the body bytes
sizeNumber of bytes in the body

Member Function Documentation

◆ append_header()

HttpResponse & edjx::response::HttpResponse::append_header ( const std::string &  header_name,
const std::string &  value 
)

Sets a response header to the given value.

Keeps any previous values for the given header name and adds the new value

Parameters
header_nameHeader name
valueHeader value
Returns
Reference to this HttpResponse object

◆ get_body()

const std::vector< uint8_t > & edjx::response::HttpResponse::get_body ( ) const

Returns a constant reference to the body.

Returns
Body of the response

◆ get_headers()

const edjx::http::HttpHeaders & edjx::response::HttpResponse::get_headers ( ) const

Returns a constant reference to the response header map.

Returns
HTTP headers

◆ get_status()

edjx::http::HttpStatusCode edjx::response::HttpResponse::get_status ( ) const

Returns the HTTP status code of the response.

Returns
HTTP status

◆ get_version()

edjx::http::HttpVersion edjx::response::HttpResponse::get_version ( ) const

Returns the HTTP version of this response.

Returns
HTTP version of the response

◆ send()

edjx::error::HttpError edjx::response::HttpResponse::send ( )

Sends the response to the client.

Returns
Returns edjx::error::HttpError::Success on success, some other value on failure.

◆ send_streaming()

edjx::error::HttpError edjx::response::HttpResponse::send_streaming ( edjx::stream::WriteStream write_stream)

Sends the response to the client using streaming.

This method opens a write stream for the response to the client.

send_streaming() and send() cannot be used at the same time.

Parameters
write_streamThe write stream handle will be copied to this object.
Returns
Returns edjx::error::HttpError::Success on success, some other value on failure.

◆ set_body() [1/3]

HttpResponse & edjx::response::HttpResponse::set_body ( const std::string &  text)

Sets the body to be text.

Parameters
textUsed as response body
Returns
Reference to this HttpResponse object

◆ set_body() [2/3]

HttpResponse & edjx::response::HttpResponse::set_body ( const std::vector< uint8_t > &  bytes)

Sets the body to be bytes.

Parameters
bytesUsed as response body
Returns
Reference to this HttpResponse object

◆ set_body() [3/3]

HttpResponse & edjx::response::HttpResponse::set_body ( const uint8_t *  mem,
size_t  size 
)

Sets the body to contain size bytes from address mem.

Parameters
memPointer do bytes to be used as body
sizeNumber of bytes to be used as body
Returns
Reference to this HttpResponse object

◆ set_header() [1/2]

HttpResponse & edjx::response::HttpResponse::set_header ( const std::string &  header_name,
const std::string &  value 
)

Sets a response header to the given value.

Discards any previous values for the given header name.

Parameters
header_nameHeader name
valueHeader value
Returns
Reference to this HttpResponse object

◆ set_header() [2/2]

HttpResponse & edjx::response::HttpResponse::set_header ( const std::string &  header_name,
const std::vector< std::string > &  values 
)

Sets a response header to the given values.

Discards any previous values for the given header name.

Parameters
header_nameHeader name
valuesMultiple header values
Returns
Reference to this HttpResponse object

◆ set_headers()

HttpResponse & edjx::response::HttpResponse::set_headers ( const edjx::http::HttpHeaders headers)

Set the response headers to the given values.

Discards any previous headers.

Parameters
headersHeaders
Returns
Reference to this HttpResponse object

◆ set_status()

HttpResponse & edjx::response::HttpResponse::set_status ( edjx::http::HttpStatusCode  status)

Sets the HTTP status code of the client response.

Parameters
statusHTTP status (e.g., 200)
Returns
Reference to this HttpResponse object

◆ set_version()

HttpResponse & edjx::response::HttpResponse::set_version ( edjx::http::HttpVersion  version)

Sets the HTTP version of this response.

Parameters
versionHTTP version (use constants from [edjx::http::HttpVersion])
Returns
Reference to this HttpResponse object

Member Data Documentation

◆ body

std::vector<uint8_t> edjx::response::HttpResponse::body

Body of the response.

◆ headers

edjx::http::HttpHeaders edjx::response::HttpResponse::headers

HTTP headers.

◆ status

edjx::http::HttpStatusCode edjx::response::HttpResponse::status

HTTP status code.

◆ version

edjx::http::HttpVersion edjx::response::HttpResponse::version

HTTP version.


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