-
Notifications
You must be signed in to change notification settings - Fork 581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Method to indicate thar request has body #1095
Comments
Can check |
Data can be chunked, without known content length. |
hasBody is a good addition |
const hasBody = req => Number(req.getHeader('content-length')) || req.getHeader('transfer-encoding').includes('chunked'); |
yes, this will work |
The client can send 0 bytes !!+req.getHeader('content-length') |
@uasan yes '0' string needs to be properly accounted for, I fixed the function |
req.getHeader('transfer-encoding')?.includes('chunked') |
req.getHeader('transfer-encoding')?.toLowerCase().includes('chunked') |
Obviously this should be hasBody() as we already do standards compliant check for this internally. So it's just setting a boolean and returning it via hasBody() |
Usually you want to differentiate between standard request uploads with a 'content-length' and potentially unlimited stream of data with 'transfer-encoding: chunked', a simple hasBody would not help with that, encourages bad practice I think, maybe some people need it for something ? const contentLength = Number(req.getHeader('content-length'));
const transferEncoding = req.getHeader('transfer-encoding');
if (contentLength) {
const body = await getBody(res);
} else if (transferEncoding.includes('chunked')) {
await processStream(res);
} else {
console.log('no body');
}
res.end('done'); |
Fot me |
bodyType() could return 0 for false, 1 for fix length, 2 for stream. The parser already knows all of this |
With a fixed body length, it is very useful to know it in advance, then it will be better like this: req.getBodyLength(): 0 | number | Infinity |
Agree, knowing the fixed length can help decide buffer size |
Will you add this method to the uws or lets close this issue? |
Is it possible to add method
hasBody()
, which will returntrue
if request has body, in order to understand that we need to read it usingonData
.The text was updated successfully, but these errors were encountered: