Skip to content

Commit

Permalink
Cache content responses (#1318)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Jan 24, 2023
1 parent 5751a22 commit ef12d44
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,10 @@ impl Server {
header::CONTENT_SECURITY_POLICY,
HeaderValue::from_static("default-src 'unsafe-eval' 'unsafe-inline'"),
);
headers.insert(
header::CACHE_CONTROL,
HeaderValue::from_static("max-age=31536000, immutable"),
);

Some((headers, inscription.into_body()?))
}
Expand Down Expand Up @@ -2254,4 +2258,26 @@ mod tests {
&fs::read_to_string("templates/preview-unknown.html").unwrap(),
);
}

#[test]
fn content_responses_have_cache_control_headers() {
let server = TestServer::new();
server.mine_blocks(1);

let txid = server.bitcoin_rpc_server.broadcast_tx(TransactionTemplate {
inputs: &[(1, 0, 0)],
witness: inscription("text/foo", "hello").to_witness(),
..Default::default()
});

server.mine_blocks(1);

let response = server.get(format!("/content/{}", InscriptionId::from(txid)));

assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.headers().get(header::CACHE_CONTROL).unwrap(),
"max-age=31536000, immutable"
);
}
}

0 comments on commit ef12d44

Please sign in to comment.