Skip to content

Commit

Permalink
fix(oas): parse headers as case insensitve
Browse files Browse the repository at this point in the history
Header name fields were not being handled as case-insensitive,
which would cause unwanted authentication and validation errors.
Refer RFC7230.

Fixes exegesis-js#75
  • Loading branch information
brocoli-tapps committed Feb 4, 2019
1 parent 41ccdb8 commit 0c58fb0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/oas3/Operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { contentToRequestMediaTypeRegistry } from './oasUtils';
import RequestMediaType from './RequestMediaType';
import Oas3CompileContext from './Oas3CompileContext';
import Parameter from './Parameter';
import { RawValues, parseParameterGroup, parseQueryParameters } from './parameterParsers';
import { RawValues, parseParameterGroup, parseQueryParameters, parseHeaderParameters } from './parameterParsers';
import {
ParametersMap,
ParametersByLocation,
Expand Down Expand Up @@ -211,7 +211,7 @@ export default class Operation {

return {
query: parseQueryParameters(this._parameters.query, queryString),
header: parseParameterGroup(this._parameters.header, headers || {}),
header: parseHeaderParameters(this._parameters.header, headers || {}),
server: params.serverParams || {},
path: rawPathParams ? parseParameterGroup(this._parameters.path, rawPathParams) : {},
cookie: {}
Expand Down
14 changes: 14 additions & 0 deletions src/oas3/parameterParsers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,17 @@ export function parseQueryParameters(
const rawValues = querystring.parse(query || '', '&', '=', {decodeURIComponent: (val: string) => val});
return _parseParameterGroup(params, rawValues, query || '');
}

export function parseHeaderParameters(
params: {
location: ParameterLocation,
parser: ParameterParser
}[],
rawHeaders: RawValues
) {
const rawValues = ld.mapKeys(
rawHeaders,
(_value: string | string[] | undefined, key: string) => key.toLowerCase()
);
return _parseParameterGroup(params, rawValues, '');
}

0 comments on commit 0c58fb0

Please sign in to comment.