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

Plugin API: Add getHeaders method to context.response #3289

Merged
merged 5 commits into from Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -15,6 +15,7 @@ describe('init()', () => {
'getBodyStream',
'getBytesRead',
'getHeader',
'getHeaders',
'getRequestId',
'getStatusCode',
'getStatusMessage',
Expand Down Expand Up @@ -70,6 +71,11 @@ describe('response.*', () => {
],
};
const result = plugin.init(response);
expect(result.response.getHeaders()).toEqual([
{ name: 'content-type', value: 'application/json' },
{ name: 'set-cookie', value: 'foo=bar' },
{ name: 'set-cookie', value: 'baz=qux' },
]);
expect(result.response.getHeader('Does-Not-Exist')).toBeNull();
expect(result.response.getHeader('CONTENT-TYPE')).toBe('application/json');
expect(result.response.getHeader('set-cookie')).toEqual(['foo=bar', 'baz=qux']);
Expand Down
6 changes: 6 additions & 0 deletions packages/insomnia-app/app/plugins/context/response.js
Expand Up @@ -68,6 +68,12 @@ export function init(response: MaybeResponse): { response: Object } {
return null;
}
},
getHeaders(): Array<{ name: string, value: string }> {
return response.headers.map(h => ({
name: h.name,
value: h.value,
}));
},
hasHeader(name: string): boolean {
return this.getHeader(name) !== null;
},
Expand Down