Commit 61e165c
next (#5154)
* perf(hono-base): avoid rest parameter in `fetch` (#5113)
* perf(context): iterate the header record with for..in (#5118)
* perf(url): replace regex tests with indexOf (#5121)
* perf(context): skip Headers creation when there are no headers to merge (#5122)
* perf(urls): refactor `tryDecodeURIComponent` (#5158)
* chore(benchmarks): correct src path on Windows, add json and middleware cases (#5173)
The default src path was computed with `URL.pathname`, which yields
`/C:/sources/hono/src` on Windows and, after `pathToFileURL`, the broken
path `C:\C:\sources\hono\src`. `fileURLToPath` is correct on all platforms.
Also adds two cases:
- `json GET /user` isolates the `c.json()` response path, which was
previously only measured inside `body POST /json` mixed with request
body parsing.
- `middleware GET /mw/hello` covers the multi-handler `compose` dispatch
path, which none of the existing cases exercised.
* perf(context): drop the throwaway `env` field initializer (#5174)
`env: E['Bindings'] = {}` allocated an object on every `Context`
construction that `#dispatch` immediately overwrote with the real env,
so the allocation was wasted on every request.
The initializer only ever mattered for `new Context(req)` without
options, which now gets its `{}` from the constructor's `else` branch.
Semantics are unchanged, including `env` being `undefined` when
`options.env` is `undefined`.
* perf(request): allocate `#validatedData` lazily (#5175)
The constructor allocated `#validatedData = {}` on every `HonoRequest`,
so every request paid for the validator feature whether or not any
validator ran.
It is now created on the first `addValidatedData()` call. `valid()`
reads through optional chaining and still returns `undefined` for
targets that were never validated, as before.
* perf(request): probe the body cache without allocating (#5176)
`#cachedBody` used `Object.keys(bodyCache)[0]` to find any already
cached body, allocating a fresh array on every body read (`req.json()`,
`req.text()`, ...) just to read one element.
A `for ... in` loop that returns on its first iteration gives the same
first-key-by-insertion-order result with no allocation. `bodyCache` is a
plain object literal, so there are no enumerable prototype keys to
consider.
* chore(benchmarks): stabilize measurements by forcing mitata batching (#5183)
* perf(hono-base): restore the rest parameter in `fetch` (#5184)
* perf(context): restore the `env` field initializer (#5186)
* feat: add first-class QUERY method support (#5070)
* feat(etag): support conditional requests for the QUERY method (#5111)
* feat(cors): allow QUERY by default as a first-class method (#5115)
* feat(cache): add first-class support for QUERY requests (#5119)
* feat(cache): support QUERY requests
* fix(cache): report unavailable QUERY hashing
* fix(cache): include request method in cache keys
* docs(cache): show QUERY-compatible registration
* feat(jsx): add React-compatible overloads to useRef (#5063)
* feat(jsx): add React-compatible overloads to useRef
Adds overloads so that useRef returns a non-nullable ref when given a
non-null initial value, matching React's API.
- useRef<T>(initialValue: T): MutableRefObject<T>
- useRef<T>(initialValue: T | null): RefObject<T>
- useRef<T = undefined>(): MutableRefObject<T | undefined>
This is a type-only change; the runtime implementation is unchanged.
Closes #5056
* feat(jsx)!: align RefObject and useRef with React 19
- `RefObject<T>` now has non-null mutable `current`
- `MutableRefObject<T>` becomes a deprecated alias
- `useRef` overloads match React 19; zero-arg form removed in favor of
`useRef(undefined)`
- `createRef`, `forwardRef`, `useImperativeHandle` updated to use
`RefObject<T | null>` for nullable refs
BREAKING CHANGE: `RefObject<T>` was `{ current: T | null }`; nullable
refs should now be typed as `RefObject<T | null>`. `useRef()` with no
argument no longer type-checks; pass `undefined` explicitly.
* ci: apply automated fixes
* refactor(jsx): remove MutableRefObject alias
hono/jsx has never exposed MutableRefObject before, and React 19 marks
it as deprecated. Per PR discussion, drop the alias entirely instead of
keeping a deprecated re-export.
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
* feat(middleware): add method-not-allowed middleware (#5132)
* feat(middleware): add method-not-allowed
* test(middleware): cover method-not-allowed
* chore(exports): expose method-not-allowed
Resolve #4633
* feat(jwt,jwk): add a configurable WWW-Authenticate realm (#5141)
* feat(jwt): add a realm option and escape challenge values
The 401 challenge hardcoded `ctx.req.url` as the `realm`. RFC 6750 describes
realm as a stable, human-readable name for the protection space, so reflecting
the full URL produces a different realm for every path and query string.
bearer-auth already exposes a `realm` option; jwt had no equivalent and its
`unauthorizedResponse()` helper is private, leaving no way to override it.
`realm` and `error_description` are also interpolated into a quoted-string
without escaping, so a `"` in either truncates the header. Both are now escaped
the way bearer-auth does it.
The default is unchanged to stay backward compatible.
Refs #4989
* feat(jwk): add a realm option and escape challenge values
Mirrors the preceding jwt change; jwk carries an identical copy of
`unauthorizedResponse()` with the same hardcoded realm and unescaped
interpolation.
Refs #4989
* test(jwt,jwk): cover realm configuration and quote escaping
Asserts the configured realm reaches the WWW-Authenticate header for both the
missing-credentials and invalid-token paths, that embedded double quotes are
escaped, and that the default is still the request URL.
The realm and escaping cases fail without the preceding commits; the default
cases guard against regressing existing behavior.
* add a test
---------
Co-authored-by: Yusuke Wada <yusuke@kamawada.com>
* feat(utils/headers): add HTTP fields newly registered with IANA (#5153)
* fix(jsx): allow a function component to return an array (#5179)
* fix(jsx): allow a function component to return an array
A function component returning an array threw "str.search is not a
function" during server-side rendering. The return value did not match
any branch in JSXFunctionNode.toStringToBuffer() and fell through to
escapeToBuffer(), which expects a string.
Handle arrays with childrenToStringToBuffer(), the same path already
used for array children. JSX.ElementType is also added so that the
type layer accepts components returning any renderable value, matching
what hono/jsx/dom already supports at runtime.
* fix(jsx): accept an array return in the type layer
The runtime already renders a function component that returns an array,
but the type layer still rejected it. Add `Child[]` to the call
signature of `FC`, and define `JSX.ElementType` with the same return
type.
Without `JSX.ElementType`, TypeScript checks the return type against
`JSX.Element` and reports TS2786. Both types now accept exactly the same
set of return values, so nothing beyond arrays becomes newly valid.
* fix(jsx): render an array resolved from a promise
An async function component returning an array produced escaped,
comma-joined text instead of markup, because the resolved array reached
the string buffer as-is and was stringified by `String()`. Wrap a
resolved array in a fragment so it is rendered like any other node.
`Child` now carries `Promise<string | Child[]>`, which surfaced the same
hole for children: a child promise resolving to an array took the same
path. Both call sites share `resolveArrayToFragment()`, which also
attaches the suspended context, so the promise branch of
`JSXFunctionNode` no longer needs its own `then()` chain.
* fix(jsx): scope promised arrays to component results
* fix(jsx-renderer): accept array component results
* fix(jsx): preserve callbacks in component arrays
* refactor(jsx): remove obsolete suspended context state
---------
Co-authored-by: Taku Amano <taku@taaas.jp>
* feat(reg-exp-router): throw UnsupportedPathError during route registration (#5171)
* fix(reg-exp-router): make wildcard sibling order in the regexp deterministic
compareKey() was inconsistent when comparing the only wildcard with
the tail wildcard, so their order relied on the insertion order
normalized by the path-length sort in the matcher build.
* fix(reg-exp-router): capture params on a label node created by an unnamed wildcard
A param like /w/:id/y registered together with /w/*/x reused the label
node created by the unnamed wildcard, which has no var index assigned,
so the param value was lost.
* feat(reg-exp-router): throw UnsupportedPathError when adding routes
Insert paths into per-method tries incrementally in add() so that
unsupported path combinations are detected at registration time
instead of at the first match.
- Static paths are inserted as real nodes (character by character,
with no pattern interpretation), but branches without a dynamic
terminal are excluded from the regexp, so the generated matchers
stay identical to the previous implementation.
- Conflict checks no longer depend on the insertion order: wildcard
nodes coexist with anything, and a single-character pattern like
/:x{a} coexists with single-character literals.
- Node#insert is now a loop instead of recursion with array spreads,
making registration plus the first match roughly 20% faster.
* test(reg-exp-router): cover method-specific path validation
* fix(compress): set Vary: Accept-Encoding on negotiated responses (#5137)
* fix(compress): set Vary: Accept-Encoding on compressed responses
The compress middleware negotiates gzip/deflate from the request's
Accept-Encoding header but never advertises Vary: Accept-Encoding on the
response. A shared cache can then store the compressed body and serve it
to a client that did not send a compatible Accept-Encoding, breaking that
client. Add Accept-Encoding to the response's Vary header when compressing,
appending to any existing Vary value and avoiding duplicates.
* fix(compress): set Vary: Accept-Encoding on identity responses too
Move the Vary handling ahead of the encoding negotiation so that a response
left uncompressed — because Accept-Encoding was absent or offered nothing the
middleware supports — is also marked as varying on Accept-Encoding. RFC 9110
lists Accept-Encoding "or lack thereof" as a determining factor, so without
this a shared cache can reuse the identity response for a client that does
accept gzip.
The helper now takes the Context and writes through ctx.header(), which
recreates the response when a handler returned a fetch() response. On Node
that recreation inherits the immutable header guard from the original
response, so the write can still throw; fall back to rebuilding the response
around a fresh Headers instance in that case.
* refactored
* remove the node.js test
* ci: apply automated fixes
---------
Co-authored-by: Yusuke Wada <yusuke@kamawada.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
---------
Co-authored-by: Igor Savin <iselwin@gmail.com>
Co-authored-by: haki <165590443+shellhaki@users.noreply.github.com>
Co-authored-by: James Ross <james@jross.me>
Co-authored-by: Taku Amano <taku@taaas.jp>
Co-authored-by: asahi <166529527+ashunar0@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Arham Amin <132888838+arhxam@users.noreply.github.com>
Co-authored-by: Hiroki Akahoshi <64849251+akahoshi1421@users.noreply.github.com>
Co-authored-by: natsuki ueda <63272932+natsuki-engr@users.noreply.github.com>1 parent 734755a commit 61e165c
41 files changed
Lines changed: 2066 additions & 353 deletions
File tree
- benchmarks/fetch
- src
- client
- jsx
- dom
- intrinsic-element
- hooks
- intrinsic-element
- middleware
- cache
- compress
- cors
- etag
- jsx-renderer
- jwk
- jwt
- method-not-allowed
- router/reg-exp-router
- utils
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | | - | |
18 | | - | |
| 18 | + | |
| 19 | + | |
19 | 20 | | |
20 | | - | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
40 | 46 | | |
41 | 47 | | |
42 | 48 | | |
43 | 49 | | |
44 | 50 | | |
45 | 51 | | |
46 | 52 | | |
| 53 | + | |
| 54 | + | |
47 | 55 | | |
48 | 56 | | |
49 | 57 | | |
50 | | - | |
51 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
52 | 61 | | |
53 | 62 | | |
| 63 | + | |
| 64 | + | |
54 | 65 | | |
55 | 66 | | |
56 | 67 | | |
| |||
64 | 75 | | |
65 | 76 | | |
66 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
67 | 89 | | |
68 | 90 | | |
69 | 91 | | |
70 | 92 | | |
71 | 93 | | |
72 | 94 | | |
73 | 95 | | |
74 | | - | |
| 96 | + | |
| 97 | + | |
75 | 98 | | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
82 | 111 | | |
83 | 112 | | |
84 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
234 | 239 | | |
235 | 240 | | |
236 | 241 | | |
| |||
528 | 533 | | |
529 | 534 | | |
530 | 535 | | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
531 | 539 | | |
532 | 540 | | |
533 | 541 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
606 | 606 | | |
607 | 607 | | |
608 | 608 | | |
609 | | - | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
616 | | - | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
617 | 615 | | |
618 | 616 | | |
619 | 617 | | |
| |||
622 | 620 | | |
623 | 621 | | |
624 | 622 | | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
632 | 642 | | |
633 | 643 | | |
634 | 644 | | |
635 | 645 | | |
636 | 646 | | |
637 | 647 | | |
638 | | - | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
639 | 652 | | |
640 | 653 | | |
641 | 654 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| 110 | + | |
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
| |||
471 | 472 | | |
472 | 473 | | |
473 | 474 | | |
474 | | - | |
475 | | - | |
| 475 | + | |
| 476 | + | |
476 | 477 | | |
477 | 478 | | |
478 | 479 | | |
479 | 480 | | |
480 | 481 | | |
481 | | - | |
| 482 | + | |
482 | 483 | | |
483 | 484 | | |
484 | 485 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2079 | 2079 | | |
2080 | 2080 | | |
2081 | 2081 | | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
2082 | 2123 | | |
2083 | 2124 | | |
2084 | 2125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
28 | 33 | | |
29 | | - | |
| 34 | + | |
30 | 35 | | |
31 | 36 | | |
32 | 37 | | |
| |||
35 | 40 | | |
36 | 41 | | |
37 | 42 | | |
| 43 | + | |
38 | 44 | | |
39 | 45 | | |
40 | 46 | | |
| |||
105 | 111 | | |
106 | 112 | | |
107 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
108 | 135 | | |
109 | 136 | | |
110 | 137 | | |
| |||
114 | 141 | | |
115 | 142 | | |
116 | 143 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 144 | + | |
121 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
122 | 153 | | |
123 | 154 | | |
124 | 155 | | |
| |||
143 | 174 | | |
144 | 175 | | |
145 | 176 | | |
146 | | - | |
147 | 177 | | |
148 | 178 | | |
149 | 179 | | |
| |||
173 | 203 | | |
174 | 204 | | |
175 | 205 | | |
176 | | - | |
| 206 | + | |
177 | 207 | | |
178 | 208 | | |
179 | 209 | | |
| |||
267 | 297 | | |
268 | 298 | | |
269 | 299 | | |
270 | | - | |
| 300 | + | |
271 | 301 | | |
272 | 302 | | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
| 303 | + | |
283 | 304 | | |
284 | 305 | | |
285 | 306 | | |
| 307 | + | |
| 308 | + | |
286 | 309 | | |
287 | 310 | | |
288 | 311 | | |
| |||
0 commit comments