Skip to content

Commit 89f7d8e

Browse files
committed
accept encoding
1 parent ee5f31e commit 89f7d8e

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

lib/executor/src/executors/compression.rs

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ pub enum CompressionType {
1515
Identity,
1616
}
1717

18-
1918
impl 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) => {

lib/executor/src/executors/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl SubgraphExecutorError {
7979
SubgraphExecutorError::RequestFailure(_, _) => "SUBGRAPH_REQUEST_FAILURE",
8080
SubgraphExecutorError::VariablesSerializationFailure(_, _) => {
8181
"SUBGRAPH_VARIABLES_SERIALIZATION_FAILURE"
82-
},
82+
}
8383
SubgraphExecutorError::UnknownEncoding(_) => "SUBGRAPH_UNKNOWN_ENCODING",
8484
SubgraphExecutorError::DecompressionFailed(_, _) => "SUBGRAPH_DECOMPRESSION_FAILED",
8585
}

lib/executor/src/executors/http.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use async_trait::async_trait;
1212
use bytes::{BufMut, Bytes, BytesMut};
1313
use http::HeaderMap;
1414
use http::HeaderValue;
15+
use http_body_util::BodyExt;
1516
use http_body_util::Full;
16-
use http_body_util::{BodyExt};
1717
use hyper::Version;
1818
use hyper_tls::HttpsConnector;
1919
use hyper_util::client::legacy::{connect::HttpConnector, Client};
@@ -65,7 +65,7 @@ impl HTTPSubgraphExecutor {
6565
);
6666
header_map.insert(
6767
http::header::ACCEPT_ENCODING,
68-
HeaderValue::from_static("gzip, deflate, br, zstd"),
68+
HeaderValue::from_static(CompressionType::accept_encoding()),
6969
);
7070

7171
Self {

lib/executor/src/executors/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub mod common;
2+
pub mod compression;
23
pub mod dedupe;
34
pub mod error;
45
pub mod http;
56
pub mod map;
6-
pub mod compression;

0 commit comments

Comments
 (0)