@@ -2,6 +2,7 @@ use graph::{
22 anyhow:: Error ,
33 blockchain:: BlockchainKind ,
44 components:: network_provider:: ChainName ,
5+ endpoint:: Compression ,
56 env:: ENV_VARS ,
67 firehose:: { SubgraphLimit , SUBGRAPHS_PER_CONN } ,
78 itertools:: Itertools ,
@@ -502,6 +503,7 @@ impl ChainSection {
502503 features,
503504 headers : Default :: default ( ) ,
504505 rules : vec ! [ ] ,
506+ compression : Compression :: None ,
505507 } ) ,
506508 } ;
507509 let entry = chains. entry ( name. to_string ( ) ) . or_insert_with ( || Chain {
@@ -705,6 +707,10 @@ pub struct Web3Provider {
705707
706708 #[ serde( default , rename = "match" ) ]
707709 rules : Vec < Web3Rule > ,
710+
711+ /// Compression method for RPC requests and responses
712+ #[ serde( default ) ]
713+ pub compression : Compression ,
708714}
709715
710716impl Web3Provider {
@@ -901,6 +907,7 @@ impl<'de> Deserialize<'de> for Provider {
901907 . ok_or_else ( || serde:: de:: Error :: missing_field ( "features" ) ) ?,
902908 headers : headers. unwrap_or_else ( HeaderMap :: new) ,
903909 rules : nodes,
910+ compression : Compression :: None ,
904911 } ) ,
905912 } ;
906913
@@ -1307,6 +1314,7 @@ mod tests {
13071314 features: BTreeSet :: new( ) ,
13081315 headers: HeaderMap :: new( ) ,
13091316 rules: Vec :: new( ) ,
1317+ compression: Compression :: None ,
13101318 } ) ,
13111319 } ,
13121320 actual
@@ -1333,6 +1341,7 @@ mod tests {
13331341 features: BTreeSet :: new( ) ,
13341342 headers: HeaderMap :: new( ) ,
13351343 rules: Vec :: new( ) ,
1344+ compression: Compression :: None ,
13361345 } ) ,
13371346 } ,
13381347 actual
@@ -1440,6 +1449,7 @@ mod tests {
14401449 features,
14411450 headers,
14421451 rules: Vec :: new( ) ,
1452+ compression: Compression :: None ,
14431453 } ) ,
14441454 } ,
14451455 actual
@@ -1465,6 +1475,7 @@ mod tests {
14651475 features: BTreeSet :: new( ) ,
14661476 headers: HeaderMap :: new( ) ,
14671477 rules: Vec :: new( ) ,
1478+ compression: Compression :: None ,
14681479 } ) ,
14691480 } ,
14701481 actual
@@ -1834,6 +1845,7 @@ mod tests {
18341845 features: BTreeSet :: new( ) ,
18351846 headers: HeaderMap :: new( ) ,
18361847 rules: Vec :: new( ) ,
1848+ compression: Compression :: None ,
18371849 } ) ,
18381850 } ,
18391851 actual
@@ -1846,6 +1858,66 @@ mod tests {
18461858 assert ! ( SubgraphLimit :: Limit ( 10 ) > SubgraphLimit :: Disabled ) ;
18471859 }
18481860
1861+ #[ test]
1862+ fn it_parses_web3_provider_with_compression ( ) {
1863+ let actual = toml:: from_str (
1864+ r#"
1865+ label = "compressed"
1866+ details = { type = "web3", url = "http://localhost:8545", features = ["archive"], compression = "gzip" }
1867+ "# ,
1868+ )
1869+ . unwrap ( ) ;
1870+
1871+ assert_eq ! (
1872+ Provider {
1873+ label: "compressed" . to_owned( ) ,
1874+ details: ProviderDetails :: Web3 ( Web3Provider {
1875+ transport: Transport :: Rpc ,
1876+ url: "http://localhost:8545" . to_owned( ) ,
1877+ features: {
1878+ let mut features = BTreeSet :: new( ) ;
1879+ features. insert( "archive" . to_string( ) ) ;
1880+ features
1881+ } ,
1882+ headers: HeaderMap :: new( ) ,
1883+ rules: Vec :: new( ) ,
1884+ compression: Compression :: Gzip ,
1885+ } ) ,
1886+ } ,
1887+ actual
1888+ ) ;
1889+ }
1890+
1891+ #[ test]
1892+ fn it_parses_web3_provider_with_no_compression ( ) {
1893+ let actual = toml:: from_str (
1894+ r#"
1895+ label = "uncompressed"
1896+ details = { type = "web3", url = "http://localhost:8545", features = ["archive"], compression = "none" }
1897+ "# ,
1898+ )
1899+ . unwrap ( ) ;
1900+
1901+ assert_eq ! (
1902+ Provider {
1903+ label: "uncompressed" . to_owned( ) ,
1904+ details: ProviderDetails :: Web3 ( Web3Provider {
1905+ transport: Transport :: Rpc ,
1906+ url: "http://localhost:8545" . to_owned( ) ,
1907+ features: {
1908+ let mut features = BTreeSet :: new( ) ;
1909+ features. insert( "archive" . to_string( ) ) ;
1910+ features
1911+ } ,
1912+ headers: HeaderMap :: new( ) ,
1913+ rules: Vec :: new( ) ,
1914+ compression: Compression :: None ,
1915+ } ) ,
1916+ } ,
1917+ actual
1918+ ) ;
1919+ }
1920+
18491921 #[ test]
18501922 fn duplicated_labels_are_not_allowed_within_chain ( ) {
18511923 let mut actual = toml:: from_str :: < ChainSection > (
0 commit comments