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 870f859c65..b0bafef2e0 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 @@ -375,7 +375,7 @@ static void http_auth_basic_redirect(void) #endif #if CONFIG_ESP_HTTP_CLIENT_ENABLE_DIGEST_AUTH -static void http_auth_digest(void) +static void http_auth_digest_md5(void) { esp_http_client_config_t config = { .url = "http://user:passwd@"CONFIG_EXAMPLE_HTTP_ENDPOINT"/digest-auth/auth/user/passwd/MD5/never", @@ -385,11 +385,31 @@ static void http_auth_digest(void) esp_err_t err = esp_http_client_perform(client); if (err == ESP_OK) { - ESP_LOGI(TAG, "HTTP Digest Auth Status = %d, content_length = %"PRId64, + ESP_LOGI(TAG, "HTTP MD5 Digest Auth Status = %d, content_length = %"PRId64, 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_LOGE(TAG, "Error performing http request %s", esp_err_to_name(err)); + } + esp_http_client_cleanup(client); +} + +static void http_auth_digest_sha256(void) +{ + esp_http_client_config_t config = { + .url = "http://user:passwd@"CONFIG_EXAMPLE_HTTP_ENDPOINT"/digest-auth/auth/user/passwd/SHA-256/never", + .event_handler = _http_event_handler, + .buffer_size_tx = 1024, // Increase buffer size as header size will increase as it contains SHA-256. + }; + 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, "HTTP SHA256 Digest Auth Status = %d, content_length = %"PRId64, + esp_http_client_get_status_code(client), + esp_http_client_get_content_length(client)); + } else { + ESP_LOGE(TAG, "Error performing http request %s", esp_err_to_name(err)); } esp_http_client_cleanup(client); } @@ -779,7 +799,8 @@ static void http_test_task(void *pvParameters) http_auth_basic_redirect(); #endif #if CONFIG_ESP_HTTP_CLIENT_ENABLE_DIGEST_AUTH - http_auth_digest(); + http_auth_digest_md5(); + http_auth_digest_sha256(); #endif http_encoded_query(); http_relative_redirect(); diff --git a/examples/protocols/esp_http_client/pytest_esp_http_client.py b/examples/protocols/esp_http_client/pytest_esp_http_client.py index 716524c920..853d7f8a4e 100644 --- a/examples/protocols/esp_http_client/pytest_esp_http_client.py +++ b/examples/protocols/esp_http_client/pytest_esp_http_client.py @@ -34,7 +34,8 @@ def test_examples_protocol_esp_http_client(dut: Dut) -> None: dut.expect(r'HTTP HEAD Status = 200, content_length = (\d)') dut.expect(r'HTTP Basic Auth Status = 200, content_length = (\d)') dut.expect(r'HTTP Basic Auth redirect Status = 200, content_length = (\d)') - dut.expect(r'HTTP Digest Auth Status = 200, content_length = (\d)') + dut.expect(r'HTTP MD5 Digest Auth Status = 200, content_length = (\d)') + dut.expect(r'HTTP SHA256 Digest Auth Status = 200, content_length = (\d)') dut.expect(r'HTTP Relative path redirect Status = 200, content_length = (\d)') dut.expect(r'HTTP Absolute path redirect Status = 200, content_length = (\d)') dut.expect(r'HTTP Absolute path redirect \(manual\) Status = 200, content_length = (\d)')