11import test from "ava" ;
22import { parse , stringify } from "devalue" ;
33import {
4+ createHTTPReducers ,
5+ createHTTPRevivers ,
46 structuredSerializableReducers ,
57 structuredSerializableRevivers ,
68} from "miniflare" ;
9+ import { NODE_PLATFORM_IMPL } from "../../../src/plugins/core/proxy/types" ;
710
811test ( "serialize RegExp object consisting of only ascii chars" , ( t ) => {
912 const input = new RegExp ( / H e l l o W o r l d / ) ;
@@ -24,3 +27,24 @@ test("serialize RegExp object containing non-ascii chars", (t) => {
2427 const deserialized = parse ( serialized , structuredSerializableRevivers ) ;
2528 t . deepEqual ( deserialized , input ) ;
2629} ) ;
30+
31+ test ( "serialize Headers object consisting of multiple Set-Cookie headers" , ( t ) => {
32+ const impl = NODE_PLATFORM_IMPL ;
33+
34+ const headers = new impl . Headers ( [
35+ [ "content-type" , "application/json" ] ,
36+ [ "authorization" , "Bearer token" ] ,
37+ ] ) ;
38+ headers . append ( "Set-Cookie" , "cookie1=value_for_cookie_1; Path=/; HttpOnly;" ) ;
39+ headers . append ( "Set-Cookie" , "cookie2=value_for_cookie_2; Path=/; HttpOnly;" ) ;
40+
41+ const serialized = stringify ( headers , createHTTPReducers ( impl ) ) ;
42+ const deserialized = parse ( serialized , createHTTPRevivers ( impl ) ) ;
43+ t . true ( deserialized instanceof impl . Headers ) ;
44+ t . is ( deserialized . get ( "content-type" ) , "application/json" ) ;
45+ t . is ( deserialized . get ( "authorization" ) , "Bearer token" ) ;
46+ t . deepEqual ( deserialized . getSetCookie ( ) , [
47+ "cookie1=value_for_cookie_1; Path=/; HttpOnly;" ,
48+ "cookie2=value_for_cookie_2; Path=/; HttpOnly;" ,
49+ ] ) ;
50+ } ) ;
0 commit comments