Skip to content

Commit faf1ff7

Browse files
committed
Upload all content to s3 as public and immutable
1 parent af26bb3 commit faf1ff7

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/s3/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl Bucket {
4545
content: R,
4646
content_length: u64,
4747
content_type: &str,
48+
cache_control: &str,
4849
) -> reqwest::Result<reqwest::Response> {
4950
let path = if path.starts_with('/') {
5051
&path[1..]
@@ -59,6 +60,7 @@ impl Bucket {
5960
.put(&url)
6061
.header(header::AUTHORIZATION, auth)
6162
.header(header::CONTENT_TYPE, content_type)
63+
.header(header::CACHE_CONTROL, cache_control)
6264
.header(header::DATE, date)
6365
.body(reqwest::Body::sized(content, content_length))
6466
.send()?

src/tests/record.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ fn replay_http(
272272
mut exchange: Exchange,
273273
stdout: &mut dyn Write,
274274
) -> Box<dyn Future<Item = hyper::Response<hyper::Body>, Error = hyper::Error> + Send> {
275-
static IGNORED_HEADERS: &[&str] = &["authorization", "date", "user-agent"];
275+
static IGNORED_HEADERS: &[&str] = &["authorization", "date", "user-agent", "cache-control"];
276276

277277
assert_eq!(req.uri().to_string(), exchange.request.uri);
278278
assert_eq!(req.method().to_string(), exchange.request.method);

src/uploaders.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use std::sync::Arc;
1313
use crate::middleware::app::RequestApp;
1414
use crate::models::Crate;
1515

16+
const CACHE_CONTROL_PUBLIC_IMMUTABLE: &str = "public,max-age=31536000,immutable";
17+
1618
#[derive(Clone, Debug)]
1719
pub enum Uploader {
1820
/// For production usage, uploads and redirects to s3.
@@ -95,7 +97,14 @@ impl Uploader {
9597
match *self {
9698
Uploader::S3 { ref bucket, .. } => {
9799
bucket
98-
.put(client, path, content, content_length, content_type)
100+
.put(
101+
client,
102+
path,
103+
content,
104+
content_length,
105+
content_type,
106+
CACHE_CONTROL_PUBLIC_IMMUTABLE,
107+
)
99108
.map_err(|e| internal(&format_args!("failed to upload to S3: {}", e)))?;
100109
Ok(Some(String::from(path)))
101110
}

0 commit comments

Comments
 (0)