Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jsimck committed Oct 23, 2024
1 parent b82b8b5 commit 2f30ad3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/http/HttpAgentImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,9 @@ export class HttpAgentImpl extends HttpAgent {
*/
_setCookiesFromResponse<B>(agentResponse: HttpAgentResponse<B>): void {
if (agentResponse.headersRaw) {
const receivedCookies = agentResponse.headersRaw.get('set-cookie');
const receivedCookies = agentResponse.headersRaw.getSetCookie();

if (receivedCookies) {
if (receivedCookies.length > 0) {
this._cookie.parseFromSetCookieHeader(
receivedCookies,
agentResponse.params.url
Expand Down
8 changes: 3 additions & 5 deletions packages/core/src/http/__tests__/HttpAgentImplSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,9 @@ describe('ima.core.http.HttpAgentImpl', () => {
'set-cookie': ['cookie1=cookie1', 'cookie2=cookie2'],
},
// @ts-ignore
headersRaw: new Map(
Object.entries({
'set-cookie': ['cookie1=cookie1', 'cookie2=cookie2'],
})
),
headersRaw: new Headers({
'set-cookie': ['cookie1=cookie1', 'cookie2=cookie2'],
}),
};
});

Expand Down
22 changes: 10 additions & 12 deletions packages/core/src/storage/CookieStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ const MAX_EXPIRE_DATE = new Date('Fri, 31 Dec 9999 23:59:59 UTC');
*/
const COOKIE_SEPARATOR = '; ';

/**
* Separator used to separate cookie declarations in the `Set-Cookie` HTTP
* header.
*/
const SERVER_COOKIE_SEPARATOR = ', ';

export type CookieOptions = {
domain?: string;
expires?: Date;
Expand Down Expand Up @@ -356,13 +350,17 @@ export class CookieStorage extends Storage<Cookie['value']> {
* HTTP response (via the `Set-Cookie` HTTP header) if at the server
* side, or the browser (via the `document.cookie` property).
*
* @param setCookieHeader The value of the `Set-Cookie` HTTP
* header.
* @param cookiesString The value of the `Set-Cookie` HTTP
* header. When there are multiple cookies, the value can be
* provided as an array of strings.
*/
parseFromSetCookieHeader(setCookieHeader: string, url?: string): void {
const cookiesArray = setCookieHeader
? setCookieHeader.split(SERVER_COOKIE_SEPARATOR)
: [];
parseFromSetCookieHeader(
cookiesString: string | string[],
url?: string
): void {
const cookiesArray = Array.isArray(cookiesString)
? cookiesString
: [cookiesString];

for (const cookie of cookiesArray) {
const cookieItem = this.#extractCookie(cookie);
Expand Down

0 comments on commit 2f30ad3

Please sign in to comment.