Skip to content

Commit 9670fe9

Browse files
committed
replace headers with same caseinsensitive key to match http spec
1 parent 554e10d commit 9670fe9

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

modules/openapi-generator/src/main/resources/typescript/http/http.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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

samples/openapi3/client/petstore/typescript/tests/default/test/http/isomorphic-fetch.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)