Skip to content
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

doc: improve documentation for consuming request body #5771

Merged
merged 3 commits into from
May 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions std/http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,9 @@ export class ServerRequest {
private _body: Deno.Reader | null = null;

/**
* Body of the request.
* Body of the request. The easiest way to consume the body is:
*
* const buf = new Uint8Array(req.contentLength);
* let bufSlice = buf;
* let totRead = 0;
* while (true) {
* const nread = await req.body.read(bufSlice);
* if (nread === null) break;
* totRead += nread;
* if (totRead >= req.contentLength) break;
* bufSlice = bufSlice.subarray(nread);
* }
* const buf: Uint8Array = await Deno.readAll(req.body);
*/
get body(): Deno.Reader {
if (!this._body) {
Expand Down