0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-30 01:56:18 +01:00
Commit Graph

477 Commits

Author SHA1 Message Date
watany
d8b0e7e51e
refactor(helper): Use getRuntimeKey() in env function (#1454)
* refactor

* lint&denoify

* marker

* type assersion

* revert fastly message
2023-09-15 18:40:06 +09:00
Yusuke Wada
9cb6b37fa3
fix(types): fix the type error in MiddlewareHandlerInterface (#1449)
* fix(types): fix the type error in `MiddlewareHandlerInterface`

* denoify
2023-09-13 08:57:52 +09:00
hagishi
00af2a5e60
feat: allow the type of app.request (#1444)
* feat: allow the type of app.request

* typo
2023-09-13 08:04:04 +09:00
Yusuke Wada
f521d30301
fix(hono-base): deprecate should be deprecated (#1448)
* fix(hono-base): `deprecate` should be `deprecated`

* denoify
2023-09-12 22:12:39 +09:00
hagishi
2a13b095c3
feat: extend app.request paramters (#1442)
* feat: extend app.request paramters

* denoify
2023-09-12 08:31:41 +09:00
Yusuke Wada
e4c4322941
feat(helper): introduce factory helper (#1434)
* feat(helper): introduce `factory` helper

* denoify
2023-09-11 07:31:30 +09:00
Yusuke Wada
27d26204af
feat(jsx): export FC (#1420)
* feat(jsx): export `FC`

* denoify
2023-09-09 17:12:21 +09:00
Yusuke Wada
665f456f84
feat(context): introduce c.var (#1406)
* feat(context): introduce `c.var`

* denoify

* make it a property

* denoify

* make it a read-only

* fix the complex pattern
2023-09-09 17:11:16 +09:00
Yusuke Wada
0f6f40354b Merge branch 'main' into next 2023-09-09 17:07:42 +09:00
jkeys089
d6ec48ee02
feat(cookie): cookie parsing improvements (#1428) 2023-09-09 17:05:09 +09:00
Yusuke Wada
f2bdfd8423 Merge branch 'main' into next 2023-09-09 16:55:59 +09:00
Yusuke Wada
7418198e36
fix(client): remove async from $url() (#1430)
* v3.6.0-rc.1

* fix(client): remove async from `$url()`

* denoify
2023-09-09 16:15:13 +09:00
Yusuke Wada
bb1b9146ed
fix(types): fix MergeSchemaPath correct (#1426)
* fix(types): fix `MergeSchemaPath` correct

* denoify
2023-09-08 22:22:38 +09:00
Yusuke Wada
963b94e67e Merge branch 'main' into next 2023-09-05 22:09:01 +09:00
Yusuke Wada
aee2093a39
feat(req): deprecate c.req.headers (not c.req.header) and others (#1410)
* feat(req): deprecate `c.req.headers` (not `c.req.header`) and others

* denoify
2023-09-05 22:08:43 +09:00
Yusuke Wada
3351e9db96
fix(jsx): enable Fragment (#1412)
* fix(jsx): enable `Fragment`

* denoify
2023-09-05 18:14:32 +09:00
Yusuke Wada
405ec8cdb7
fix(utils/buffer): don't decode space as + (#1411)
* fix(`utils/buffer`): don't decode space as `+`

* denoify
2023-09-05 17:30:40 +09:00
Yusuke Wada
40c350cd88
feat(context): introduce c.render() (#1397)
* feat(context): introduce `c.render()`

* denoify
2023-09-05 16:01:58 +09:00
Derrick Farris
8cea5bc9c3
feat(context): add status to TypedResponse (#1403)
* feat(context): add `status` to `TypedResponse`

* test(context): make sure `tRes` has `status` prop
2023-09-05 15:58:43 +09:00
Yusuke Wada
08cd702760 Merge branch 'main' into next 2023-09-05 15:55:47 +09:00
Yusuke Wada
d194e9b3c2
fix(rpc): infer path with route() and basePath() (#1401)
* fix(rpc): infer path with `route()` and `basePath()`

* denoify
2023-09-04 07:59:04 +09:00
Yusuke Wada
5cbd89c3ae
fix(validator): cache arrayBuffer to use after validation (#1393)
* wip

* fix(validator): cache `arrayBuffer` to use after validation

* denoify

* refactor

* denoify

* make it `bufferToFormData()` in utils/buffer.ts
2023-09-03 14:43:01 +09:00
jkeys089
0316bbadf6
feat: improvements to secure headers middleware (#1395) 2023-09-03 07:51:36 +09:00
renzor
7b68ff61a4
feat: Add $url method to hono client to extract an endpoint's url (#1384) 2023-09-02 07:15:59 +09:00
Yusuke Wada
0ac27fc817
fix(types): infer a response type for async handler (#1385)
* fix(types): infer a response type for async handler

* denoify
2023-08-29 23:07:27 +09:00
Yusuke Wada
8ac21d3881
fix(context): different types using jsonT() (#1379)
* fix(context): `jsonT()` handle diferrent types

* denoify
2023-08-28 22:33:06 +09:00
Yusuke Wada
1eb4a1dcdc
fix(types): fix AddDollar (#1373) 2023-08-24 16:58:02 +09:00
Yusuke Wada
3bd44fa25c
fix(types): export ToSchema (#1372)
* fix(types): export `ToSchema`

* denoify
2023-08-24 16:12:17 +09:00
Yusuke Wada
6034dd7f7f
fix(types): remove type-errors for routes (#1371)
* fix(types): remove type-errors for routes

* denoify

* fixed the client and the presets

* rename
2023-08-24 15:36:49 +09:00
Yusuke Wada
d678c75808
fix(compress): delete content-length header (#1366)
* fix(compress): delete `content-length` header

* denoify
2023-08-23 09:11:37 +09:00
Yusuke Wada
a168ed584b
fix(client): continue if query value is undefined (#1368)
* fix(client): `continue` if query value is `undefined`

* denoify
2023-08-23 09:11:25 +09:00
Yusuke Wada
f1c9d7b74d
fix(middleware.ts): export secure-headers for Deno (#1361) 2023-08-21 15:38:35 +09:00
Yusuke Wada
e07019125d
feat: introduce "Helpers" (#1353)
* mv jsx

* introduce helper

* denoify & add src/helper.ts for Deno

* remove `c` not used

* remove `c` in lagon test

* remove `src/adapter.ts` not used
2023-08-21 15:22:37 +09:00
watany
66b915ac07
feat(middleware): Alternative middleware equivalent to Helmet (#1341)
* v0.1

* v0.2

* v0.3

* v0.4

* v0.5

* v1.0

* adding require-corp

* fix

* denoify

* rename header"s"

* await phase

* refactor routing

* rename packages

* format and lint

* denoify

* add testing

* Cross-Origin-Embedder-Policy

* csp

* denoify

* linter

* disable eslint fix

* default likes helmet

* denoify
2023-08-21 00:24:59 +09:00
asaxeye
88e7650ee8
fix(types): corrected argument types for Context methods (#1357) 2023-08-21 00:23:05 +09:00
Yusuke Wada
2b274662e9
fix(client): ignore header and cookie types (#1359)
* fix(client): ignore `header` and `cookie` types

* denoify
2023-08-21 00:19:04 +09:00
Yusuke Wada
07bc29ee60
feat(app): pass env to getPath() (#1345)
* feat(app): pass `env` to `getPath()`

* denoify
2023-08-20 16:03:25 +09:00
sizumita
4a027474f1
fix(type): add missing S to RemoveBlankRecord (#1354)
* fix(type): add missing S to RemoveBlankRecord

* fix(test): Fix testcase mistake

* run prettier
2023-08-20 15:45:22 +09:00
Yusuke Wada
8adc8c14c4
feat(validator): supports header and cookie (#1352)
* feat(validator): supports `header` and `cookie`

* denoify
2023-08-19 18:23:04 +09:00
Yusuke Wada
9e391cf8f9
feat(validator): deprecate queries (use query instead) (#1350)
* fixed test

* denoify
2023-08-19 17:50:50 +09:00
Yusuke Wada
2faaa15ea1
fix(req): fix inferring types in req.valid() (#1351)
* fix(req): fix inferring types in `req.valid()`

* denoify
2023-08-19 17:48:49 +09:00
Yusuke Wada
dc0696f2d1
refactor(context): allow passing HonoRequest as 1st arg (#1312)
* perf(context): allow passing `HonoRequest` as 1st arg

* denoify

* test: fix the node runtime test

* test: fix deno tests
2023-08-19 16:20:08 +09:00
Torsten Engelbrecht
1a2c0d58e5
fix(middleware): signed cookie misinterpretation of cookie values with dot (#1342)
Close #1337
2023-08-18 18:56:10 +09:00
Yusuke Wada
f254fdc846
feat(req): cache body content (#1333)
* feat(req): cache body content

* denoify

* use destruction

* denoify
2023-08-18 16:25:48 +09:00
Tanner Scadden
fa1c7df42b
fix(client): Web query undefined check (#1340)
* Added check for undefined in query

* denofied
2023-08-18 16:18:21 +09:00
Sor4chi
49ce537684
refactor(compress-middleware): resolve type assertion using const assertion (#1343)
* refactor: resolve type assertion using const assertion

* denoify
2023-08-18 16:14:58 +09:00
Yusuke Wada
91af6d3007
refactor: denoify (#1344) 2023-08-18 16:13:04 +09:00
Sor4chi
8ab0ccd7cc
docs: support change of escapeTextForBrowser path in react (#1336) 2023-08-16 07:39:35 +09:00
Yusuke Wada
acbd495bbe
fix(app): set / for path as default (#1330)
* fix(app): set `/` for `path` as default

* denoify
2023-08-15 00:33:16 +09:00
Yusuke Wada
70e0b3b8c6 denoify 2023-08-14 23:34:56 +09:00
Yusuke Wada
88537363d8 denoify 2023-08-14 22:46:45 +09:00
sizumita
fa75c26d0b
fix(type): Fix reflecting basePath when no path in handler (#1325)
* fix(type): Reflects BasePath in HandlerInterface if without path

* test(path): add path param tests for routing without path and with basePath

* did denonify

* fix(type): Handler type

* test(path): add test for chained route
2023-08-14 22:09:44 +09:00
CyberFlame
66b1619f2d
fix(cookie): misspell (#1321)
* fix misspell

* denoify
2023-08-14 16:11:14 +09:00
rosahaj
5320ed6c57
fix(type): Export Schema type to allow route exports in declaration files (#1309)
* Export Schema type to allow route exports in declaration files

* Apply changes to src/mod.ts as well

* denoify
2023-08-11 07:05:51 +09:00
Yusuke Wada
b7f12ddbe9 Revert "refactor(utils/url): remove unnecessary code (#1315)"
This reverts commit ce4ac5a6f5.
2023-08-10 16:39:28 +09:00
Yusuke Wada
ce4ac5a6f5
refactor(utils/url): remove unnecessary code (#1315)
* refactor(utils/url): remove unnecessary code

* denoify
2023-08-10 15:02:14 +09:00
Yusuke Wada
48a8729862
perf(hono-base): use constructor.name instead of instanceof (#1311)
* perf(hono-base): use `constructor.name` instead of `instanceof`

* denoify
2023-08-10 10:10:40 +09:00
Tim Fish
9be3b7b6dd
Add missing wasm mime type (#1307)
* Add missing wasm mime type

* deno dist
2023-08-09 21:45:07 +09:00
Yusuke Wada
a104bf0010
fix(netlify): fix import paths (#1304) 2023-08-08 09:35:05 +09:00
Yusuke Wada
f7bce19751
fix(validator): support async validator func (#1303)
* fix(validator): support async validator func

* denoify
2023-08-07 21:26:53 +09:00
Yusuke Wada
85f8ab663f
refactor(app): add "deprecate message" for app.handleEvent() (#1298)
* refactor(app): add "deprecate message" for `app.handleEvent()`

* denoify
2023-08-05 23:41:45 +09:00
Yusuke Wada
4a3c5834de
chore(benchmark): update the handle-event benchmark (#1297)
* chore(benchmark): update the handle-event benchmark

* denoify
2023-08-05 23:37:41 +09:00
Yusuke Wada
8e2eaf9d24
docs(jsdoc): fix a app.route() JSDoc description (#1296)
* docs(jsdoc): fix a `app.route()` JSDoc description

* denoify
2023-08-05 23:28:34 +09:00
Yusuke Wada
8b0f189a3f refactor(json-pretty): don't use c.pretty() (#1288) 2023-08-05 18:14:57 +09:00
Yusuke Wada
09368ac9cc
feat(adapter): add Netlify adapter (#1290)
* feat(adapter): add Netlify adapter

* denoify
2023-08-05 18:12:02 +09:00
Yusuke Wada
85b54920f9
feat(parseBody): allow passing generics to parseBody() (#1289)
* feat(parseBody): allow passing generics to `parseBody()`

* denoify
2023-08-05 18:10:12 +09:00
Torsten Engelbrecht
35246d0de6
feat(middleware): Simple cookie signing functionality (#1279) 2023-08-05 17:19:08 +09:00
Yusuke Wada
47ae014724
perf(context): add init flag (#1284)
* perf(context): add `init` flag

* denoify
2023-08-04 00:09:12 +09:00
Yusuke Wada
d5cfe040d8
fix(types): add a missing handler type (#1283)
* fix(types): add a missing handler type

* fix & denoify
2023-08-03 23:09:58 +09:00
watany
4f7d027f5b
doc(readme): adding Lambda@Edge (#1278) 2023-08-01 10:38:28 +09:00
Yusuke Wada
e851e9bd82
perf(utils/url): use regexp instead of indexOf() (#1276)
* perf(utils/url): use regexp instead of `indexOf()`

* remove unused file

* denoify
2023-07-29 23:38:55 +09:00
Yusuke Wada
8ea833a7d0
refactor(hono-base): remove async/await from app.request (#1275)
* refactor(hono-base): remove async/await from `app.request`

* denoify
2023-07-28 17:52:11 +09:00
Yusuke Wada
77b7ac7fe7
fix(utils/filepath): allow .. in filename (#1272)
* fix(utils/filepath): allow `..` in filename

* denoify

* support `./foo../bar.txt`

* denoify

* add tests

---

Co-authored-by: Taku Amano <taku@taaas.jp>
2023-07-27 11:43:42 +09:00
Yusuke Wada
614ab9d6e4
fix(utils/filepath): don't allow dot segments (#1271) 2023-07-27 08:37:20 +09:00
Codinak
1495f8b41b
fix(jsx): escapeToBuffer vulnerability (#1266)
* fix escapeToBuffer vulnerability

Escape single quote (0x27) to limit execution capabilities under certain conditions.

* denoify
2023-07-26 23:12:25 +09:00
Yusuke Wada
b0a368676e
fix(hono-base): enable strict with getPath option (#1259)
* fix(hono-base): enable `strict` with `getPath` option

* denoify
2023-07-23 16:03:45 +09:00
Yusuke Wada
5c1f7f033c
fix(hono/quick): use SmartRouter (#1250)
* fix(hono/quick): use SmartRouter

* denoify
2023-07-20 17:43:35 +09:00
Yusuke Wada
47dbeaa147
fix(trie-router-router): For "Named param with trailing wildcard" (#1246)
* fix(trie-router-router): For "Named param with trailing wildcard"

* denoify
2023-07-20 16:48:38 +09:00
Taku Amano
3e663af916
fix(pattern-router): For "Named param with trailing wildcard" (#1244)
* fix(pattern-router): For "Named param with trailing wildcard"

* chore: denoify
2023-07-20 16:48:21 +09:00
James A Rosen
4b39eba618
refactor(etag): simplify cloning logic (#1242)
If the upstream response doesn't include an `ETag` header, the ETag
middleware needs to clone the response so it can read the body to
compute an ETag. This commit simplifies the management of the original
and cloned responses.
2023-07-19 09:57:57 +09:00
markthree
0efc6952a3
perf(deno/middlewares/serveStatic): serve static with stream (#1234)
* perf(deno/middlewares/serveStatic): serve static with stream

* Revert "perf(deno/middlewares/serveStatic): serve static with stream"

This reverts commit 0360966d1e.

* fix(deno/middlewares/serveStatic): fix position and test for serve static with stream

* chore(deno/middlewares/serveStatic): clean temp dist files
2023-07-15 14:28:48 +09:00
Yusuke Wada
42dc3646a0
fix(cache): clone the response (#1232)
* fix

* clone the response shortly

* add test for not found

* denoify

---------

Co-authored-by: brn <brn@b6n.ch>
2023-07-15 09:36:03 +09:00
Yusuke Wada
cef0adb1d6
fix(mount): include query params (#1224)
* fix(mount): include query params

* denoify
2023-07-08 18:25:50 +09:00
Pascal
b0e0ce85a0
feat: Add Server-Timing API as middleware (#1215)
* feat(timing): add Server-Timing API as middleware

* refactor(timing): rename config to TimingOptions
2023-07-03 11:19:49 +09:00
flow
d6f4d1a501
Fix replaceUrlParam to ignore regexp in path (#1214)
* Fix replaceUrlParam to ignore regexp in path

* Generate deno_dist files
2023-07-02 22:25:19 +09:00
Yusuke Wada
8ebd8b7b76
fix(jsonT): remove overloads from JSONTRespond (#1208)
* fix(`jsonT`): remove overloads from `JSONTRespond`

* denoify

* update tests
2023-06-29 20:09:00 +09:00
ryoppippi
bae5419d54
feat: add deleteCookie (#1190)
* add deleteCookie

* fix test

* fix test

* add test for deteleCookie with third argument opt
2023-06-29 19:58:38 +09:00
Yusuke Wada
5b873fcc5c
fix(types): allow not to set skipLibCheck (#1206)
* fix(types): allow not to set `skipLibCheck`

* use `unknown`

* denoify
2023-06-29 16:48:00 +09:00
James A Rosen
ddc34e1f6a
perf(Request): optimize Request.prototype.header (#1204)
`Request.prototype.header` has two overloads:

 1. with a string name, it returns that header value if present
 2. with no argument, it returns all the headers as an object

Previously, the implementation built the whole object for (2) even when
returning a single header. This was wasteful. This commit changes it to
return the header by name if specified and only iterate over all the
headers when the caller asks for the whole object.
2023-06-29 16:27:05 +09:00
James A Rosen
f356702efc
fix(etag): support multi-value If-None-Match (#1199)
* chore(etag): reduce global state in tests

Previously, the `etag` tests used a single Hono `app` that was
instantiated statically before the tests. Having a shared app increases
the chances of inter-test conflicts and makes it impossible to modify
the app for a single test. This, in turn, makes it harder for test
maintainers to see the connection between the app configuration and the
expectations.

This commit moves the creation of the `app` into a `beforeEach` block
and moves any app configuration that relates to a single test case into
that test case.

* perf(etag): don't override ETags from upstream

Previously, the `etag` middleware would always compute an `ETag`
header based on the SHA-1 of the `Response` body. In cases where the
upstream response already includes the header, this wastefully
clones the response, reads the body into memory, and computes a hash.

This commit changes the middleware to bypass the hash computation if
the `Response` already has an ETag.

* perf(etag): 304s include only necessary headers

The spec[^1] for 304 Not Modified says,

> The server generating a 304 response MUST generate any of the
> following header fields that would have been sent in a 200 (OK)
> response to the same request:
>
>  * Content-Location, Date, ETag, and Vary
>  * Cache-Control and Expires (see [CACHING])
>
> Since the goal of a 304 response is to minimize information transfer
> when the recipient already has one or more cached representations, a
> sender SHOULD NOT generate representation metadata other than the
> above listed fields unless said metadata exists for the purpose of
> guiding cache updates (e.g., Last-Modified might be useful if the
> response does not have an ETag field).

Previously, the `etag` middleware was sending all headers from the
original response except for `content-type` (omitted by
`Context.prototype.set res`) and `content-length` (omitted by the `etag`
middleware itself).

This commit changes the middleware to include only the headers
required with the spec, upgrading it from _conditionally compliant_ to
_fully compliant_. The list is configurable as
`options.retainedHeaders`.

[^1]: https://www.rfc-editor.org/rfc/rfc9110#name-304-not-modified

* fix(etag): Support multi-value If-None-Match

The spec[^1] for `If-None-Match` says,

> If the field value is a list of entity tags, the condition is false if
> one of the listed tags matches the entity tag of the selected
> representation.

and provides these examples:

```
If-None-Match: "xyzzy"
If-None-Match: W/"xyzzy"
If-None-Match: "xyzzy", "r2d2xxxx", "c3piozzzz"
If-None-Match: W/"xyzzy", W/"r2d2xxxx", W/"c3piozzzz"
If-None-Match: *
```

The value `*` isn't relevant for this middleware, but the other values
are.

This commit adds support for multi-value comma-separated ETags in the
`If-None-Match` header.

[^1]: https://www.rfc-editor.org/rfc/rfc9110#name-if-none-match

* perf(etag): prefer Header.prototype.get

Previously, the `etag` middleware used `c.req.header(...)` to access the
`If-None-Match` header. This method works, but is less efficient than
accessing the value via the raw `Headers` object.

Additionally, the middleware was trying multiple case versions for the
same header, but header-lookup is case-insensitive, so it was wasting
time on requests that lacked the header altogether.

This change also makes `etag` consistent with the other middleware in
this repo (e.g. `basic-auth`, `compress`), which all use
`c.req.headers.get(...)` to access headers.
2023-06-29 16:23:26 +09:00
Yusuke Wada
ee5929b045
fix(tsconfig): remove skipLibCheck (#1201) 2023-06-26 17:14:40 +09:00
Yusuke Wada
4b2dfb824b
fix(utils/cookie): allow 0 to maxAge (#1196)
* fix(utils/cookie): allow 0 to maxAge

* denoify
2023-06-23 17:33:20 +09:00
Yusuke Wada
e2b26d6074
fix(cookie): maxAge should be positive (#1194)
* Allow setting cookie's maxAge to 0.

* fix(cookie): `maxAge` should be positive

* denoify

---------

Co-authored-by: David Manouchehri <david.manouchehri@ai.moda>
2023-06-22 22:37:07 +09:00
Kelly Littlepage
387d696303
fix: application/x-www-form-urlencoded decoding (#1189)
The current logic for decoding application/x-www-form-urlencoded is
overly restrictive and misses `Content-Type` headers with a character
encoding set, i.e., application/x-www-form-urlencoded; charset=UTF-8.

This fix harmonizes the logic for handling multipart/form-data
and application/x-www-form-urlencoded in the `parseBody` method of
request objects.
2023-06-21 22:51:59 +09:00
Yusuke Wada
5f9453b498
feat(jsx): React-like style conversion (#1159)
* feat(jsx): React-like `style` conversion

* denoify
2023-06-07 21:56:04 +09:00
IGUCHI Kanahiro
a6b0833060
fix: avoid range-error (#1168)
* fix: avoid range-error

* fix: avoid range-error

* denoify
2023-06-07 21:54:49 +09:00
Alexander Kozlov
8387b8c0f6
fix(HttpException): error message should not be the HTTP reason phrase (#1161)
* fix(HttpException): error message should not be the HTTP reason phrase

* review fixes

---------

Co-authored-by: Nasa <nasa@mail.inc>
2023-06-07 21:17:52 +09:00
ayame113
81d271279c
feat: Allow context.jsonT to take interface as an argument (#1162) 2023-06-06 10:23:09 +09:00
Taku Amano
8a1b9aa9a8
refactor: Tweaks variable names to reduce code. (#1157)
* refactor: Tweaks variable names to reduce code.

* Delete meaningless comments

* chore: denoify
2023-06-04 09:16:29 +09:00
Yusuke Wada
2d6abaff5c
fix(tire-router/pattern-router): fixed the named capture issue (#1148)
* fix(trie-router): fixed the named capture issue

* denoify

* denoify

* refactor(pattern-router): Use Object.assign for shortening the code. (#1154)

* refactor(pattern-router): Use `Object.assign` for shortening the code.

* chore: denoify

---------

Co-authored-by: Taku Amano <taku@taaas.jp>
2023-06-03 09:08:01 +09:00