mirror of
https://github.com/tenrok/axios.git
synced 2026-05-15 11:59:42 +03:00
feat(AxiosHeaders): add getSetCookie method to retrieve set-cookie headers values (#5707)
* feat(AxiosHeaders): add getSetCookie method to retrieve set-cookie header values * refactor(AxiosHeaders.js): use logical OR instead of nullish coalescing operator in getSetCookie method --------- Co-authored-by: Willian Agostini <willian.agostini@gmail.com.br> Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Vendored
+2
@@ -74,6 +74,8 @@ export class AxiosHeaders {
|
||||
getAuthorization(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
||||
hasAuthorization(matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
getSetCookie(): string[];
|
||||
|
||||
[Symbol.iterator](): IterableIterator<[string, AxiosHeaderValue]>;
|
||||
}
|
||||
|
||||
|
||||
@@ -245,6 +245,10 @@ class AxiosHeaders {
|
||||
return Object.entries(this.toJSON()).map(([header, value]) => header + ': ' + value).join('\n');
|
||||
}
|
||||
|
||||
getSetCookie() {
|
||||
return this["set-cookie"] || [];
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
return 'AxiosHeaders';
|
||||
}
|
||||
|
||||
@@ -423,4 +423,19 @@ describe('AxiosHeaders', function () {
|
||||
assert.deepStrictEqual(new AxiosHeaders({x:1, y:2}).toString(), 'x: 1\ny: 2');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSetCookie', function () {
|
||||
it('should return set-cookie', function () {
|
||||
const headers = new AxiosHeaders(
|
||||
'Set-Cookie: key=val;\n' +
|
||||
'Set-Cookie: key2=val2;\n'
|
||||
);
|
||||
|
||||
assert.deepStrictEqual(headers.getSetCookie(), ['key=val;', 'key2=val2;']);
|
||||
});
|
||||
|
||||
it('should return empty set-cookie', function () {
|
||||
assert.deepStrictEqual(new AxiosHeaders().getSetCookie(), []);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user