@@ -11,6 +11,27 @@ use alloy::transports::{TransportError, TransportFut};
1111
1212use graph:: prelude:: alloy:: transports:: { http:: Http , ipc:: IpcConnect , ws:: WsConnect } ;
1313
14+ /// Compression method for RPC requests.
15+ #[ derive( Clone , Copy , Debug , Default , PartialEq , Eq ) ]
16+ pub enum Compression {
17+ #[ default]
18+ None ,
19+ Gzip ,
20+ Brotli ,
21+ Deflate ,
22+ }
23+
24+ impl std:: fmt:: Display for Compression {
25+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
26+ match self {
27+ Compression :: None => write ! ( f, "none" ) ,
28+ Compression :: Gzip => write ! ( f, "gzip" ) ,
29+ Compression :: Brotli => write ! ( f, "brotli" ) ,
30+ Compression :: Deflate => write ! ( f, "deflate" ) ,
31+ }
32+ }
33+ }
34+
1435/// Abstraction over different transport types for Alloy providers.
1536#[ derive( Clone , Debug ) ]
1637pub enum Transport {
@@ -46,17 +67,24 @@ impl Transport {
4667 headers : graph:: http:: HeaderMap ,
4768 metrics : Arc < EndpointMetrics > ,
4869 provider : impl AsRef < str > ,
49- gzip : bool ,
70+ compression : Compression ,
5071 ) -> Self {
5172 let mut client_builder = reqwest:: Client :: builder ( ) . default_headers ( headers) ;
5273
53- if gzip {
54- client_builder = client_builder. gzip ( true ) ;
74+ match compression {
75+ Compression :: None => { }
76+ Compression :: Gzip => {
77+ client_builder = client_builder. gzip ( true ) ;
78+ }
79+ Compression :: Brotli => {
80+ client_builder = client_builder. brotli ( true ) ;
81+ }
82+ Compression :: Deflate => {
83+ client_builder = client_builder. deflate ( true ) ;
84+ }
5585 }
5686
57- let client = client_builder
58- . build ( )
59- . expect ( "Failed to build HTTP client" ) ;
87+ let client = client_builder. build ( ) . expect ( "Failed to build HTTP client" ) ;
6088
6189 let http_transport = Http :: with_client ( client, rpc) ;
6290 let metrics_transport = MetricsHttp :: new ( http_transport, metrics, provider. as_ref ( ) . into ( ) ) ;
0 commit comments