fix(esp_http_client): Add test case in esp_http_client example

Add a test case in esp_http_client example to test HTTP_METHOD_HEAD
with async mode
pull/13572/head
Harshit Malpani 2023-12-22 16:20:24 +05:30 zatwierdzone przez Mahavir Jain
rodzic 2060f3a645
commit fd859d8931
2 zmienionych plików z 27 dodań i 0 usunięć

Wyświetl plik

@ -624,6 +624,31 @@ static void https_async(void)
ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
}
esp_http_client_cleanup(client);
// Test HTTP_METHOD_HEAD with is_async enabled
config.url = "https://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/get";
config.event_handler = _http_event_handler;
config.crt_bundle_attach = esp_crt_bundle_attach;
config.is_async = true;
config.timeout_ms = 5000;
client = esp_http_client_init(&config);
esp_http_client_set_method(client, HTTP_METHOD_HEAD);
while (1) {
err = esp_http_client_perform(client);
if (err != ESP_ERR_HTTP_EAGAIN) {
break;
}
}
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTPS 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_http_client_cleanup(client);
}
static void https_with_invalid_url(void)

Wyświetl plik

@ -45,6 +45,7 @@ def test_examples_protocol_esp_http_client(dut: Dut) -> None:
# content-len for chunked encoding is typically -1, could be a positive length in some cases
dut.expect(r'HTTP Stream reader Status = 200, content_length = (\d)')
dut.expect(r'HTTPS Status = 200, content_length = (\d)')
dut.expect(r'HTTPS Status = 200, content_length = (\d)')
dut.expect(r'Last esp error code: 0x8001')
dut.expect(r'HTTP GET Status = 200, content_length = (\d)')
dut.expect(r'HTTP POST Status = 200, content_length = (\d)')
@ -91,6 +92,7 @@ def test_examples_protocol_esp_http_client_dynamic_buffer(dut: Dut) -> None:
# content-len for chunked encoding is typically -1, could be a positive length in some cases
dut.expect(r'HTTP Stream reader Status = 200, content_length = (\d)')
dut.expect(r'HTTPS Status = 200, content_length = (\d)')
dut.expect(r'HTTPS Status = 200, content_length = (\d)')
dut.expect(r'Last esp error code: 0x8001')
dut.expect(r'HTTP GET Status = 200, content_length = (\d)')
dut.expect(r'HTTP POST Status = 200, content_length = (\d)')