From 08a4fe0d6155da2254fcbf074e4adf12825c1ab8 Mon Sep 17 00:00:00 2001 From: yuanjm Date: Fri, 7 Aug 2020 11:47:43 +0800 Subject: [PATCH] feat(http): Modify for esp8266 --- components/esp_http_client/CMakeLists.txt | 4 ++-- components/esp_http_client/Kconfig | 6 ++++++ components/esp_http_client/include/esp_http_client.h | 2 +- components/esp_http_client/lib/http_auth.c | 6 +++++- components/esp_http_client/lib/include/http_header.h | 2 +- .../esp_http_client/main/esp_http_client_example.c | 2 +- examples/protocols/esp_http_client/sdkconfig.defaults | 3 +++ 7 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 examples/protocols/esp_http_client/sdkconfig.defaults diff --git a/components/esp_http_client/CMakeLists.txt b/components/esp_http_client/CMakeLists.txt index 327e9077..b2f9ec1e 100644 --- a/components/esp_http_client/CMakeLists.txt +++ b/components/esp_http_client/CMakeLists.txt @@ -4,5 +4,5 @@ idf_component_register(SRCS "esp_http_client.c" "lib/http_utils.c" INCLUDE_DIRS "include" PRIV_INCLUDE_DIRS "lib/include" - REQUIRES nghttp - PRIV_REQUIRES mbedtls lwip esp-tls tcp_transport) + REQUIRES http_parser + PRIV_REQUIRES mbedtls lwip esp-tls tcp_transport tcpip_adapter) diff --git a/components/esp_http_client/Kconfig b/components/esp_http_client/Kconfig index 9cc8a680..a2e56c5d 100644 --- a/components/esp_http_client/Kconfig +++ b/components/esp_http_client/Kconfig @@ -14,4 +14,10 @@ menu "ESP HTTP client" This option will enable HTTP Basic Authentication. It is disabled by default as Basic auth uses unencrypted encoding, so it introduces a vulnerability when not using TLS + config HTTP_BUF_SIZE + int "Default HTTP Buffer Size (both send and receive)" + default 512 + range 512 1460 + help + Set HTTP Buffer Size. The larger buffer size will make send and receive more size packet once. endmenu diff --git a/components/esp_http_client/include/esp_http_client.h b/components/esp_http_client/include/esp_http_client.h index 8c2c148a..b22783ae 100644 --- a/components/esp_http_client/include/esp_http_client.h +++ b/components/esp_http_client/include/esp_http_client.h @@ -24,7 +24,7 @@ extern "C" { #endif -#define DEFAULT_HTTP_BUF_SIZE (512) +#define DEFAULT_HTTP_BUF_SIZE CONFIG_HTTP_BUF_SIZE typedef struct esp_http_client *esp_http_client_handle_t; typedef struct esp_http_client_event *esp_http_client_event_handle_t; diff --git a/components/esp_http_client/lib/http_auth.c b/components/esp_http_client/lib/http_auth.c index 1fcc2f11..8827870d 100644 --- a/components/esp_http_client/lib/http_auth.c +++ b/components/esp_http_client/lib/http_auth.c @@ -19,7 +19,7 @@ #include "esp_netif.h" #include "lwip/sockets.h" -#include "esp32/rom/md5_hash.h" +#include "rom/md5_hash.h" #include "mbedtls/base64.h" #include "esp_system.h" @@ -81,6 +81,10 @@ char *http_auth_digest(const char *username, const char *password, esp_http_auth return NULL; } + if (auth_data->algorithm == NULL) { + auth_data->algorithm = "md5"; + } + ha1 = calloc(1, MD5_MAX_LEN); HTTP_MEM_CHECK(TAG, ha1, goto _digest_exit); diff --git a/components/esp_http_client/lib/include/http_header.h b/components/esp_http_client/lib/include/http_header.h index 9d8ea3ad..c514c616 100644 --- a/components/esp_http_client/lib/include/http_header.h +++ b/components/esp_http_client/lib/include/http_header.h @@ -15,7 +15,7 @@ #ifndef _HTTP_HEADER_H_ #define _HTTP_HEADER_H_ -#include "sys/queue.h" +#include "rom/queue.h" #include "esp_err.h" #ifdef __cplusplus diff --git a/examples/protocols/esp_http_client/main/esp_http_client_example.c b/examples/protocols/esp_http_client/main/esp_http_client_example.c index 7cc3eb1d..e1dc0a35 100644 --- a/examples/protocols/esp_http_client/main/esp_http_client_example.c +++ b/examples/protocols/esp_http_client/main/esp_http_client_example.c @@ -647,7 +647,7 @@ static void http_test_task(void *pvParameters) void app_main(void) { esp_err_t ret = nvs_flash_init(); - if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { + if (ret == ESP_ERR_NVS_NO_FREE_PAGES) { ESP_ERROR_CHECK(nvs_flash_erase()); ret = nvs_flash_init(); } diff --git a/examples/protocols/esp_http_client/sdkconfig.defaults b/examples/protocols/esp_http_client/sdkconfig.defaults new file mode 100644 index 00000000..2b9ef82e --- /dev/null +++ b/examples/protocols/esp_http_client/sdkconfig.defaults @@ -0,0 +1,3 @@ +CONFIG_NEWLIB_LIBRARY_LEVEL_NORMAL=y +CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=1024 +CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=16384