@@ -101,6 +101,8 @@ typedef struct {
101
101
const char * cert_common_name ;
102
102
esp_err_t (* crt_bundle_attach )(void * conf );
103
103
esp_transport_handle_t ext_transport ;
104
+ char * response_headers ;
105
+ size_t response_headers_len ;
104
106
} websocket_config_storage_t ;
105
107
106
108
typedef enum {
@@ -215,6 +217,9 @@ static esp_err_t esp_websocket_client_dispatch_event(esp_websocket_client_handle
215
217
event_data .error_handle .error_type = client -> error_handle .error_type ;
216
218
event_data .error_handle .esp_ws_handshake_status_code = client -> error_handle .esp_ws_handshake_status_code ;
217
219
220
+ // Add response headers to event data
221
+ event_data .response_headers = client -> config -> response_headers ;
222
+ event_data .response_headers_len = client -> config -> response_headers_len ;
218
223
219
224
if ((err = esp_event_post_to (client -> event_handle ,
220
225
WEBSOCKET_EVENTS , event ,
@@ -420,6 +425,7 @@ static esp_err_t esp_websocket_client_destroy_config(esp_websocket_client_handle
420
425
free (cfg -> subprotocol );
421
426
free (cfg -> user_agent );
422
427
free (cfg -> headers );
428
+ free (cfg -> response_headers );
423
429
memset (cfg , 0 , sizeof (websocket_config_storage_t ));
424
430
free (client -> config );
425
431
client -> config = NULL ;
@@ -474,7 +480,11 @@ static esp_err_t set_websocket_transport_optional_settings(esp_websocket_client_
474
480
.user_agent = client -> config -> user_agent ,
475
481
.headers = client -> config -> headers ,
476
482
.auth = client -> config -> auth ,
477
- .propagate_control_frames = true
483
+ .propagate_control_frames = true,
484
+ #if WS_TRANSPORT_STORE_RESPONSE_HEADERS
485
+ .response_headers = client -> config -> response_headers ,
486
+ .response_headers_len = client -> config -> response_headers_len
487
+ #endif
478
488
};
479
489
return esp_transport_ws_set_config (trans , & config );
480
490
}
@@ -726,6 +736,17 @@ esp_websocket_client_handle_t esp_websocket_client_init(const esp_websocket_clie
726
736
client -> config -> crt_bundle_attach = config -> crt_bundle_attach ;
727
737
client -> config -> ext_transport = config -> ext_transport ;
728
738
739
+ // Allocate memory for response_headers if length is specified
740
+ if (config -> response_headers_len > 0 ) {
741
+ client -> config -> response_headers = malloc (config -> response_headers_len );
742
+ ESP_WS_CLIENT_MEM_CHECK (TAG , client -> config -> response_headers , goto _websocket_init_fail );
743
+ memset (client -> config -> response_headers , 0 , config -> response_headers_len );
744
+ client -> config -> response_headers_len = config -> response_headers_len ;
745
+ } else {
746
+ client -> config -> response_headers = NULL ;
747
+ client -> config -> response_headers_len = 0 ;
748
+ }
749
+
729
750
if (config -> uri ) {
730
751
if (esp_websocket_client_set_uri (client , config -> uri ) != ESP_OK ) {
731
752
ESP_LOGE (TAG , "Invalid uri" );
0 commit comments