Closed Kiskae closed 2 weeks ago
Hi, @Kiskae. Thanks for reporting this.
Would I be correct to assume that this can be fixed by ading .map(x => x.trim())
in here?
If so, would you be interested in opening a pull request to help us fix this?
This has been released in v0.3.1!
Make sure to always update to the latest version (npm i @mswjs/source@latest
) to get the newest features and bug fixes.
Predictable release automation by @ossjs/release.
Description
The accept header can contain whitespace in addition to ',' between content types, if the content schema does not match the first content type then it doesn't match at all.
Reproduction steps
*/*
Accept: text/html, */*
Expected behavior
The content returns as described by the openapi spec.
Initial assessment
In https://github.com/mswjs/source/blob/main/src/open-api/utils/open-api-utils.ts
toHeaders
andtoBody
split the accept header using.split(',')
. This means that all content-types besides the first are prefixed by existing whitespace in the accept header. This then gets included in the regex, which makes it fail to match since the openapi content types usually don't contain whitespace.Currently I'm patching this by adding
.trim()
to thecontentTypeToRegExp
method.Screenshots