#include <http_response_builder.h>
|
| HttpResponseBuilder (uint16_t a_status_code) |
|
void | set_header (string key, string value) |
|
char * | build (const void *body, size_t body_size, size_t *size) |
|
nsapi_error_t | send (TCPSocket *socket, const void *body, size_t body_size) |
|
Definition at line 139 of file http_response_builder.h.
◆ HttpResponseBuilder()
HttpResponseBuilder::HttpResponseBuilder |
( |
uint16_t |
a_status_code | ) |
|
|
inline |
Definition at line 141 of file http_response_builder.h.
const char * status_message
static const char * get_http_status_string(uint16_t status_code)
◆ build()
char* HttpResponseBuilder::build |
( |
const void * |
body, |
|
|
size_t |
body_size, |
|
|
size_t * |
size |
|
) |
| |
|
inline |
Definition at line 159 of file http_response_builder.h.
161 snprintf(buffer,
sizeof(buffer),
"%d", body_size);
164 char status_code_buffer[5];
165 snprintf(status_code_buffer,
sizeof(status_code_buffer),
"%d",
172 8 + 1 + strlen(status_code_buffer) + 1 + strlen(
status_message) + 2;
175 typedef map<string, string>::iterator it_type;
178 *size += it->first.length() + 1 + 1 + it->second.length() + 2;
188 char *res = (
char *)calloc(*size + 1, 1);
189 char *originalRes = res;
192 sprintf(res,
"HTTP/1.1 %s %s\r\n", status_code_buffer,
status_message);
194 typedef map<string, string>::iterator it_type;
197 res += sprintf(res,
"%s: %s\r\n", it->first.c_str(), it->second.c_str());
200 res += sprintf(res,
"\r\n");
203 memcpy(res, body, body_size);
208 printf(
"\nhttp_response_builder#build\n");
209 printf(
"----- BEGIN RESPONSE -----\n");
210 printf(
"%s", originalRes);
211 printf(
"----- END RESPONSE -----\n");
void set_header(string key, string value)
map< string, string > headers
◆ send()
nsapi_error_t HttpResponseBuilder::send |
( |
TCPSocket * |
socket, |
|
|
const void * |
body, |
|
|
size_t |
body_size |
|
) |
| |
|
inline |
Definition at line 217 of file http_response_builder.h.
219 return NSAPI_ERROR_NO_SOCKET;
222 char *response =
build(body, body_size, &res_size);
224 nsapi_error_t r = socket->send(response, res_size);
char * build(const void *body, size_t body_size, size_t *size)
Referenced by WebServer::tick().
◆ set_header()
void HttpResponseBuilder::set_header |
( |
string |
key, |
|
|
string |
value |
|
) |
| |
|
inline |
Set a header for the request If the key already exists, it will be overwritten...
Definition at line 149 of file http_response_builder.h.
150 map<string, string>::iterator it =
headers.find(key);
◆ headers
map<string, string> HttpResponseBuilder::headers |
|
private |
◆ status_code
uint16_t HttpResponseBuilder::status_code |
|
private |
◆ status_message
const char* HttpResponseBuilder::status_message |
|
private |
The documentation for this class was generated from the following file: