Merge branch 'feature/http_client_head' into 'master'

esp_http_client: add head method support

See merge request idf/esp-idf!2895
This commit is contained in:
Ivan Grokhotkov 2018-08-08 20:58:39 +08:00
commit ee3f64cbad
4 changed files with 21 additions and 1 deletions

View file

@ -135,7 +135,8 @@ static const char *HTTP_METHOD_MAPPING[] = {
"POST",
"PUT",
"PATCH",
"DELETE"
"DELETE",
"HEAD"
};
/**
@ -705,6 +706,11 @@ static int esp_http_client_get_data(esp_http_client_handle_t client)
if (client->state < HTTP_STATE_RES_COMPLETE_HEADER) {
return ESP_FAIL;
}
if (client->connection_info.method == HTTP_METHOD_HEAD) {
return 0;
}
esp_http_buffer_t *res_buffer = client->response->buffer;
ESP_LOGD(TAG, "data_process=%d, content_length=%d", client->response->data_process, client->response->content_length);

View file

@ -76,6 +76,7 @@ typedef enum {
HTTP_METHOD_PUT, /*!< HTTP PUT Method */
HTTP_METHOD_PATCH, /*!< HTTP PATCH Method */
HTTP_METHOD_DELETE, /*!< HTTP DELETE Method */
HTTP_METHOD_HEAD, /*!< HTTP HEAD Method */
HTTP_METHOD_MAX,
} esp_http_client_method_t;

View file

@ -35,6 +35,7 @@ def test_examples_protocol_esp_http_client(env, extra_data):
dut1.expect(re.compile(r"HTTP PUT Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP PATCH Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP DELETE Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP HEAD Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP Basic Auth Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP Basic Auth redirect Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP Digest Auth Status = 200, content_length = (\d)"))

View file

@ -136,6 +136,18 @@ static void http_rest()
ESP_LOGE(TAG, "HTTP DELETE request failed: %s", esp_err_to_name(err));
}
//HEAD
esp_http_client_set_url(client, "http://httpbin.org/get");
esp_http_client_set_method(client, HTTP_METHOD_HEAD);
err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP HEAD Status = %d, content_length = %d",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "HTTP HEAD request failed: %s", esp_err_to_name(err));
}
esp_http_client_cleanup(client);
}