fulmine.js 5.19.5 → 5.19.6

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.19.5",
3
+ "version": "5.19.6",
4
4
  "description": "Drop-in Express 5 replacement on uWebSockets.js. Your existing middleware keeps working.",
5
5
  "main": "src/index.js",
6
6
  "exports": {
@@ -1082,8 +1082,11 @@ function createBodyParser(defaultType, beforeReturn, checkOptions, charsetPolicy
1082
1082
  return beforeReturn(req, res, next, options, empty, encoding);
1083
1083
  }
1084
1084
 
1085
- // skip reading too large body; NaN compares false, so no declared length passes
1086
- if (lengthNumber > limit) {
1085
+ // skip reading too large body; NaN compares false, so no declared length passes.
1086
+ // Not while inflating: content-length counts the compressed bytes and the limit is
1087
+ // about the ones that come out, which body-parser says by leaving the length unset.
1088
+ // The limit is still enforced per chunk as they inflate, see keepChunk
1089
+ if (!inflate && lengthNumber > limit) {
1087
1090
  return next(
1088
1091
  bodyError("request entity too large", 413, "entity.too.large", {
1089
1092
  expected: lengthNumber,
package/src/response.js CHANGED
@@ -76,6 +76,12 @@ function invalidChunkError(chunk) {
76
76
  `The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received ${received}`
77
77
  );
78
78
  err.code = "ERR_INVALID_ARG_TYPE";
79
+ // node stamps the code into the stack's first line and then puts the name back, so err.name
80
+ // reads TypeError while the error page, which prints the stack, shows the bracketed form
81
+ err.name = "TypeError [ERR_INVALID_ARG_TYPE]";
82
+ void err.stack;
83
+ // through the index signature: name is not optional on Error, so a plain delete is a type error
84
+ delete (/** @type {Record<string, unknown>} */ (/** @type {unknown} */ (err)).name);
79
85
  return err;
80
86
  }
81
87
  const { sign } = require("cookie-signature");
@@ -842,6 +848,25 @@ module.exports = class Response extends LazyWritable {
842
848
  * @returns {this}
843
849
  */
844
850
  send(body) {
851
+ // undefined means nothing was passed, and Express treats that differently from a value
852
+ // that happens to be empty: no content-type and no ETag for send(), both for send(null)
853
+ // and send(""). It writes no header for it either, so it does not refuse a head that has
854
+ // gone out: after a res.write(), express answers this and we hung up on it.
855
+ if (body === undefined) {
856
+ if (!this.headersSent) {
857
+ // freshness and the bodiless statuses, as every express send goes through: a 204
858
+ // answered with json(undefined) loses the type json had set
859
+ if (this.req.fresh) {
860
+ this.status(304);
861
+ }
862
+ if (this.statusCode === 204 || this.statusCode === 304) {
863
+ delete this.headers["content-type"];
864
+ delete this.headers["content-length"];
865
+ delete this.headers["transfer-encoding"];
866
+ }
867
+ }
868
+ return this.end("");
869
+ }
845
870
  if (this.headersSent) {
846
871
  // what express's send meets first once the head is out is setHeader's refusal
847
872
  throw headersSentError("set");
@@ -854,22 +879,6 @@ module.exports = class Response extends LazyWritable {
854
879
  body = Buffer.from(body.buffer, body.byteOffset, body.byteLength);
855
880
  }
856
881
  const isBuffer = Buffer.isBuffer(body);
857
- // undefined means nothing was passed, and Express treats that differently from a value
858
- // that happens to be empty: no content-type and no ETag for send(), both for send(null)
859
- // and send("").
860
- if (body === undefined) {
861
- // still through freshness and the bodiless statuses, as every express send is: a 204
862
- // answered with json(undefined) loses the type json had set
863
- if (this.req.fresh) {
864
- this.status(304);
865
- }
866
- if (this.statusCode === 204 || this.statusCode === 304) {
867
- delete this.headers["content-type"];
868
- delete this.headers["content-length"];
869
- delete this.headers["transfer-encoding"];
870
- }
871
- return this.end("");
872
- }
873
882
  // null is an object as far as Express's switch is concerned, so it becomes the empty
874
883
  // string without ever reaching the branch that gives a string its content-type. It still
875
884
  // earns an ETag. send("") takes the string branch and does get one.