@@ -95,34 +95,55 @@ test('getSocketPath', () => {
9595 expect ( socketPath ) . toEqual ( '/tmp/server0.sock' )
9696} )
9797
98- describe ( 'forwardResponseToApiGateway: content-type encoding' , ( ) => {
99- const PassThrough = require ( 'stream' ) . PassThrough
100-
101- class MockResponse extends PassThrough {
102- constructor ( statusCode , headers , body ) {
103- super ( )
104- this . statusCode = statusCode
105- this . headers = headers || { }
106- this . write ( body )
107- this . end ( )
108- }
98+ const PassThrough = require ( 'stream' ) . PassThrough
99+
100+ class MockResponse extends PassThrough {
101+ constructor ( statusCode , headers , body ) {
102+ super ( )
103+ this . statusCode = statusCode
104+ this . headers = headers || { }
105+ this . write ( body )
106+ this . end ( )
109107 }
108+ }
110109
111- class MockServer {
112- constructor ( binaryTypes ) {
113- this . _binaryTypes = binaryTypes || [ ]
114- }
110+ class MockServer {
111+ constructor ( binaryTypes ) {
112+ this . _binaryTypes = binaryTypes || [ ]
115113 }
114+ }
116115
117- class MockContext {
118- constructor ( resolve ) {
119- this . resolve = resolve
120- }
121- succeed ( successResponse ) {
122- this . resolve ( successResponse )
123- }
116+ class MockContext {
117+ constructor ( resolve ) {
118+ this . resolve = resolve
119+ }
120+ succeed ( successResponse ) {
121+ this . resolve ( successResponse )
124122 }
123+ }
125124
125+ describe ( 'forwardResponseToApiGateway: header handling' , ( ) => {
126+ test ( 'multiple headers with the same name get transformed' , ( ) => {
127+ const server = new MockServer ( )
128+ const headers = { 'foo' : [ 'bar' , 'baz' ] }
129+ const body = 'hello world'
130+ const response = new MockResponse ( 200 , headers , body )
131+ return new Promise (
132+ ( resolve , reject ) => {
133+ const context = new MockContext ( resolve )
134+ awsServerlessExpress . forwardResponseToApiGateway (
135+ server , response , context )
136+ }
137+ ) . then ( successResponse => expect ( successResponse ) . toEqual ( {
138+ statusCode : 200 ,
139+ body : body ,
140+ headers : { Foo : 'bar' , fOo : 'baz' } ,
141+ isBase64Encoded : false
142+ } ) )
143+ } )
144+ } )
145+
146+ describe ( 'forwardResponseToApiGateway: content-type encoding' , ( ) => {
126147 test ( 'content-type header missing' , ( ) => {
127148 const server = new MockServer ( )
128149 const headers = { 'foo' : 'bar' }
0 commit comments