Skip to content

Commit

Permalink
fix: specify content type in header
Browse files Browse the repository at this point in the history
  • Loading branch information
caipira113 committed Jul 18, 2023
1 parent 06c622a commit 46503e8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ serde = { version = "1.0.171", features = ["derive"] }
anyhow = "1.0.71"
aws-config = "0.55.3"
aws-sdk-s3 = "0.28.0"
bytes = "1.4.0"
futures-util = "0.3.28"
env_logger = "0.10.0"
log = "0.4.19"
13 changes: 8 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use actix_web::http::StatusCode;
use actix_web::web::Data;
use aws_config::meta::region::RegionProviderChain;
use aws_sdk_s3::Client;
use aws_sdk_s3::operation::get_object::GetObjectOutput;
use env_logger::Env;
use futures_util::{Stream, TryStreamExt};
use serde::{Deserialize, Serialize};

#[derive(Debug)]
Expand Down Expand Up @@ -37,15 +37,15 @@ fn get_bind_address() -> IpAddr {
.unwrap_or_else(|_| IpAddr::from_str("127.0.0.1").unwrap())
}

async fn get_object(client: &Client, opt: Opt) -> Result<impl Stream<Item=Result<bytes::Bytes, anyhow::Error>>, anyhow::Error> {
async fn get_object(client: &Client, opt: Opt) -> Result<GetObjectOutput, anyhow::Error> {
let object = client
.get_object()
.bucket(opt.bucket)
.key(opt.object)
.send()
.await?;

Ok(object.body.map_err(Into::into))
Ok(object)
}

#[get("/{tail:.*}")]
Expand All @@ -63,8 +63,11 @@ async fn serve(key: web::Path<String>, client: Data<Client>) -> impl Responder {
response.insert_header(("Cache-Control", "public, max-age=31536000"));
}
}
response.streaming(stream)
},
if let Some(content_type) = stream.content_type() {
response.insert_header(("Content-Type", content_type));
}
response.streaming(stream.body)
}
Err(err) => {
let root_cause = err.root_cause();
log::error!("Error retrieving object: {}", root_cause);
Expand Down

0 comments on commit 46503e8

Please sign in to comment.