diff --git a/types/superagent/index.d.ts b/types/superagent/index.d.ts index 7c1898cdc2..7915277b37 100644 --- a/types/superagent/index.d.ts +++ b/types/superagent/index.d.ts @@ -100,6 +100,7 @@ declare namespace request { files: any; forbidden: boolean; get(header: string): string; + get(header: 'Set-Cookie'): string[]; header: any; info: boolean; links: object; @@ -148,6 +149,7 @@ declare namespace request { serialize(serializer: Serializer): this; set(field: object): this; set(field: string, val: string): this; + set(field: 'Cookie', val: string[]): this; timeout(ms: number | { deadline?: number, response?: number }): this; type(val: string): this; unset(field: string): this; diff --git a/types/superagent/superagent-tests.ts b/types/superagent/superagent-tests.ts index 44ef7cf773..b261a551d7 100644 --- a/types/superagent/superagent-tests.ts +++ b/types/superagent/superagent-tests.ts @@ -83,6 +83,12 @@ request .set({ 'API-Key': 'foobar', Accept: 'application/json' }) .end(callback); +// Setting cookie header +request + .get('/search') + .set('Cookie', ['name1=value1; Domain=.test.com; Path=/', 'name2=value2; Domain=.test.com; Path=/']) + .end(callback); + // GET requests request .get('/search') @@ -198,6 +204,12 @@ request('/search') const charset: string = res.charset; }); +// Getting response 'Set-Cookie' +request('/search') + .end((res: request.Response) => { + const setCookie: string[] = res.get('Set-Cookie'); + }); + // Custom parsers request .post('/search')