Skip to content

Commit

Permalink
feat(websocket): added esp_websocket_client_set_header API
Browse files Browse the repository at this point in the history
  • Loading branch information
suren-gabrielyan-espressif committed Sep 4, 2023
1 parent 6c7259f commit 8060715
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
14 changes: 13 additions & 1 deletion components/esp_websocket_client/esp_websocket_client.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -756,6 +756,18 @@ esp_err_t esp_websocket_client_set_headers(esp_websocket_client_handle_t client,
return ret;
}

esp_err_t esp_websocket_client_set_header(esp_websocket_client_handle_t client, const char *key, const char *value)
{
if (client == NULL || key == NULL) { // TODO if value is NULL, it will remove existing key
return ESP_ERR_INVALID_ARG;
}

xSemaphoreTakeRecursive(client->lock, portMAX_DELAY);
esp_err_t ret = esp_transport_ws_set_header(client->transport, key, value);
xSemaphoreGiveRecursive(client->lock);
return ret;
}

static esp_err_t esp_websocket_client_recv(esp_websocket_client_handle_t client)
{
int rlen;
Expand Down
17 changes: 16 additions & 1 deletion components/esp_websocket_client/include/esp_websocket_client.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -165,6 +165,21 @@ esp_err_t esp_websocket_client_set_uri(esp_websocket_client_handle_t client, con
*/
esp_err_t esp_websocket_client_set_headers(esp_websocket_client_handle_t client, const char *headers);

/**
* @brief Set websocket headers for the client
*
* Notes:
* - should not be used together with `esp_websocket_client_set_headers`
*
* @param[in] client The client
* @param[in] key The header key
* @param[in] value The header value
*
* @return esp_err_t
*/
esp_err_t esp_websocket_client_set_header(esp_websocket_client_handle_t client, const char *key, const char *value);

/**
* @brief Open the WebSocket connection
*
Expand Down

0 comments on commit 8060715

Please sign in to comment.