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 {
85
85
char * subprotocol ;
86
86
char * user_agent ;
87
87
char * headers ;
88
+ const char * response_headers ;
88
89
int pingpong_timeout_sec ;
89
90
size_t ping_interval_sec ;
90
91
const char * cert ;
@@ -1020,6 +1021,9 @@ static void esp_websocket_client_task(void *pv)
1020
1021
client -> config -> host ,
1021
1022
client -> config -> port ,
1022
1023
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
1023
1027
if (result < 0 ) {
1024
1028
esp_tls_error_handle_t error_handle = esp_transport_get_error_handle (client -> transport );
1025
1029
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
1341
1345
return client -> wait_timeout_ms ;
1342
1346
}
1343
1347
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
+
1344
1360
esp_err_t esp_websocket_client_set_reconnect_timeout (esp_websocket_client_handle_t client , int reconnect_timeout_ms )
1345
1361
{
1346
1362
if (client == NULL ) {
Original file line number Diff line number Diff line change @@ -195,6 +195,11 @@ static void websocket_app_start(void)
195
195
}
196
196
vTaskDelay (1000 / portTICK_PERIOD_MS );
197
197
}
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
+ }
198
203
199
204
vTaskDelay (1000 / portTICK_PERIOD_MS );
200
205
// Sending text data
Original file line number Diff line number Diff line change 21
21
extern "C" {
22
22
#endif
23
23
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
+
24
29
typedef struct esp_websocket_client * esp_websocket_client_handle_t ;
25
30
26
31
ESP_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
432
437
*/
433
438
int esp_websocket_client_get_reconnect_timeout (esp_websocket_client_handle_t client );
434
439
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
435
453
/**
436
454
* @brief Set next reconnect timeout for client.
437
455
*
You can’t perform that action at this time.
0 commit comments