Skip to content

Commit

Permalink
Plugin API: Add getHeaders method to context.response (#3289)
Browse files Browse the repository at this point in the history
Co-authored-by: Opender Singh <opender.singh@konghq.com>
  • Loading branch information
monrax and develohpanda committed Apr 20, 2021
1 parent c4d72a2 commit 7e745c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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

0 comments on commit 7e745c6

Please sign in to comment.