return http_header_set(client->request->headers, key, value);
}
+esp_err_t esp_http_client_get_header(esp_http_client_handle_t client, const char *key, char **value)
+{
+ return http_header_get(client->request->headers, key, value);
+}
+
esp_err_t esp_http_client_delete_header(esp_http_client_handle_t client, const char *key)
{
return http_header_delete(client->request->headers, key);
client->post_len = len;
ESP_LOGD(TAG, "set post file length = %d", len);
if (client->post_data) {
- err = esp_http_client_set_header(client, "Content-Type", "application/x-www-form-urlencoded");
+ char *value = NULL;
+ if ((err = esp_http_client_get_header(client, "Content-Type", &value)) != ESP_OK) {
+ return err;
+ }
+ if (value == NULL) {
+ err = esp_http_client_set_header(client, "Content-Type", "application/x-www-form-urlencoded");
+ }
} else {
client->post_len = 0;
err = esp_http_client_set_header(client, "Content-Type", NULL);
esp_err_t esp_http_client_set_url(esp_http_client_handle_t client, const char *url);
/**
- * @brief Set post data, this function must be called before `esp_http_client_finalize_open` or perform
+ * @brief Set post data, this function must be called before `esp_http_client_perform`.
* Note: The data parameter passed to this function is a pointer and this function will not copy the data
*
* @param[in] client The esp_http_client handle
*/
esp_err_t esp_http_client_set_header(esp_http_client_handle_t client, const char *key, const char *value);
+/**
+ * @brief Get http request header.
+ * The value parameter will be set to NULL if there is no header which is same as
+ * the key specified, otherwise the address of header value will be assigned to value parameter.
+ * This function must be called after `esp_http_client_init`.
+ *
+ * @param[in] client The esp_http_client handle
+ * @param[in] key The header key
+ * @param[out] value The header value
+ *
+ * @return
+ * - ESP_OK
+ * - ESP_FAIL
+ */
+esp_err_t esp_http_client_get_header(esp_http_client_handle_t client, const char *key, char **value);
+
/**
* @brief Set http request method
*
/**
- * @brief Check response data is chunked, must call after `esp_http_client_finalize_open`
+ * @brief Check response data is chunked
*
* @param[in] client The esp_http_client handle
*
/**
- * @brief Get http response status code, the valid value if this function invoke after `esp_http_client_perform` or `esp_http_client_finalize_open`
+ * @brief Get http response status code, the valid value if this function invoke after `esp_http_client_perform`
*
* @param[in] client The esp_http_client handle
*
/**
* @brief Get http response content length (from header Content-Length)
- * the valid value if this function invoke after `esp_http_client_perform` or `esp_http_client_finalize_open`
+ * the valid value if this function invoke after `esp_http_client_perform`
*
* @param[in] client The esp_http_client handle
*