HTTP Server : Add helper APIs for sending string content

Note : In future consider deprecating usage of -1 for setting
buffer length equal to string length in APIs httpd_resp_send()
and httpd_resp_send_chunk()
This commit is contained in:
Anurag Kar
2019-01-06 02:44:45 +05:30
parent 91d6b3b989
commit 107f52c4fc
2 changed files with 54 additions and 4 deletions

View File

@@ -246,7 +246,9 @@ esp_err_t httpd_resp_send(httpd_req_t *r, const char *buf, ssize_t buf_len)
const char *colon_separator = ": ";
const char *cr_lf_seperator = "\r\n";
if (buf_len == -1) buf_len = strlen(buf);
if (buf_len == HTTPD_RESP_USE_STRLEN) {
buf_len = strlen(buf);
}
/* Request headers are no longer available */
ra->req_hdrs_count = 0;
@@ -306,7 +308,9 @@ esp_err_t httpd_resp_send_chunk(httpd_req_t *r, const char *buf, ssize_t buf_len
return ESP_ERR_HTTPD_INVALID_REQ;
}
if (buf_len == -1) buf_len = strlen(buf);
if (buf_len == HTTPD_RESP_USE_STRLEN) {
buf_len = strlen(buf);
}
struct httpd_req_aux *ra = r->aux;
const char *httpd_chunked_hdr_str = "HTTP/1.1 %s\r\nContent-Type: %s\r\nTransfer-Encoding: chunked\r\n";