Skip to content

Commit

Permalink
per spec content disposition & cache-control
Browse files Browse the repository at this point in the history
  • Loading branch information
Arqu committed Oct 11, 2022
1 parent a3ab39b commit 931bece
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
1 change: 0 additions & 1 deletion iroh-gateway/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ fn default_headers() -> HeaderMap {
.collect::<AccessControlAllowHeaders>(),
);
// todo(arqu): remove these once propperly implmented
headers.insert(CACHE_CONTROL, VALUE_NO_CACHE_NO_TRANSFORM.clone());
headers.insert(ACCEPT_RANGES, VALUE_NONE.clone());
headers
}
Expand Down
2 changes: 0 additions & 2 deletions iroh-gateway/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ pub static HEADER_CACHE_CONTROL: HeaderName = HeaderName::from_static("cache-con
// Common Header Values
pub static VALUE_XCTO_NOSNIFF: HeaderValue = HeaderValue::from_static("nosniff");
pub static VALUE_NONE: HeaderValue = HeaderValue::from_static("none");
pub static VALUE_NO_CACHE_NO_TRANSFORM: HeaderValue =
HeaderValue::from_static("no-cache, no-transform");
pub static VAL_IMMUTABLE_MAX_AGE: HeaderValue =
HeaderValue::from_static("public, max-age=31536000, immutable");

Expand Down
42 changes: 23 additions & 19 deletions iroh-gateway/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,12 @@ async fn serve_raw<T: ContentLoader + std::marker::Unpin>(

match body {
FileResult::File(body) => {
set_content_disposition_headers(
&mut headers,
format!("{}.bin", req.cid).as_str(),
DISPOSITION_ATTACHMENT,
);
let file_name = match req.query_file_name.is_empty() {
true => format!("{}.bin", req.cid),
false => req.query_file_name.clone(),
};

set_content_disposition_headers(&mut headers, &file_name, DISPOSITION_ATTACHMENT);
set_etag_headers(&mut headers, get_etag(&req.cid, Some(req.format.clone())));
add_cache_control_headers(&mut headers, metadata.clone());
add_ipfs_roots_headers(&mut headers, metadata);
Expand Down Expand Up @@ -428,16 +429,17 @@ async fn serve_car<T: ContentLoader + std::marker::Unpin>(

match body {
FileResult::File(body) => {
set_content_disposition_headers(
&mut headers,
format!("{}.car", req.cid).as_str(),
DISPOSITION_ATTACHMENT,
);
let file_name = match req.query_file_name.is_empty() {
true => format!("{}.car", req.cid),
false => req.query_file_name.clone(),
};

// todo(arqu): this should be root cid
set_content_disposition_headers(&mut headers, &file_name, DISPOSITION_ATTACHMENT);

add_cache_control_headers(&mut headers, metadata.clone());
let etag = format!("W/{}", get_etag(&req.cid, Some(req.format.clone())));
set_etag_headers(&mut headers, etag);
// todo(arqu): check if etag matches for root cid
// todo(arqu): handle if none match
add_ipfs_roots_headers(&mut headers, metadata);
response(StatusCode::OK, body, headers)
}
Expand All @@ -463,16 +465,18 @@ async fn serve_car_recursive<T: ContentLoader + std::marker::Unpin>(
.await
.map_err(|e| error(StatusCode::INTERNAL_SERVER_ERROR, &e, &state))?;

set_content_disposition_headers(
&mut headers,
format!("{}.car", req.cid).as_str(),
DISPOSITION_ATTACHMENT,
);
let file_name = match req.query_file_name.is_empty() {
true => format!("{}.car", req.cid),
false => req.query_file_name.clone(),
};

// todo(arqu): this should be root cid
set_content_disposition_headers(&mut headers, &file_name, DISPOSITION_ATTACHMENT);

// add_cache_control_headers(&mut headers, metadata.clone());
let etag = format!("W/{}", get_etag(&req.cid, Some(req.format.clone())));
set_etag_headers(&mut headers, etag);
// todo(arqu): check if etag matches for root cid

// todo(arqu): handle if none match
// add_ipfs_roots_headers(&mut headers, metadata);
response(StatusCode::OK, body, headers)
}
Expand Down
1 change: 0 additions & 1 deletion iroh-gateway/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ impl ResponseFormat {
headers.insert(CONTENT_TYPE, CONTENT_TYPE_IPLD_CAR.clone());
headers.insert(&HEADER_X_CONTENT_TYPE_OPTIONS, VALUE_XCTO_NOSNIFF.clone());
headers.insert(ACCEPT_RANGES, VALUE_NONE.clone());
headers.insert(CACHE_CONTROL, VALUE_NO_CACHE_NO_TRANSFORM.clone());
}
ResponseFormat::Fs(_) => {
// Don't send application/octet-stream in that case, let the
Expand Down

0 comments on commit 931bece

Please sign in to comment.