@@ -15,8 +15,10 @@ pub enum CompressionType {
1515 Identity ,
1616}
1717
18-
1918impl CompressionType {
19+ pub fn accept_encoding ( ) -> & ' static str {
20+ "gzip, deflate, br, zstd"
21+ }
2022 pub fn header_value ( & self ) -> String {
2123 match self {
2224 CompressionType :: Gzip => "gzip" . to_string ( ) ,
@@ -32,9 +34,7 @@ impl CompressionType {
3234 . to_string ( ) ,
3335 }
3436 }
35- pub fn from_encoding_header (
36- encoding : & str ,
37- ) -> Result < CompressionType , SubgraphExecutorError > {
37+ pub fn from_encoding_header ( encoding : & str ) -> Result < CompressionType , SubgraphExecutorError > {
3838 let encodings: Vec < & str > = encoding. split ( ',' ) . map ( |s| s. trim ( ) ) . collect ( ) ;
3939 if encodings. len ( ) > 1 {
4040 let types = encodings
@@ -54,43 +54,54 @@ impl CompressionType {
5454 }
5555 }
5656 }
57- pub fn decompress < ' a > ( & ' a self , body : Bytes ) -> BoxFuture < ' a , Result < Bytes , SubgraphExecutorError > > {
57+ pub fn decompress < ' a > (
58+ & ' a self ,
59+ body : Bytes ,
60+ ) -> BoxFuture < ' a , Result < Bytes , SubgraphExecutorError > > {
5861 Box :: pin ( async move {
5962 match self {
6063 CompressionType :: Gzip => {
6164 let mut decoder = GzipDecoder :: new ( body. as_ref ( ) ) ;
6265 let mut buf = Vec :: new ( ) ;
63- let _ = decoder
64- . read_to_end ( & mut buf)
65- . await
66- . map_err ( |e| SubgraphExecutorError :: DecompressionFailed ( self . header_value ( ) , e. to_string ( ) ) ) ;
66+ let _ = decoder. read_to_end ( & mut buf) . await . map_err ( |e| {
67+ SubgraphExecutorError :: DecompressionFailed (
68+ self . header_value ( ) ,
69+ e. to_string ( ) ,
70+ )
71+ } ) ;
6772 Ok ( Bytes :: from ( buf) )
6873 }
6974 CompressionType :: Deflate => {
7075 let mut decoder = DeflateDecoder :: new ( body. as_ref ( ) ) ;
7176 let mut buf = Vec :: new ( ) ;
72- let _ = decoder
73- . read_to_end ( & mut buf)
74- . await
75- . map_err ( |e| SubgraphExecutorError :: DecompressionFailed ( self . header_value ( ) , e. to_string ( ) ) ) ;
77+ let _ = decoder. read_to_end ( & mut buf) . await . map_err ( |e| {
78+ SubgraphExecutorError :: DecompressionFailed (
79+ self . header_value ( ) ,
80+ e. to_string ( ) ,
81+ )
82+ } ) ;
7683 Ok ( Bytes :: from ( buf) )
7784 }
7885 CompressionType :: Brotli => {
7986 let mut decoder = BrotliDecoder :: new ( body. as_ref ( ) ) ;
8087 let mut buf = Vec :: new ( ) ;
81- let _ = decoder
82- . read_to_end ( & mut buf)
83- . await
84- . map_err ( |e| SubgraphExecutorError :: DecompressionFailed ( self . header_value ( ) , e. to_string ( ) ) ) ;
88+ let _ = decoder. read_to_end ( & mut buf) . await . map_err ( |e| {
89+ SubgraphExecutorError :: DecompressionFailed (
90+ self . header_value ( ) ,
91+ e. to_string ( ) ,
92+ )
93+ } ) ;
8594 Ok ( Bytes :: from ( buf) )
8695 }
8796 CompressionType :: Zstd => {
8897 let mut decoder = ZstdDecoder :: new ( body. as_ref ( ) ) ;
8998 let mut buf = Vec :: new ( ) ;
90- let _ = decoder
91- . read_to_end ( & mut buf)
92- . await
93- . map_err ( |e| SubgraphExecutorError :: DecompressionFailed ( self . header_value ( ) , e. to_string ( ) ) ) ;
99+ let _ = decoder. read_to_end ( & mut buf) . await . map_err ( |e| {
100+ SubgraphExecutorError :: DecompressionFailed (
101+ self . header_value ( ) ,
102+ e. to_string ( ) ,
103+ )
104+ } ) ;
94105 Ok ( Bytes :: from ( buf) )
95106 }
96107 CompressionType :: Multiple ( types) => {
0 commit comments