fix(http): choose the body parser by the media type (GitHub #36)
parseRequestBody picked JSON, urlencoded or multipart with contentType.includes() on the raw header. That is case-sensitive, so a valid `Application/JSON` reached the handler as a string, and it matches anywhere in the header, so a parameter could choose the parser: `text/plain; x=application/json` was parsed as JSON. The media type is now taken from the part before any `;`, trimmed and lowercased (RFC 9110 §8.3.1), and compared exactly. The boundary is still read from the full header. A type that merely contains one of the three no longer selects its parser. `application/json-patch+json` used to be parsed as JSON and now arrives as text, as other `+json` types always have. CHANGELOG says so. test/http.test.ts sends both cases from the issue, plus their urlencoded equivalents, through the Node server. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
3 files changed
+42
-3
No files matched your search
@@ -266,6 +266,14 @@ npm treats versions as semver and semver forbids leading zeros.
|
||||
fails with `<Module> @Module metadata is missing mountpoint`. `mountpoint: ''` still mounts at the
|
||||
root.
|
||||
|
||||
- **The body parser is chosen by the media type** (GitHub #36). It was chosen by a substring of
|
||||
the raw `Content-Type` header, case-sensitively, so `Content-Type: Application/JSON` reached the
|
||||
handler as a string while `text/plain; x=application/json` was parsed as JSON. The same applied
|
||||
to urlencoded and multipart bodies. The parser now compares the media type, the part before any
|
||||
`;`, trimmed and lowercased, exactly. **A type that only contains one of the three no longer
|
||||
selects its parser:** `application/json-patch+json` used to be parsed as JSON and now arrives as
|
||||
text, like any other `+json` type always has. Parse it in the handler.
|
||||
|
||||
- **`listen()` rejects when the port is taken** (#138). A bind failure such as `EADDRINUSE` or
|
||||
`EACCES` arrives as the server's `error` event, which `listen()` did not handle: the promise
|
||||
never settled, and the error surfaced as an unhandled one. It now rejects with that error. The
|
||||
|
||||
Reference in new issue
Block a user