Skip to content

Commit 936c83d

Browse files
authored
Merge pull request #14 from aws-samples/dev
add support for HTTP compression
2 parents d30e2f7 + a9ca357 commit 936c83d

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "aws-lambda-adapter"
3-
version = "0.1.0"
3+
version = "0.1.2"
44
authors = ["Harold Sun <[email protected]>"]
55
edition = "2018"
66

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ $ cd aws-lambda-adapter
3232

3333
### Compiling with Docker
3434
On x86_64 Windows, Linux and macOS, you can run one command to compile Lambda Adapter with docker.
35-
The Dockerfile is [here](Dockerfile.x86). [AWS CLI v2](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) should have been installed and configured.
35+
The Dockerfile is [here](Dockerfile). [AWS CLI v2](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) should have been installed and configured.
3636

3737
```shell
3838
$ make build

examples/nginx/app/config/nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ http {
3030

3131
keepalive_timeout 65;
3232

33-
#gzip on;
33+
gzip on;
3434

3535
include /etc/nginx/conf.d/*.conf;
3636
}

src/main.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ async fn http_proxy_handler(event: Request, _: Context) -> Result<impl IntoRespo
163163
serializer.finish();
164164
}
165165
debug!("app_url is {:#?}", app_url);
166+
debug!("request headers are {:#?}", parts.headers);
166167

167168
let app_response = HTTP_CLIENT
168169
.get()
@@ -186,18 +187,30 @@ async fn http_proxy_handler(event: Request, _: Context) -> Result<impl IntoRespo
186187

187188
async fn convert_body(app_response: reqwest::Response) -> Result<Body, Error> {
188189
let content_type;
190+
debug!("app response headers are {:#?}", app_response.headers());
191+
192+
if app_response
193+
.headers()
194+
.get(http::header::CONTENT_ENCODING)
195+
.is_some()
196+
{
197+
debug!("body is binary");
198+
let content = app_response.bytes().await?;
199+
return Ok(Body::Binary(content.to_vec()));
200+
}
201+
189202
if let Some(value) = app_response.headers().get(http::header::CONTENT_TYPE) {
190203
content_type = value.to_str().unwrap_or_default();
191204
} else {
192-
// default to "application/json" if content-type header is not available in the response
193-
content_type = "application/json";
205+
// default to "application/octet-stream" if content-type header is not available in the response
206+
content_type = "application/octet-stream";
194207
}
208+
debug!("content_type is {:?}", content_type);
195209

196210
if content_type.starts_with("text")
197-
|| content_type.eq("application/json")
198-
|| content_type.eq("application/javascript")
199-
|| content_type.eq("application/xml")
200-
|| content_type.eq("image/svg+xml")
211+
|| content_type.starts_with("application/json")
212+
|| content_type.starts_with("application/javascript")
213+
|| content_type.starts_with("application/xml")
201214
{
202215
debug!("body is text");
203216
let body_text = app_response.text().await?;

0 commit comments

Comments
 (0)