superagent: cookie related headers has special types

This commit is contained in:
freewind 2018-12-30 21:32:52 +08:00
parent efb66b22be
commit fb0afa719b
2 changed files with 14 additions and 0 deletions

View File

@ -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;

View File

@ -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')