Skip to content
Myr

Merge commit from fork

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Yusuke Wada · committed by GitHub · parent 6792789 · Browse files · 2 files+81 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+81 added−3 removed

  • tests:+68 added−0 removed
  • other:+13 added−3 removed

2 files+81 added−3 removed

modified:src/middleware/body-limit/index.test.ts+68 added
modified:src/middleware/body-limit/index.ts+13 added-3 removed
69 unmodified lines
70 // maybe GET or HEAD request71 return next()72 }7374 if (c.req.raw.headers.has('content-length')) {75 // we can trust content-length header because it's already validated by server74 const hasTransferEncoding = c.req.raw.headers.has('transfer-encoding')75 const hasContentLength = c.req.raw.headers.has('content-length')7677 // RFC 7230: If both Transfer-Encoding and Content-Length are present,78 // Transfer-Encoding takes precedence and Content-Length should be ignored79 if (hasTransferEncoding && hasContentLength) {80 // Both headers present - follow RFC 7230 and ignore Content-Length81 // This might indicate request smuggling attempt82 }8384 if (hasContentLength && !hasTransferEncoding) {85 // Only Content-Length present - we can trust it86 const contentLength = parseInt(c.req.raw.headers.get('content-length') || '0', 10)87 return contentLength > maxSize ? onError(c) : next()88 }8980 // maybe chunked transfer encoding90 // Transfer-Encoding present (chunked) or no length headers9192 let size = 093 const rawReader = c.req.raw.body.getReader()94 const reader = new ReadableStream({
31 unmodified lines