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

What is the benefit of using ctx.meta.$location & ctx.meta.$responseType vs just setting via ctx.meta.$responseHeaders? #350

Open
valeeum opened this issue Apr 10, 2024 · 4 comments

Comments

@valeeum
Copy link

valeeum commented Apr 10, 2024

I'm just curious why ctx.meta.$location & ctx.meta.$responseType options are offered as opposed to setting "Location" and "Content-Type" header via ctx.meta.$responseHeaders?

@icebob
Copy link
Member

icebob commented Apr 21, 2024

Nothing special just you can write the same shortly.

@icebob icebob closed this as completed Apr 21, 2024
@valeeum
Copy link
Author

valeeum commented Apr 21, 2024

But it's not just there for convenience since it can cause error if not set:

// Redirect
			if (res.statusCode==201 || (res.statusCode >= 300 && res.statusCode < 400 && res.statusCode !== 304)) {
				const location = ctx.meta.$location;
				/* istanbul ignore next */
				if (!location) {
					this.logger.warn(`The 'ctx.meta.$location' is missing for status code '${res.statusCode}'!`);
				} else {
					res.setHeader("Location", location);
				}
			}

@valeeum
Copy link
Author

valeeum commented Apr 21, 2024

I suggest we use the following code:

const location = ctx.meta.$location ?? ctx.meta.$responseHeaders?.['Location'];

@icebob
Copy link
Member

icebob commented Apr 21, 2024

Good catch

@icebob icebob reopened this Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants