File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed
Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,19 @@ export default class Headers {
3434 constructor ( init = undefined ) {
3535 this [ MAP ] = Object . create ( null ) ;
3636
37+ if ( init instanceof Headers ) {
38+ const rawHeaders = init . raw ( ) ;
39+ const headerNames = Object . keys ( rawHeaders ) ;
40+
41+ for ( const headerName of headerNames ) {
42+ for ( const value of rawHeaders [ headerName ] ) {
43+ this . append ( headerName , value ) ;
44+ }
45+ }
46+
47+ return ;
48+ }
49+
3750 // We don't worry about converting prop to ByteString here as append()
3851 // will handle it.
3952 if ( init == null ) {
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ export default class Response {
2323 this . url = opts . url ;
2424 this . status = opts . status || 200 ;
2525 this . statusText = opts . statusText || STATUS_CODES [ this . status ] ;
26+
2627 this . headers = new Headers ( opts . headers ) ;
2728
2829 Object . defineProperty ( this , Symbol . toStringTag , {
Original file line number Diff line number Diff line change @@ -1205,6 +1205,18 @@ describe('node-fetch', () => {
12051205 } ) ;
12061206 } ) ;
12071207
1208+ it ( 'should return all headers using raw()' , function ( ) {
1209+ url = `${ base } cookie` ;
1210+ return fetch ( url ) . then ( res => {
1211+ const expected = [
1212+ 'a=1' ,
1213+ 'b=1'
1214+ ] ;
1215+
1216+ expect ( res . headers . raw ( ) [ 'set-cookie' ] ) . to . deep . equal ( expected ) ;
1217+ } ) ;
1218+ } ) ;
1219+
12081220 it ( 'should allow iterating through all headers with forEach' , function ( ) {
12091221 const headers = new Headers ( [
12101222 [ 'b' , '2' ] ,
You can’t perform that action at this time.
0 commit comments