@@ -13,7 +13,7 @@ import type { CookieStore } from "./types";
13
13
export function cookies ( ) : CookieStore {
14
14
const headersList = headers ( ) ;
15
15
const cookieHeader = headersList . get ( "Cookie" ) ?? "" ;
16
- const cookieValuesByName = readCookieHeader ( cookieHeader . replace ( / ; $ / , "" ) ) ;
16
+ const cookieValuesByName = parseCookieHeader ( cookieHeader . replace ( / ; $ / , "" ) ) ;
17
17
18
18
const cookieMap = new Map < string , Cookie > ( ) ;
19
19
const responseHeaders = response ( ) . headers ;
@@ -26,7 +26,7 @@ export function cookies(): CookieStore {
26
26
27
27
function updateResponseCookiesFromMap ( ) {
28
28
const cookieHeader = responseHeaders . get ( "Set-Cookie" ) ?? "" ;
29
- const responseCookies = parseResponseCookies ( cookieHeader ) ;
29
+ const responseCookies = parseSetCookieHeader ( cookieHeader ) ;
30
30
31
31
/** Add any extra set-cookie headers that were added during the request by the consumer */
32
32
responseCookies . forEach ( ( cookie , name ) => {
@@ -36,7 +36,7 @@ export function cookies(): CookieStore {
36
36
responseHeaders . delete ( "Set-Cookie" ) ;
37
37
38
38
for ( const [ name , cookie ] of cookieMap . entries ( ) ) {
39
- if ( isDeleted ( cookie ) ) cookieMap . delete ( name ) ;
39
+ if ( isCookieDeleted ( cookie ) ) cookieMap . delete ( name ) ;
40
40
responseHeaders . append ( "Set-Cookie" , cookie . serialize ( ) ) ;
41
41
}
42
42
}
@@ -108,16 +108,16 @@ export function cookies(): CookieStore {
108
108
} ) ;
109
109
}
110
110
111
- function isDeleted ( { attributes } : Cookie ) {
111
+ export function isCookieDeleted ( { attributes } : Cookie ) : boolean {
112
112
return (
113
113
attributes . maxAge === 0 ||
114
- ( attributes . expires && ! isWithinExpirationDate ( attributes . expires ) )
114
+ ( ! ! attributes . expires && ! isWithinExpirationDate ( attributes . expires ) )
115
115
) ;
116
116
}
117
117
118
- function readCookieHeader ( cookie : string ) {
118
+ export function parseCookieHeader ( cookieHeader : string ) : Map < string , string > {
119
119
try {
120
- return parseCookies ( cookie . trim ( ) ) ;
120
+ return parseCookies ( cookieHeader . trim ( ) ) ;
121
121
} catch ( error ) {
122
122
if ( error instanceof URIError ) {
123
123
return new Map < string , string > ( ) ;
@@ -128,8 +128,8 @@ function readCookieHeader(cookie: string) {
128
128
}
129
129
}
130
130
131
- function parseResponseCookies ( header : string ) : Map < string , Cookie > {
132
- const split = parseSetCookie . splitCookiesString ( header ) ;
131
+ export function parseSetCookieHeader ( header : string ) : Map < string , Cookie > {
132
+ const split = parseSetCookie . splitCookiesString ( header . trim ( ) ) ;
133
133
const parsedCookies = parseSetCookie ( split ) ;
134
134
const cookies = new Map (
135
135
parsedCookies . map ( ( { name, value, sameSite, ...attributes } ) => {
0 commit comments