Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Add ability to set response attributes on a per-route basis #1354

Open
benmccann opened this issue Aug 2, 2020 · 4 comments
Open

Add ability to set response attributes on a per-route basis #1354

benmccann opened this issue Aug 2, 2020 · 4 comments
Labels

Comments

@benmccann
Copy link
Member

benmccann commented Aug 2, 2020

There's a desire to set certain response attributes on a per-route basis. E.g. the Cache-Control header, other headers, response type, etc.

A few ideas:

@Conduitry
Copy link
Member

My knee-jerk reaction here would be something along the lines of the second option above, where we have a new module-level export in the component, which is passed the req/res objects when doing a server rendering of that route.

@ajbouh
Copy link

ajbouh commented Aug 17, 2020

Being able to affect the request and response before/after render would be a powerful tool.

Might be good to provide a single "around" hook to this effect, or maybe just two different hooks: "before" and "after". Though I think "around" would be better.

@ehrencrona
Copy link
Contributor

ehrencrona commented Sep 15, 2020

How about allowing this in preload? So either exposing a this.setHeader, as in

	export function preload(page, session) {
		this.setHeader('Cache-Control', 'max-age=3600');
	}

or potentially just exposing the entire response, though I think that might be exposing a bit much.

What is the use case for doing something to request/response after the request?

@benmccann
Copy link
Member Author

preload might not be the right place to do it because it runs on the server and client

One example @ajbouh gave elsewhere was timing how long preload took. He wanted to instrument that call and so having a before/after hook would be useful for that. I imagine he might be wanting to do the same thing here of instrumenting how long it takes the entire request to be handled

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

Successfully merging a pull request may close this issue.

4 participants