mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
httpd_resp_send: use HTTPD_RESP_USE_STRLEN
when possible
This commit is contained in:
parent
f29370b02c
commit
6673407f98
@ -1047,7 +1047,7 @@ esp_err_t httpd_resp_send_chunk(httpd_req_t *r, const char *buf, ssize_t buf_len
|
|||||||
* - ESP_ERR_HTTPD_INVALID_REQ : Invalid request
|
* - ESP_ERR_HTTPD_INVALID_REQ : Invalid request
|
||||||
*/
|
*/
|
||||||
static inline esp_err_t httpd_resp_sendstr(httpd_req_t *r, const char *str) {
|
static inline esp_err_t httpd_resp_sendstr(httpd_req_t *r, const char *str) {
|
||||||
return httpd_resp_send(r, str, (str == NULL) ? 0 : strlen(str));
|
return httpd_resp_send(r, str, (str == NULL) ? 0 : HTTPD_RESP_USE_STRLEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1068,7 +1068,7 @@ static inline esp_err_t httpd_resp_sendstr(httpd_req_t *r, const char *str) {
|
|||||||
* - ESP_ERR_HTTPD_INVALID_REQ : Invalid request
|
* - ESP_ERR_HTTPD_INVALID_REQ : Invalid request
|
||||||
*/
|
*/
|
||||||
static inline esp_err_t httpd_resp_sendstr_chunk(httpd_req_t *r, const char *str) {
|
static inline esp_err_t httpd_resp_sendstr_chunk(httpd_req_t *r, const char *str) {
|
||||||
return httpd_resp_send_chunk(r, str, (str == NULL) ? 0 : strlen(str));
|
return httpd_resp_send_chunk(r, str, (str == NULL) ? 0 : HTTPD_RESP_USE_STRLEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Some commonly used status codes */
|
/* Some commonly used status codes */
|
||||||
|
@ -451,7 +451,7 @@ esp_err_t httpd_resp_send_err(httpd_req_t *req, httpd_err_code_t error, const ch
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Send HTTP error message */
|
/* Send HTTP error message */
|
||||||
ret = httpd_resp_send(req, msg, strlen(msg));
|
ret = httpd_resp_send(req, msg, HTTPD_RESP_USE_STRLEN);
|
||||||
|
|
||||||
#ifdef CONFIG_HTTPD_ERR_RESP_NO_DELAY
|
#ifdef CONFIG_HTTPD_ERR_RESP_NO_DELAY
|
||||||
/* If TCP_NODELAY was set successfully above, time to disable it */
|
/* If TCP_NODELAY was set successfully above, time to disable it */
|
||||||
|
@ -23,7 +23,7 @@ Application Example
|
|||||||
{
|
{
|
||||||
/* Send a simple response */
|
/* Send a simple response */
|
||||||
const char resp[] = "URI GET Response";
|
const char resp[] = "URI GET Response";
|
||||||
httpd_resp_send(req, resp, strlen(resp));
|
httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ Application Example
|
|||||||
|
|
||||||
/* Send a simple response */
|
/* Send a simple response */
|
||||||
const char resp[] = "URI POST Response";
|
const char resp[] = "URI POST Response";
|
||||||
httpd_resp_send(req, resp, strlen(resp));
|
httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ HTTP Server 组件提供了在 ESP32 上运行轻量级 Web 服务器的功能
|
|||||||
{
|
{
|
||||||
/* 发送回简单的响应数据包 */
|
/* 发送回简单的响应数据包 */
|
||||||
const char[] resp = "URI GET Response";
|
const char[] resp = "URI GET Response";
|
||||||
httpd_resp_send(req, resp, strlen(resp));
|
httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ HTTP Server 组件提供了在 ESP32 上运行轻量级 Web 服务器的功能
|
|||||||
|
|
||||||
/* 发送简单的响应数据包 */
|
/* 发送简单的响应数据包 */
|
||||||
const char[] resp = "URI POST Response";
|
const char[] resp = "URI POST Response";
|
||||||
httpd_resp_send(req, resp, strlen(resp));
|
httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ static esp_err_t hello_get_handler(httpd_req_t *req)
|
|||||||
{
|
{
|
||||||
#define STR "Hello World!"
|
#define STR "Hello World!"
|
||||||
ESP_LOGI(TAG, "Free Stack for server task: '%d'", uxTaskGetStackHighWaterMark(NULL));
|
ESP_LOGI(TAG, "Free Stack for server task: '%d'", uxTaskGetStackHighWaterMark(NULL));
|
||||||
httpd_resp_send(req, STR, strlen(STR));
|
httpd_resp_send(req, STR, HTTPD_RESP_USE_STRLEN);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
#undef STR
|
#undef STR
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ static esp_err_t test_header_get_handler(httpd_req_t *req)
|
|||||||
}
|
}
|
||||||
if (httpd_req_get_hdr_value_str(req, "Header2", buf, buf_len) == ESP_OK) {
|
if (httpd_req_get_hdr_value_str(req, "Header2", buf, buf_len) == ESP_OK) {
|
||||||
ESP_LOGI(TAG, "Header2 content: %s", buf);
|
ESP_LOGI(TAG, "Header2 content: %s", buf);
|
||||||
httpd_resp_send(req, buf, strlen(buf));
|
httpd_resp_send(req, buf, HTTPD_RESP_USE_STRLEN);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(TAG, "Header2 not found");
|
ESP_LOGE(TAG, "Header2 not found");
|
||||||
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "Header2 not found");
|
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "Header2 not found");
|
||||||
@ -121,7 +121,7 @@ static esp_err_t hello_type_get_handler(httpd_req_t *req)
|
|||||||
{
|
{
|
||||||
#define STR "Hello World!"
|
#define STR "Hello World!"
|
||||||
httpd_resp_set_type(req, HTTPD_TYPE_TEXT);
|
httpd_resp_set_type(req, HTTPD_TYPE_TEXT);
|
||||||
httpd_resp_send(req, STR, strlen(STR));
|
httpd_resp_send(req, STR, HTTPD_RESP_USE_STRLEN);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
#undef STR
|
#undef STR
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ static esp_err_t hello_status_get_handler(httpd_req_t *req)
|
|||||||
{
|
{
|
||||||
#define STR "Hello World!"
|
#define STR "Hello World!"
|
||||||
httpd_resp_set_status(req, HTTPD_500);
|
httpd_resp_set_status(req, HTTPD_500);
|
||||||
httpd_resp_send(req, STR, strlen(STR));
|
httpd_resp_send(req, STR, HTTPD_RESP_USE_STRLEN);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
#undef STR
|
#undef STR
|
||||||
}
|
}
|
||||||
@ -228,7 +228,7 @@ static esp_err_t adder_post_handler(httpd_req_t *req)
|
|||||||
*adder += val;
|
*adder += val;
|
||||||
|
|
||||||
snprintf(outbuf, sizeof(outbuf),"%d", *adder);
|
snprintf(outbuf, sizeof(outbuf),"%d", *adder);
|
||||||
httpd_resp_send(req, outbuf, strlen(outbuf));
|
httpd_resp_send(req, outbuf, HTTPD_RESP_USE_STRLEN);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,7 +251,7 @@ static esp_err_t leftover_data_post_handler(httpd_req_t *req)
|
|||||||
|
|
||||||
buf[ret] = '\0';
|
buf[ret] = '\0';
|
||||||
ESP_LOGI(TAG, "leftover data handler read %s", buf);
|
ESP_LOGI(TAG, "leftover data handler read %s", buf);
|
||||||
httpd_resp_send(req, buf, strlen(buf));
|
httpd_resp_send(req, buf, HTTPD_RESP_USE_STRLEN);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,7 +281,7 @@ static void generate_async_resp(void *arg)
|
|||||||
static esp_err_t async_get_handler(httpd_req_t *req)
|
static esp_err_t async_get_handler(httpd_req_t *req)
|
||||||
{
|
{
|
||||||
#define STR "Hello World!"
|
#define STR "Hello World!"
|
||||||
httpd_resp_send(req, STR, strlen(STR));
|
httpd_resp_send(req, STR, HTTPD_RESP_USE_STRLEN);
|
||||||
/* Also register a HTTPD Work which sends the same data on the same
|
/* Also register a HTTPD Work which sends the same data on the same
|
||||||
* socket again
|
* socket again
|
||||||
*/
|
*/
|
||||||
|
@ -71,7 +71,7 @@ static esp_err_t adder_post_handler(httpd_req_t *req)
|
|||||||
|
|
||||||
/* Respond with the accumulated value */
|
/* Respond with the accumulated value */
|
||||||
snprintf(outbuf, sizeof(outbuf),"%d", *adder);
|
snprintf(outbuf, sizeof(outbuf),"%d", *adder);
|
||||||
httpd_resp_send(req, outbuf, strlen(outbuf));
|
httpd_resp_send(req, outbuf, HTTPD_RESP_USE_STRLEN);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ static esp_err_t adder_get_handler(httpd_req_t *req)
|
|||||||
|
|
||||||
/* Respond with the accumulated value */
|
/* Respond with the accumulated value */
|
||||||
snprintf(outbuf, sizeof(outbuf),"%d", *((int *)req->sess_ctx));
|
snprintf(outbuf, sizeof(outbuf),"%d", *((int *)req->sess_ctx));
|
||||||
httpd_resp_send(req, outbuf, strlen(outbuf));
|
httpd_resp_send(req, outbuf, HTTPD_RESP_USE_STRLEN);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ static esp_err_t adder_put_handler(httpd_req_t *req)
|
|||||||
|
|
||||||
/* Respond with the reset value */
|
/* Respond with the reset value */
|
||||||
snprintf(outbuf, sizeof(outbuf),"%d", *((int *)req->sess_ctx));
|
snprintf(outbuf, sizeof(outbuf),"%d", *((int *)req->sess_ctx));
|
||||||
httpd_resp_send(req, outbuf, strlen(outbuf));
|
httpd_resp_send(req, outbuf, HTTPD_RESP_USE_STRLEN);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ static esp_err_t hello_get_handler(httpd_req_t *req)
|
|||||||
/* Send response with custom headers and body set as the
|
/* Send response with custom headers and body set as the
|
||||||
* string passed in user context*/
|
* string passed in user context*/
|
||||||
const char* resp_str = (const char*) req->user_ctx;
|
const char* resp_str = (const char*) req->user_ctx;
|
||||||
httpd_resp_send(req, resp_str, strlen(resp_str));
|
httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
|
||||||
|
|
||||||
/* After sending the HTTP response the old HTTP request
|
/* After sending the HTTP response the old HTTP request
|
||||||
* headers are lost. Check if HTTP request headers can be read now. */
|
* headers are lost. Check if HTTP request headers can be read now. */
|
||||||
|
@ -30,7 +30,7 @@ static const char *TAG = "example";
|
|||||||
static esp_err_t root_get_handler(httpd_req_t *req)
|
static esp_err_t root_get_handler(httpd_req_t *req)
|
||||||
{
|
{
|
||||||
httpd_resp_set_type(req, "text/html");
|
httpd_resp_set_type(req, "text/html");
|
||||||
httpd_resp_send(req, "<h1>Hello Secure World!</h1>", -1); // -1 = use strlen()
|
httpd_resp_send(req, "<h1>Hello Secure World!</h1>", HTTPD_RESP_USE_STRLEN);
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user