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

Add getHeaders to context.response on the Plugin API #3282

Closed
monrax opened this issue Apr 14, 2021 · 1 comment · Fixed by #3289
Closed

Add getHeaders to context.response on the Plugin API #3282

monrax opened this issue Apr 14, 2021 · 1 comment · Fixed by #3289
Labels
A-plugin-api Area: Plugin API / System E-good-first-issue Experience required: Beginner / New

Comments

@monrax
Copy link
Contributor

monrax commented Apr 14, 2021

Is your feature request related to a problem? Please describe.
There is no way to get all response header keys

Describe the solution you'd like
Create a getHeaders method for context.response similar to the context.request one

Describe alternatives you've considered
None

Additional context
None

@develohpanda develohpanda added A-plugin-api Area: Plugin API / System C-feature-accepted E-good-first-issue Experience required: Beginner / New labels Apr 14, 2021
@develohpanda
Copy link
Contributor

develohpanda commented Apr 14, 2021

Thanks! Just adding notes for anybody looking to pick this up. 🙌🏽

Looks like context.request has a getHeaders method:

getHeaders(): Array<{ name: string, value: string }> {
return renderedRequest.headers.map(h => ({
name: h.name,
value: h.value,
}));
},

But context.response is missing it:

getHeader(name: string): string | Array<string> | null {
const headers = response.headers || [];
const matchedHeaders = headers.filter(h => h.name.toLowerCase() === name.toLowerCase());
if (matchedHeaders.length > 1) {
return matchedHeaders.map(h => h.value);
} else if (matchedHeaders.length === 1) {
return matchedHeaders[0].value;
} else {
return null;
}
},
hasHeader(name: string): boolean {
return this.getHeader(name) !== null;
},

Should be a fairly straightforward fix! I believe this is just an oversight. 🤗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-plugin-api Area: Plugin API / System E-good-first-issue Experience required: Beginner / New
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants