Skip to content

Commit

Permalink
Remove no-transform cache control header
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDaub committed Oct 14, 2024
1 parent 544312d commit 0f77292
Showing 1 changed file with 28 additions and 43 deletions.
71 changes: 28 additions & 43 deletions src/http.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export async function launch(trie, libp2p) {
app.get("/friends", async (request, reply) => {
reply.header(
"Cache-Control",
"public, max-age=3600, no-transform, stale-while-revalidate=86400",
"public, max-age=3600, stale-while-revalidate=86400",
);
return reply
.status(200)
Expand All @@ -209,7 +209,7 @@ export async function launch(trie, libp2p) {
app.get("/kiwipass-mint", async (request, reply) => {
reply.header(
"Cache-Control",
"public, max-age=3600, no-transform, stale-while-revalidate=86400",
"public, max-age=3600, stale-while-revalidate=86400",
);
return reply
.status(200)
Expand Down Expand Up @@ -321,21 +321,15 @@ export async function launch(trie, libp2p) {
const httpMessage = "Bad Request";
const details =
"Please only submit subscription along with a valid Ethereum addresses.";
reply.header(
"Cache-Control",
"public, max-age=0, no-transform, must-revalidate",
);
reply.header("Cache-Control", "public, max-age=0, must-revalidate");
return sendError(reply, code, httpMessage, details);
}

if (!isValidWebPushSubscription(request.body)) {
const code = 400;
const httpMessage = "Bad Request";
const details = "Error storing subscription";
reply.header(
"Cache-Control",
"public, max-age=0, no-transform, must-revalidate",
);
reply.header("Cache-Control", "public, max-age=0, must-revalidate");
return sendError(reply, code, httpMessage, details);
}

Expand All @@ -345,10 +339,7 @@ export async function launch(trie, libp2p) {
const code = 500;
const httpMessage = "Internal Server Error";
const details = "Error storing subscription";
reply.header(
"Cache-Control",
"public, max-age=0, no-transform, must-revalidate",
);
reply.header("Cache-Control", "public, max-age=0, must-revalidate");
return sendError(reply, code, httpMessage, details);
}

Expand Down Expand Up @@ -397,7 +388,7 @@ export async function launch(trie, libp2p) {
const details = `Get Leaderboard`;
reply.header(
"Cache-Control",
"public, max-age=300, no-transform, must-revalidate, stale-while-revalidate=3600",
"public, max-age=300, must-revalidate, stale-while-revalidate=3600",
);
return sendStatus(reply, code, httpMessage, details, { leaders });
});
Expand All @@ -409,10 +400,7 @@ export async function launch(trie, libp2p) {
const code = 400;
const httpMessage = "Bad Request";
const details = "Please only submit valid Ethereum addresses.";
reply.header(
"Cache-Control",
"public, max-age=0, no-transform, must-revalidate",
);
reply.header("Cache-Control", "public, max-age=0, must-revalidate");
return sendError(reply, code, httpMessage, details);
}

Expand All @@ -422,7 +410,7 @@ export async function launch(trie, libp2p) {
const details = `Karma`;
reply.header(
"Cache-Control",
"public, max-age=300, no-transform, stale-while-revalidate=300",
"public, max-age=300, stale-while-revalidate=300",
);
return sendStatus(reply, code, httpMessage, details, {
address,
Expand All @@ -439,7 +427,7 @@ export async function launch(trie, libp2p) {
const results = await index(trie, page);
reply.header(
"Cache-Control",
"public, max-age=300, no-transform, must-revalidate, stale-while-revalidate=30",
"public, max-age=300, must-revalidate, stale-while-revalidate=30",
);
stories = results.stories;
} else if (request.params.name === "new") {
Expand All @@ -451,7 +439,7 @@ export async function launch(trie, libp2p) {
} else if (request.params.name === "best") {
reply.header(
"Cache-Control",
"public, max-age=3600, no-transform, must-revalidate, stale-while-revalidate=86400",
"public, max-age=3600, must-revalidate, stale-while-revalidate=86400",
);

let page = parseInt(request.query.page);
Expand All @@ -476,10 +464,7 @@ export async function launch(trie, libp2p) {
const httpMessage = "Not Implemented";
const details =
"We currently don't implement any other endpoint but 'hot' and 'new'";
reply.header(
"Cache-Control",
"public, max-age=0, no-transform, must-revalidate",
);
reply.header("Cache-Control", "public, max-age=0, must-revalidate");
return sendError(reply, code, httpMessage, details);
}

Expand Down Expand Up @@ -512,7 +497,7 @@ export async function launch(trie, libp2p) {

reply.header(
"Cache-Control",
"public, max-age=10, no-transform, stale-while-revalidate=31536000",
"public, max-age=10, stale-while-revalidate=31536000",
);
const code = 200;
const httpMessage = "OK";
Expand All @@ -533,7 +518,7 @@ export async function launch(trie, libp2p) {

reply.header(
"Cache-Control",
"public, max-age=60, no-transform, stale-while-revalidate=3600",
"public, max-age=60, stale-while-revalidate=3600",
);
return reply
.status(200)
Expand Down Expand Up @@ -561,15 +546,15 @@ export async function launch(trie, libp2p) {
}
reply.header(
"Cache-Control",
"public, max-age=5, no-transform, stale-while-revalidate=3600",
"public, max-age=5, stale-while-revalidate=3600",
);
return reply.status(200).type("text/html").send(content);
});
app.get("/stories/:slug?", async (request, reply) => {
if (request.params.slug) {
reply.header(
"Cache-Control",
"public, max-age=10, no-transform, stale-while-revalidate=31536000",
"public, max-age=10, stale-while-revalidate=31536000",
);
const queryParams = new URLSearchParams(request.query).toString();
return reply.redirect(`/stories?${queryParams}`);
Expand Down Expand Up @@ -597,7 +582,7 @@ export async function launch(trie, libp2p) {
);
reply.header(
"Cache-Control",
"public, max-age=10, no-transform, stale-while-revalidate=31536000",
"public, max-age=10, stale-while-revalidate=31536000",
);
return reply.status(200).type("text/html").send(content);
});
Expand All @@ -623,7 +608,7 @@ export async function launch(trie, libp2p) {
if (request.query.cached) {
reply.header(
"Cache-Control",
"public, max-age=1, no-transform, must-revalidate, stale-while-revalidate=5",
"public, max-age=1, stale-while-revalidate=5",
);
} else {
reply.header("Cache-Control", "no-cache");
Expand Down Expand Up @@ -662,7 +647,7 @@ export async function launch(trie, libp2p) {

reply.header(
"Cache-Control",
"public, max-age=3600, no-transform, stale-while-revalidate=2592000",
"public, max-age=3600, stale-while-revalidate=2592000",
);
return reply.status(200).type("text/html").send(content);
});
Expand Down Expand Up @@ -875,7 +860,7 @@ export async function launch(trie, libp2p) {
app.get("/onboarding", async (request, reply) => {
reply.header(
"Cache-Control",
"public, max-age=3600, no-transform, stale-while-revalidate=86400",
"public, max-age=3600, stale-while-revalidate=86400",
);
return reply
.status(200)
Expand All @@ -890,7 +875,7 @@ export async function launch(trie, libp2p) {
app.get("/whattosubmit", async (request, reply) => {
reply.header(
"Cache-Control",
"public, max-age=3600, no-transform, stale-while-revalidate=86400",
"public, max-age=3600, stale-while-revalidate=86400",
);
return reply
.status(200)
Expand All @@ -900,7 +885,7 @@ export async function launch(trie, libp2p) {
app.get("/referral", async (request, reply) => {
reply.header(
"Cache-Control",
"public, max-age=3600, no-transform, stale-while-revalidate=86400",
"public, max-age=3600, stale-while-revalidate=86400",
);
return reply
.status(200)
Expand All @@ -910,7 +895,7 @@ export async function launch(trie, libp2p) {
app.get("/onboarding-reader", async (request, reply) => {
reply.header(
"Cache-Control",
"public, max-age=3600, no-transform, stale-while-revalidate=86400",
"public, max-age=3600, stale-while-revalidate=86400",
);
return reply
.status(200)
Expand All @@ -925,7 +910,7 @@ export async function launch(trie, libp2p) {
app.get("/onboarding-curator", async (request, reply) => {
reply.header(
"Cache-Control",
"public, max-age=3600, no-transform, stale-while-revalidate=86400",
"public, max-age=3600, stale-while-revalidate=86400",
);
return reply
.status(200)
Expand All @@ -940,7 +925,7 @@ export async function launch(trie, libp2p) {
app.get("/onboarding-submitter", async (request, reply) => {
reply.header(
"Cache-Control",
"public, max-age=3600, no-transform, stale-while-revalidate=86400",
"public, max-age=3600, stale-while-revalidate=86400",
);
return reply
.status(200)
Expand Down Expand Up @@ -1034,17 +1019,17 @@ export async function launch(trie, libp2p) {
if (request.query.mode === "new") {
reply.header(
"Cache-Control",
"public, max-age=86400, no-transform, stale-while-revalidate=600000",
"public, max-age=86400, stale-while-revalidate=600000",
);
} else if (!request.query.mode || request.query.mode == "top") {
reply.header(
"Cache-Control",
"public, max-age=86400, no-transform, stale-while-revalidate=86400",
"public, max-age=86400, stale-while-revalidate=86400",
);
} else {
reply.header(
"Cache-Control",
"public, max-age=3600, no-transform, stale-while-revalidate=60",
"public, max-age=3600, stale-while-revalidate=60",
);
}

Expand Down Expand Up @@ -1100,7 +1085,7 @@ export async function launch(trie, libp2p) {

reply.header(
"Cache-Control",
"public, max-age=86400, no-transform, stale-while-revalidate=600000",
"public, max-age=86400, stale-while-revalidate=600000",
);
return reply.status(200).type("text/html").send(content);
});
Expand Down

0 comments on commit 0f77292

Please sign in to comment.