File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed
components/esp_websocket_client Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ typedef struct {
8585 char * subprotocol ;
8686 char * user_agent ;
8787 char * headers ;
88+ const char * response_headers ;
8889 int pingpong_timeout_sec ;
8990 size_t ping_interval_sec ;
9091 const char * cert ;
@@ -1020,6 +1021,9 @@ static void esp_websocket_client_task(void *pv)
10201021 client -> config -> host ,
10211022 client -> config -> port ,
10221023 client -> config -> network_timeout_ms );
1024+ #if WS_TRANSPORT_GET_RESPONSE_HEADER
1025+ client -> config -> response_headers = esp_transport_ws_get_response_header (client -> transport );
1026+ #endif
10231027 if (result < 0 ) {
10241028 esp_tls_error_handle_t error_handle = esp_transport_get_error_handle (client -> transport );
10251029 client -> error_handle .esp_ws_handshake_status_code = esp_transport_ws_get_upgrade_request_status (client -> transport );
@@ -1341,6 +1345,18 @@ int esp_websocket_client_get_reconnect_timeout(esp_websocket_client_handle_t cli
13411345 return client -> wait_timeout_ms ;
13421346}
13431347
1348+ #if WS_TRANSPORT_GET_RESPONSE_HEADER
1349+ const char * esp_websocket_client_get_response_header (esp_websocket_client_handle_t client )
1350+ {
1351+ if (client == NULL ) {
1352+ ESP_LOGW (TAG , "Client was not initialized" );
1353+ return NULL ;
1354+ }
1355+
1356+ return client -> config -> response_headers ;
1357+ }
1358+ #endif
1359+
13441360esp_err_t esp_websocket_client_set_reconnect_timeout (esp_websocket_client_handle_t client , int reconnect_timeout_ms )
13451361{
13461362 if (client == NULL ) {
Original file line number Diff line number Diff line change @@ -195,6 +195,11 @@ static void websocket_app_start(void)
195195 }
196196 vTaskDelay (1000 / portTICK_PERIOD_MS );
197197 }
198+ /* WebSocket handshake response headers if available */
199+ const char * headers = esp_websocket_client_get_response_header (client );
200+ if (headers ) {
201+ ESP_LOGI (TAG , "WebSocket response headers:\n%s" , headers );
202+ }
198203
199204 vTaskDelay (1000 / portTICK_PERIOD_MS );
200205 // Sending text data
Original file line number Diff line number Diff line change 2121extern "C" {
2222#endif
2323
24+ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL (5 , 5 , 0 )
25+ // Features supported in 5.5.0
26+ #define WS_TRANSPORT_GET_RESPONSE_HEADER 1
27+ #endif
28+
2429typedef struct esp_websocket_client * esp_websocket_client_handle_t ;
2530
2631ESP_EVENT_DECLARE_BASE (WEBSOCKET_EVENTS ); // declaration of the task events family
@@ -432,6 +437,19 @@ esp_err_t esp_websocket_client_set_ping_interval_sec(esp_websocket_client_handle
432437 */
433438int esp_websocket_client_get_reconnect_timeout (esp_websocket_client_handle_t client );
434439
440+ #if WS_TRANSPORT_GET_RESPONSE_HEADER
441+ /**
442+ * @brief Get the response header for client.
443+ *
444+ * Notes:
445+ * - This API should be called after the connection atempt otherwise its result is meaningless
446+ *
447+ * @param[in] client The client
448+ *
449+ * @return The response header
450+ */
451+ const char * esp_websocket_client_get_response_header (esp_websocket_client_handle_t client );
452+ #endif
435453/**
436454 * @brief Set next reconnect timeout for client.
437455 *
You can’t perform that action at this time.
0 commit comments