Skip to content

Commit

Permalink
Make HTTP header names case-insensitive
Browse files Browse the repository at this point in the history
RFC 2616 specifies HTTP header names as case-insensitive. Thus,
lower-case the names we get from the schema.

Node's HTTP library does the same for incoming header names, so we don't
need to do anything there.
  • Loading branch information
mmalecki committed Dec 19, 2019
1 parent c72950e commit 7638591
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/compiler/CompiledParameterHeader.ts
Expand Up @@ -16,18 +16,19 @@ export default class CompiledParameterHeader {
* If in is "header" and the name field is "Accept", "Content-Type" or "Authorization",
* the parameter definition SHALL be ignored.
*/
private ignoreHeaders = ['Accept', 'Content-Type', 'Authorization'];
private ignoreHeaders = ['Accept', 'Content-Type', 'Authorization'].map(header => header.toLowerCase())

constructor(parameters: ParameterObject[], options: Partial<ChowOptions>) {
for (const parameter of parameters) {
if (this.ignoreHeaders.includes(parameter.name)) {
const headerName = parameter.name.toLowerCase()
if (this.ignoreHeaders.includes(headerName)) {
continue;
}

this.headerSchema.properties![parameter.name] = parameter.schema || {};
this.headerSchema.properties![headerName] = parameter.schema || {};

if (parameter.required) {
this.headerSchema.required!.push(parameter.name);
this.headerSchema.required!.push(headerName);
}
}

Expand Down

0 comments on commit 7638591

Please sign in to comment.