mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-16 12:02:11 +02:00
Add User-Agent and additional headers to esp_websocket_client
Merges https://github.com/espressif/esp-idf/pull/4345 * Original commit: espressif/esp-idf@9200250f51
This commit is contained in:
@ -63,6 +63,8 @@ typedef struct {
|
|||||||
void *user_context;
|
void *user_context;
|
||||||
int network_timeout_ms;
|
int network_timeout_ms;
|
||||||
char *subprotocol;
|
char *subprotocol;
|
||||||
|
char *user_agent;
|
||||||
|
char *headers;
|
||||||
} websocket_config_storage_t;
|
} websocket_config_storage_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -179,6 +181,16 @@ static esp_err_t esp_websocket_client_set_config(esp_websocket_client_handle_t c
|
|||||||
cfg->subprotocol = strdup(config->subprotocol);
|
cfg->subprotocol = strdup(config->subprotocol);
|
||||||
ESP_WS_CLIENT_MEM_CHECK(TAG, cfg->subprotocol, return ESP_ERR_NO_MEM);
|
ESP_WS_CLIENT_MEM_CHECK(TAG, cfg->subprotocol, return ESP_ERR_NO_MEM);
|
||||||
}
|
}
|
||||||
|
if (config->user_agent) {
|
||||||
|
free(cfg->user_agent);
|
||||||
|
cfg->user_agent = strdup(config->user_agent);
|
||||||
|
ESP_WS_CLIENT_MEM_CHECK(TAG, cfg->user_agent, return ESP_ERR_NO_MEM);
|
||||||
|
}
|
||||||
|
if (config->headers) {
|
||||||
|
free(cfg->headers);
|
||||||
|
cfg->headers = strdup(config->headers);
|
||||||
|
ESP_WS_CLIENT_MEM_CHECK(TAG, cfg->headers, return ESP_ERR_NO_MEM);
|
||||||
|
}
|
||||||
|
|
||||||
cfg->network_timeout_ms = WEBSOCKET_NETWORK_TIMEOUT_MS;
|
cfg->network_timeout_ms = WEBSOCKET_NETWORK_TIMEOUT_MS;
|
||||||
cfg->user_context = config->user_context;
|
cfg->user_context = config->user_context;
|
||||||
@ -207,6 +219,8 @@ static esp_err_t esp_websocket_client_destroy_config(esp_websocket_client_handle
|
|||||||
free(cfg->username);
|
free(cfg->username);
|
||||||
free(cfg->password);
|
free(cfg->password);
|
||||||
free(cfg->subprotocol);
|
free(cfg->subprotocol);
|
||||||
|
free(cfg->user_agent);
|
||||||
|
free(cfg->headers);
|
||||||
memset(cfg, 0, sizeof(websocket_config_storage_t));
|
memset(cfg, 0, sizeof(websocket_config_storage_t));
|
||||||
free(client->config);
|
free(client->config);
|
||||||
client->config = NULL;
|
client->config = NULL;
|
||||||
@ -221,6 +235,12 @@ static void set_websocket_transport_optional_settings(esp_websocket_client_handl
|
|||||||
if (trans && client->config->subprotocol) {
|
if (trans && client->config->subprotocol) {
|
||||||
esp_transport_ws_set_subprotocol(trans, client->config->subprotocol);
|
esp_transport_ws_set_subprotocol(trans, client->config->subprotocol);
|
||||||
}
|
}
|
||||||
|
if (trans && client->config->user_agent) {
|
||||||
|
esp_transport_ws_set_user_agent(trans, client->config->user_agent);
|
||||||
|
}
|
||||||
|
if (trans && client->config->headers) {
|
||||||
|
esp_transport_ws_set_headers(trans, client->config->headers);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_websocket_client_handle_t esp_websocket_client_init(const esp_websocket_client_config_t *config)
|
esp_websocket_client_handle_t esp_websocket_client_init(const esp_websocket_client_config_t *config)
|
||||||
|
@ -92,6 +92,8 @@ typedef struct {
|
|||||||
const char *cert_pem; /*!< SSL Certification, PEM format as string, if the client requires to verify server */
|
const char *cert_pem; /*!< SSL Certification, PEM format as string, if the client requires to verify server */
|
||||||
esp_websocket_transport_t transport; /*!< Websocket transport type, see `esp_websocket_transport_t */
|
esp_websocket_transport_t transport; /*!< Websocket transport type, see `esp_websocket_transport_t */
|
||||||
char *subprotocol; /*!< Websocket subprotocol */
|
char *subprotocol; /*!< Websocket subprotocol */
|
||||||
|
char *user_agent; /*!< Websocket user-agent */
|
||||||
|
char *headers; /*!< Websocket additional headers */
|
||||||
} esp_websocket_client_config_t;
|
} esp_websocket_client_config_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user