@@ -4,7 +4,7 @@ import qs from 'qs';
44import cookie from 'cookie' ;
55import Application from './Application' ;
66import { RequestEvent , HandlerContext , RequestEventRequestContext , LambdaEventSourceType } from './request-response-types' ;
7- import { StringMap , KeyValueStringObject , StringArrayOfStringsMap , StringUnknownMap } from '@silvermine/toolbox' ;
7+ import { StringMap , KeyValueStringObject , StringArrayOfStringsMap , StringUnknownMap , isUndefined } from '@silvermine/toolbox' ;
88import ConsoleLogger from './logging/ConsoleLogger' ;
99
1010function safeDecode ( s : string ) : string {
@@ -479,6 +479,10 @@ export default class Request {
479479 const headers = evt . multiValueHeaders || _ . mapObject ( evt . headers , ( v ) => { return [ v ] ; } ) ;
480480
481481 return _ . reduce ( headers , ( memo : StringArrayOfStringsMap , v , k ) => {
482+ if ( isUndefined ( v ) ) {
483+ return memo ;
484+ }
485+
482486 const key = k . toLowerCase ( ) ;
483487
484488 memo [ key ] = v ;
@@ -554,7 +558,7 @@ export default class Request {
554558 }
555559 }
556560
557- private _parseQuery ( multiValQuery : StringArrayOfStringsMap , query : StringMap ) : { raw : string ; parsed : KeyValueStringObject } {
561+ private _parseQuery ( multiValQuery : Partial < StringArrayOfStringsMap > , query : Partial < StringMap > ) : { raw : string ; parsed : KeyValueStringObject } {
558562 let queryString ;
559563
560564 // It may seem strange to encode the URI components immediately after decoding them.
@@ -566,11 +570,15 @@ export default class Request {
566570 // values that were not correct.
567571 if ( _ . isEmpty ( multiValQuery ) ) {
568572 queryString = _ . reduce ( query , ( memo , v , k ) => {
573+ if ( isUndefined ( v ) ) {
574+ return memo ;
575+ }
576+
569577 return memo + `&${ k } =${ encodeURIComponent ( safeDecode ( v ) ) } ` ;
570578 } , '' ) ;
571579 } else {
572580 queryString = _ . reduce ( multiValQuery , ( memo , vals , k ) => {
573- _ . each ( vals , ( v ) => {
581+ _ . each ( vals || [ ] , ( v ) => {
574582 memo += `&${ k } =${ encodeURIComponent ( safeDecode ( v ) ) } ` ;
575583 } ) ;
576584 return memo ;
0 commit comments