From dc16b8243fde94cea063c58d790d0a86e305e1ae Mon Sep 17 00:00:00 2001 From: David Cermak Date: Wed, 24 Apr 2019 14:49:20 +0200 Subject: [PATCH] esp_http_client: added example test case to verify error code received when connecting to non-existent url --- .../esp_http_client/esp_http_client_test.py | 3 ++- .../main/esp_http_client_example.c | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/examples/protocols/esp_http_client/esp_http_client_test.py b/examples/protocols/esp_http_client/esp_http_client_test.py index 0d161da4c2..1c9c1d5701 100644 --- a/examples/protocols/esp_http_client/esp_http_client_test.py +++ b/examples/protocols/esp_http_client/esp_http_client_test.py @@ -45,8 +45,9 @@ def test_examples_protocol_esp_http_client(env, extra_data): dut1.expect(re.compile(r"HTTP Absolute path redirect Status = 200, content_length = (\d)")) dut1.expect(re.compile(r"HTTPS Status = 200, content_length = (\d)")) dut1.expect(re.compile(r"HTTP redirect to HTTPS Status = 200, content_length = (\d)"), timeout=10) - dut1.expect(re.compile(r"HTTP chunk encoding Status = 200, content_length = -1")) + dut1.expect(re.compile(r"HTTP chunk encoding Status = 200, content_length = (\d)")) dut1.expect(re.compile(r"HTTP Stream reader Status = 200, content_length = (\d)")) + dut1.expect(re.compile(r"Last esp error code: 0x8001")) dut1.expect("Finish http example") 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 d6ae5b270f..6a642a73f4 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 @@ -492,6 +492,25 @@ static void https_async() esp_http_client_cleanup(client); } +static void https_with_invalid_url() +{ + esp_http_client_config_t config = { + .url = "https://not.existent.url", + .event_handler = _http_event_handler, + }; + esp_http_client_handle_t client = esp_http_client_init(&config); + esp_err_t err = esp_http_client_perform(client); + + if (err == ESP_OK) { + ESP_LOGI(TAG, "HTTPS Status = %d, content_length = %d", + esp_http_client_get_status_code(client), + esp_http_client_get_content_length(client)); + } else { + ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err)); + } + esp_http_client_cleanup(client); +} + static void http_test_task(void *pvParameters) { @@ -508,6 +527,7 @@ static void http_test_task(void *pvParameters) http_download_chunk(); http_perform_as_stream_reader(); https_async(); + https_with_invalid_url(); ESP_LOGI(TAG, "Finish http example"); vTaskDelete(NULL); @@ -529,6 +549,7 @@ void app_main() * examples/protocols/README.md for more information about this function. */ ESP_ERROR_CHECK(example_connect()); + ESP_LOGI(TAG, "Connected to AP, begin http example"); xTaskCreate(&http_test_task, "http_test_task", 8192, NULL, 5, NULL); } -- 2.40.0