Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow custom cache control settings for requests #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

NeilHanlon
Copy link
Contributor

Currently, the publisher server only allows for three options when setting cache-control settings: extended (one year), never (no-store), and null, which skips setting the cache-control header.

At the same time, the implementation for serving local content prevents mutation of the backend response after receiving it (e.g., to add a custom cache-control header based on a path), as the act of catching the response to modify it strips the original Response headers. This is contrary to the documentation[1] which indicates the headers can be mutated in this fashion. (i.e., by passing beresp.body through pipeThrough) with a transform stream. From my testing, it's not possible to mutate the headers along with (or without) the content.

This change modifies the serveRequest method to add an optional cache parameter which allows the user to set a custom cache-control string. Although there are other ways to solve this (such as allowing serveRequest to accept arbitrary headers which will be appended/merged, or figuring out if the broken example is the result of a bug or old documentation), this method solves my current needs.

[1] https://www.fastly.com/documentation/guides/compute/javascript/#parsing-and-transforming-responses

Currently, the publisher server only allows for three options when
setting cache-control settings: extended (one year), never (no-store),
and null, which skips setting the cache-control header.

At the same time, the implementation for serving local content prevents
mutation of the backend response after receiving it (e.g., to add a
custom cache-control header based on a path), as the act of catching the
response to modify it strips the original Response headers. This is
contrary to the documentation[1] which indicates the headers can be
mutated in this fashion. (i.e., by passing beresp.body through
`pipeThrough`) with a transform stream. From my testing, it's not
possible to mutate the headers along with (or without) the content.

This change modifies the serveRequest method to add an optional cache
parameter which allows the user to set a custom cache-control string.
Although there are other ways to solve this (such as allowing
serveRequest to accept arbitrary headers which will be appended/merged,
or figuring out if the broken example is the result of a bug or old
documentation), this method solves my current needs.

[1] https://www.fastly.com/documentation/guides/compute/javascript/#parsing-and-transforming-responses

Signed-off-by: Neil Hanlon <[email protected]>
@NeilHanlon
Copy link
Contributor Author

looking at this again, I think the 'right' thing to do is accept a CacheOveride like the js-runtime does. will look at that in the morning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant