Skip to content

Commit 9653c4b

Browse files
JacksonTianJulien Gilli
authored and
Julien Gilli
committed
doc: mention callback for http res/req write & end
Add documentation for the callback parameter of http.ClientRequest's and http.ServerResponse's write and end methods.
1 parent fe6d5be commit 9653c4b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

doc/api/http.markdown

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ Example:
389389
response.removeHeader("Content-Encoding");
390390

391391

392-
### response.write(chunk[, encoding])
392+
### response.write(chunk[, encoding][, callback])
393393

394394
If this method is called and [response.writeHead()][] has not been called,
395395
it will switch to implicit header mode and flush the implicit headers.
@@ -399,7 +399,8 @@ be called multiple times to provide successive parts of the body.
399399

400400
`chunk` can be a string or a buffer. If `chunk` is a string,
401401
the second parameter specifies how to encode it into a byte stream.
402-
By default the `encoding` is `'utf8'`.
402+
By default the `encoding` is `'utf8'`. The last parameter `callback`
403+
will be called when this chunk of data is flushed.
403404

404405
**Note**: This is the raw HTTP body and has nothing to do with
405406
higher-level multi-part body encodings that may be used.
@@ -433,15 +434,15 @@ emit trailers, with a list of the header fields in its value. E.g.,
433434
response.end();
434435

435436

436-
### response.end([data][, encoding])
437+
### response.end([data][, encoding][, callback])
437438

438439
This method signals to the server that all of the response headers and body
439440
have been sent; that server should consider this message complete.
440441
The method, `response.end()`, MUST be called on each
441442
response.
442443

443-
If `data` is specified, it is equivalent to calling `response.write(data, encoding)`
444-
followed by `response.end()`.
444+
If `data` is specified, it is equivalent to calling
445+
`response.write(data, encoding)` followed by `response.end(callback)`.
445446

446447

447448
## http.request(options[, callback])
@@ -864,7 +865,7 @@ That's usually what you want (it saves a TCP round-trip) but not when the first
864865
data isn't sent until possibly much later. `request.flush()` lets you bypass
865866
the optimization and kickstart the request.
866867

867-
### request.write(chunk[, encoding])
868+
### request.write(chunk[, encoding][, callback])
868869

869870
Sends a chunk of the body. By calling this method
870871
many times, the user can stream a request body to a
@@ -877,15 +878,17 @@ The `chunk` argument should be a [Buffer][] or a string.
877878
The `encoding` argument is optional and only applies when `chunk` is a string.
878879
Defaults to `'utf8'`.
879880

881+
The `callback` argument is optional and will be called when this chunk of data
882+
is flushed.
880883

881-
### request.end([data][, encoding])
884+
### request.end([data][, encoding][, callback])
882885

883886
Finishes sending the request. If any parts of the body are
884887
unsent, it will flush them to the stream. If the request is
885888
chunked, this will send the terminating `'0\r\n\r\n'`.
886889

887890
If `data` is specified, it is equivalent to calling
888-
`request.write(data, encoding)` followed by `request.end()`.
891+
`request.write(data, encoding)` followed by `request.end(callback)`.
889892

890893
### request.abort()
891894

0 commit comments

Comments
 (0)