@@ -18,13 +18,14 @@ use serde::{Deserialize, Serialize};
1818use tracing:: { debug, info, warn} ;
1919use url:: Url ;
2020
21- use super :: { MUX_PATH_ENV , PbsConfig , RelayConfig , load_optional_env_var} ;
21+ use super :: { MUX_PATH_ENV , MUXER_HTTP_MAX_LENGTH , PbsConfig , RelayConfig , load_optional_env_var} ;
2222use crate :: {
23- config:: { remove_duplicate_keys, safe_read_http_response } ,
23+ config:: remove_duplicate_keys,
2424 interop:: { lido:: utils:: * , ssv:: utils:: * } ,
2525 pbs:: RelayClient ,
2626 types:: { BlsPublicKey , Chain } ,
2727 utils:: default_bool,
28+ wire:: read_chunked_body_with_max,
2829} ;
2930
3031#[ derive( Debug , Clone , Deserialize , Serialize ) ]
@@ -156,7 +157,7 @@ pub struct MuxConfig {
156157
157158impl MuxConfig {
158159 /// Returns the env, actual path, and internal path to use for the file
159- /// loader. In File mode, validates the mux file prior to returning.
160+ /// loader. In File mode, validates the mux file prior to returning.
160161 pub fn loader_env ( & self ) -> eyre:: Result < Option < ( String , String , String ) > > {
161162 let Some ( loader) = self . loader . as_ref ( ) else {
162163 return Ok ( None ) ;
@@ -237,7 +238,16 @@ impl MuxKeysLoader {
237238 }
238239 let client = reqwest:: ClientBuilder :: new ( ) . timeout ( http_timeout) . build ( ) ?;
239240 let response = client. get ( url) . send ( ) . await ?;
240- let pubkey_bytes = safe_read_http_response ( response) . await ?;
241+ let status = response. status ( ) ;
242+ let pubkey_bytes = read_chunked_body_with_max ( response, MUXER_HTTP_MAX_LENGTH )
243+ . await
244+ . wrap_err ( "Failed to read response body" ) ?;
245+ if !status. is_success ( ) {
246+ bail ! (
247+ "Request failed with status: {status}, body: {}" ,
248+ String :: from_utf8_lossy( & pubkey_bytes)
249+ ) ;
250+ }
241251 serde_json:: from_slice ( & pubkey_bytes)
242252 . wrap_err ( "failed to fetch mux keys from HTTP endpoint" )
243253 }
0 commit comments