File tree Expand file tree Collapse file tree
modules/openapi-generator/src/main/resources/typescript/http
samples/openapi3/client/petstore/typescript/tests/default/test/http Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -183,6 +183,13 @@ export class RequestContext {
183183 }
184184
185185 public setHeaderParam(key: string, value: string): void {
186+ // Delete any existing headers with case -insensitive matching
187+ const lowerKey = key.toLowerCase();
188+ for (const existingKey in this.headers) {
189+ if (existingKey.toLowerCase() === lowerKey) {
190+ delete this.headers[existingKey];
191+ }
192+ }
186193 this.headers[key] = value;
187194 }
188195
Original file line number Diff line number Diff line change @@ -67,5 +67,16 @@ for (let libName in libs) {
6767 done ( ) ;
6868 } ) . catch ( done )
6969 } )
70+
71+ it ( "Case Insensitive Header Replacement" , ( done ) => {
72+ let requestContext = new petstore . RequestContext ( "http://httpbin.org/cookies" , petstore . HttpMethod . GET ) ;
73+ requestContext . setHeaderParam ( "testkey1" :"testvalue1" ) ;
74+ expect ( requestContext . getHeaders ( ) . testkey1 ) . to . eq ( "testvalue1" ) ;
75+
76+ // replace with differently cased key
77+ requestContext . setHeaderParam ( "tEsTkeY1" :"testvalue2" ) ;
78+ expect ( requestContext . getHeaders ( ) . testkey1 ) . to . be . undefined ;
79+ expect ( requestContext . getHeaders ( ) . testkey1 ) . to . eq ( "testvalue2" ) ;
80+ } )
7081 } )
71- }
82+ }
You can’t perform that action at this time.
0 commit comments