fulmine.js 5.20.0 → 5.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fulmine.js",
3
- "version": "5.20.0",
3
+ "version": "5.21.0",
4
4
  "description": "Drop-in Express 5 replacement on uWebSockets.js, up to 20x faster. Same API, your middleware and framework keep working.",
5
5
  "main": "src/index.js",
6
6
  "exports": {
package/src/cli.js CHANGED
@@ -107,10 +107,11 @@ const DIFFERENCES = [
107
107
  [
108
108
  "a compiled route keeps its connection header",
109
109
  "A handler simple enough to be read at registration time is answered natively, and a client\n" +
110
- "that sent Connection: close is still told keep-alive, though the socket does close. A body\n" +
111
- "with a piece of the query in it is framed chunked, since its length is not known until the\n" +
112
- "request arrives. A response that would carry a validator is never compiled, so conditional\n" +
113
- 'requests behave as on Express. app.set("declarative responses", false) turns it off.'
110
+ "that sent Connection: close is still told keep-alive, though the socket does close. A\n" +
111
+ "response that would carry a validator is never compiled, so conditional requests behave as\n" +
112
+ 'on Express. app.set("declarative responses", false) turns it off. A body with a piece of\n' +
113
+ 'the query or a route parameter in it is compiled only under app.set("declarative request\n' +
114
+ 'values", true), which takes the value as uWS reads it: undecoded, the first one, or none.'
114
115
  ],
115
116
  [
116
117
  "headers are capped at 4096 bytes by default",
@@ -818,6 +818,12 @@ module.exports = function compileDeclarative(cb, app) {
818
818
  }
819
819
  const { sendUsed, bodyFromSend } = read;
820
820
 
821
+ // a part copied out of the request is written by uWS with its own reading of it, so the
822
+ // route is compiled only where the application asked for that
823
+ if (!app.get("declarative request values") && body.some((part) => part.type !== "text")) {
824
+ return false;
825
+ }
826
+
821
827
  // a handler that never sends is not a response: Express leaves the request waiting, so this
822
828
  // has to fall back instead of answering a bare 200
823
829
  if (!sendUsed && !sendStatusUsed) {
package/src/optimizer.js CHANGED
@@ -558,8 +558,9 @@ function registerUwsRoute(router, route, optimizedPath) {
558
558
  route.paramCallbacks.size === 0 && // a param callback has to run, and this answers without running anything
559
559
  // a captured value is decoded when the route runs, and one that cannot be decoded is a
560
560
  // 400 in express and on the ordinary path here. Nothing runs to raise it on a
561
- // declarative response, so GET /a-b%5Ec@d%e came back 200 from app.get("/:p12")
562
- route.optimizedParams === undefined &&
561
+ // declarative response, so GET /a-b%5Ec@d%e came back 200 from app.get("/:p12").
562
+ // "declarative request values" is the application accepting that
563
+ (route.optimizedParams === undefined || router.get("declarative request values")) &&
563
564
  // a declarative response is answered by µWS itself, so no javascript runs and the case
564
565
  // guard could not: a route that needs one has to stay an ordinary handler
565
566
  caseGuards === null &&
package/src/testing.js CHANGED
@@ -187,8 +187,11 @@ function whyNotCompiled(app, entry) {
187
187
  if (!app.get("declarative responses")) {
188
188
  return "answered by µWS, but declarative responses are turned off";
189
189
  }
190
- if (entry.path.includes(":")) {
191
- return "answered by µWS, but the route captures, and nothing runs to decode the value";
190
+ if (entry.path.includes(":") && !app.get("declarative request values")) {
191
+ return (
192
+ "answered by µWS, but the route captures, and nothing runs to decode the value: " +
193
+ 'app.set("declarative request values", true) is what puts a route here'
194
+ );
192
195
  }
193
196
  if (app.get("etag")) {
194
197
  return (
package/src/utils.js CHANGED
@@ -1028,6 +1028,11 @@ const defaultSettings = {
1028
1028
  // The native µWS router matches bytes, so the compiler in _compileOptimizedRoutes only hands
1029
1029
  // it routes whose earlier siblings it can prove agree under either case rule.
1030
1030
  "declarative responses": true,
1031
+ // off: a compiled body copies nothing out of the request. On, res.send(req.query.q) and
1032
+ // res.send(req.params.id) compile too, written by uWS as it reads them and not as Express
1033
+ // does: a query key repeated or missing gives the first value or nothing, a route parameter
1034
+ // goes out undecoded, and one that Express refuses with a 400 is answered
1035
+ "declarative request values": false,
1031
1036
  // on. Off hands every request to the ordinary chain instead of letting uWS match what it can,
1032
1037
  // which is slower and answers the same. Not a tuning knob: it exists so one application can be
1033
1038
  // served both ways and the answers compared, see `npm run fuzz -- --self`. A compiled response