@@ -502,6 +502,7 @@ impl ChainSection {
502
502
features,
503
503
headers : Default :: default ( ) ,
504
504
rules : vec ! [ ] ,
505
+ compression : Compression :: None ,
505
506
} ) ,
506
507
} ;
507
508
let entry = chains. entry ( name. to_string ( ) ) . or_insert_with ( || Chain {
@@ -705,6 +706,10 @@ pub struct Web3Provider {
705
706
706
707
#[ serde( default , rename = "match" ) ]
707
708
rules : Vec < Web3Rule > ,
709
+
710
+ /// Compression method for RPC requests and responses
711
+ #[ serde( default ) ]
712
+ pub compression : Compression ,
708
713
}
709
714
710
715
impl Web3Provider {
@@ -901,6 +906,7 @@ impl<'de> Deserialize<'de> for Provider {
901
906
. ok_or_else ( || serde:: de:: Error :: missing_field ( "features" ) ) ?,
902
907
headers : headers. unwrap_or_else ( HeaderMap :: new) ,
903
908
rules : nodes,
909
+ compression : Compression :: None ,
904
910
} ) ,
905
911
} ;
906
912
@@ -944,6 +950,25 @@ pub enum Transport {
944
950
Ipc ,
945
951
}
946
952
953
+ #[ derive( Copy , Clone , Debug , Deserialize , Serialize , PartialEq ) ]
954
+ pub enum Compression {
955
+ #[ serde( rename = "none" ) ]
956
+ None ,
957
+ #[ serde( rename = "gzip" ) ]
958
+ Gzip ,
959
+ // Future compression methods can be added here:
960
+ // #[serde(rename = "brotli")]
961
+ // Brotli,
962
+ // #[serde(rename = "deflate")]
963
+ // Deflate,
964
+ }
965
+
966
+ impl Default for Compression {
967
+ fn default ( ) -> Self {
968
+ Compression :: None
969
+ }
970
+ }
971
+
947
972
impl Default for Transport {
948
973
fn default ( ) -> Self {
949
974
Self :: Rpc
@@ -1307,6 +1332,7 @@ mod tests {
1307
1332
features: BTreeSet :: new( ) ,
1308
1333
headers: HeaderMap :: new( ) ,
1309
1334
rules: Vec :: new( ) ,
1335
+ compression: Compression :: None ,
1310
1336
} ) ,
1311
1337
} ,
1312
1338
actual
@@ -1333,6 +1359,7 @@ mod tests {
1333
1359
features: BTreeSet :: new( ) ,
1334
1360
headers: HeaderMap :: new( ) ,
1335
1361
rules: Vec :: new( ) ,
1362
+ compression: Compression :: None ,
1336
1363
} ) ,
1337
1364
} ,
1338
1365
actual
@@ -1440,6 +1467,7 @@ mod tests {
1440
1467
features,
1441
1468
headers,
1442
1469
rules: Vec :: new( ) ,
1470
+ compression: Compression :: None ,
1443
1471
} ) ,
1444
1472
} ,
1445
1473
actual
@@ -1465,6 +1493,7 @@ mod tests {
1465
1493
features: BTreeSet :: new( ) ,
1466
1494
headers: HeaderMap :: new( ) ,
1467
1495
rules: Vec :: new( ) ,
1496
+ compression: Compression :: None ,
1468
1497
} ) ,
1469
1498
} ,
1470
1499
actual
@@ -1834,6 +1863,7 @@ mod tests {
1834
1863
features: BTreeSet :: new( ) ,
1835
1864
headers: HeaderMap :: new( ) ,
1836
1865
rules: Vec :: new( ) ,
1866
+ compression: Compression :: None ,
1837
1867
} ) ,
1838
1868
} ,
1839
1869
actual
@@ -1846,6 +1876,66 @@ mod tests {
1846
1876
assert ! ( SubgraphLimit :: Limit ( 10 ) > SubgraphLimit :: Disabled ) ;
1847
1877
}
1848
1878
1879
+ #[ test]
1880
+ fn it_parses_web3_provider_with_compression ( ) {
1881
+ let actual = toml:: from_str (
1882
+ r#"
1883
+ label = "compressed"
1884
+ details = { type = "web3", url = "http://localhost:8545", features = ["archive"], compression = "gzip" }
1885
+ "# ,
1886
+ )
1887
+ . unwrap ( ) ;
1888
+
1889
+ assert_eq ! (
1890
+ Provider {
1891
+ label: "compressed" . to_owned( ) ,
1892
+ details: ProviderDetails :: Web3 ( Web3Provider {
1893
+ transport: Transport :: Rpc ,
1894
+ url: "http://localhost:8545" . to_owned( ) ,
1895
+ features: {
1896
+ let mut features = BTreeSet :: new( ) ;
1897
+ features. insert( "archive" . to_string( ) ) ;
1898
+ features
1899
+ } ,
1900
+ headers: HeaderMap :: new( ) ,
1901
+ rules: Vec :: new( ) ,
1902
+ compression: Compression :: Gzip ,
1903
+ } ) ,
1904
+ } ,
1905
+ actual
1906
+ ) ;
1907
+ }
1908
+
1909
+ #[ test]
1910
+ fn it_parses_web3_provider_with_no_compression ( ) {
1911
+ let actual = toml:: from_str (
1912
+ r#"
1913
+ label = "uncompressed"
1914
+ details = { type = "web3", url = "http://localhost:8545", features = ["archive"], compression = "none" }
1915
+ "# ,
1916
+ )
1917
+ . unwrap ( ) ;
1918
+
1919
+ assert_eq ! (
1920
+ Provider {
1921
+ label: "uncompressed" . to_owned( ) ,
1922
+ details: ProviderDetails :: Web3 ( Web3Provider {
1923
+ transport: Transport :: Rpc ,
1924
+ url: "http://localhost:8545" . to_owned( ) ,
1925
+ features: {
1926
+ let mut features = BTreeSet :: new( ) ;
1927
+ features. insert( "archive" . to_string( ) ) ;
1928
+ features
1929
+ } ,
1930
+ headers: HeaderMap :: new( ) ,
1931
+ rules: Vec :: new( ) ,
1932
+ compression: Compression :: None ,
1933
+ } ) ,
1934
+ } ,
1935
+ actual
1936
+ ) ;
1937
+ }
1938
+
1849
1939
#[ test]
1850
1940
fn duplicated_labels_are_not_allowed_within_chain ( ) {
1851
1941
let mut actual = toml:: from_str :: < ChainSection > (
0 commit comments