* fix: `ClientResponse` now properly extends fetch's `Response`
Better experience / fix types error when working with functions that expects a fetch's `Response`
* feat(context): switch from `InterfaceToType` to `Simplify` for better performance
Also automatically infer ReturnType for cleaner code
* feat(context): infer `TypedResponse` for `TextRespond`
* feat: improve response types flow with `ResponseFormat`
Co-authored-by: Yusuke Wada <yusuke@kamawada.com>
* tests: adjust & add new tests for `TextRespond` & `ResponseFormat`
* tests: improve test of using interface
* chore: denoify
---------
Co-authored-by: Yusuke Wada <yusuke@kamawada.com>
* feat: Ensure that calls to `c.json()` have a type equivalent to `c.jsonT()`
* refactor: Objects with "response" properties are never returned by the handler
* refactor: "status" is not needed in TypedResponse
* refactor: Revive `c.jsonT()` and add @deprecated label
* refactor: Tweaks commenting on "eslint-disable" broken by `format:fix`
* test: Use `c.json()` instead of `c.jsonT()` to make sure there are no problems
* refactor: allow ambiguous type for `c.json()`
* chore: denoify
* fix: Remove unused TypedResponse from import statement
* fix: return status 500 when using validator 'form'
When using `validator('form', ...)` hono is returning a 500 status
when receiving a POST request with a JSON in request body, instead
of a bad request 400, .
This is happenning due to a unhandled error in an
underlying library (@miniflare).
https://github.com/cloudflare/miniflare/pull/711
The code changes in this PR are responsible to prepare the code to
handle possible TypeError that can be thrown in the future, by the lib
doing the FormData parsing, as per, https://fetch.spec.whatwg.org/#dom-body-formdata.
This PR should wait for bugfix on @miniflare.
* fix: json validator allowing Content-Type value other than json/application
Forgery attacks will try to avoid preflight requests when POSTing JSON
payloads manipulating the HTTP header Content-Type. For example, it will
send a JSON payload with `Content-Type=text/plain`, but the request stills
containing a JSON in its body. Those requests must be rejected.
Thus, when using the validator with the target set to `json`, we must
check the Content-Type header.
* fix: change check for json Content-Type header
Change JSON validation to only allow Content-Type header starting with
'application/json'.
Change from regexp test to starsWith builtin function, to make code more
expressive.
---------
Co-authored-by: Bruno Nascimento <bruno.nascimento@csghq.com>
* test(vitest): replace `jest` with `vitest` for core tests
* test(fastly): `jest` -> `vitest`, correct env for fastly
* test(jest): remove `jest-environment-miniflare` as dep
* test(lagon): configure `lagon` tests to run on `vitest`
* test(lambda): `jest` -> `vitest`
* test(lambda-edge): `jest` -> `vitest`
* test(node): `jest` -> `vitest`
* test(wrangler): `jest` -> `vitest`
* chore(deps): remove `jest` and `ts-jest` from deps
* test(vitest): add `yarn coverage` for checking coverage
* test(fastly): fix check for `globalThis.crypto`
* test(handler): fix stray `.only`
* test(lagon): change env file back to original path
* test(fastly): go back to `jest` until `vitest` has support for fastly env
* test(fastly): remove hack for the `crypto` global from the test
* Allow validator to apply validation to path param.
* chore: denoify
* feat(validator): Enable passing the path to ValidationFunction as a template parameter.
* chore: denoify
Co-authored-by: yusukebe <yusuke@kamawada.com>