Browse Source

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.
v0.11.15-release
Jackson Tian 10 years ago
committed by Julien Gilli
parent
commit
9653c4b8c7
  1. 19
      doc/api/http.markdown

19
doc/api/http.markdown

@ -389,7 +389,7 @@ Example:
response.removeHeader("Content-Encoding"); response.removeHeader("Content-Encoding");
### response.write(chunk[, encoding]) ### response.write(chunk[, encoding][, callback])
If this method is called and [response.writeHead()][] has not been called, If this method is called and [response.writeHead()][] has not been called,
it will switch to implicit header mode and flush the implicit headers. 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.
`chunk` can be a string or a buffer. If `chunk` is a string, `chunk` can be a string or a buffer. If `chunk` is a string,
the second parameter specifies how to encode it into a byte stream. the second parameter specifies how to encode it into a byte stream.
By default the `encoding` is `'utf8'`. By default the `encoding` is `'utf8'`. The last parameter `callback`
will be called when this chunk of data is flushed.
**Note**: This is the raw HTTP body and has nothing to do with **Note**: This is the raw HTTP body and has nothing to do with
higher-level multi-part body encodings that may be used. 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.,
response.end(); response.end();
### response.end([data][, encoding]) ### response.end([data][, encoding][, callback])
This method signals to the server that all of the response headers and body This method signals to the server that all of the response headers and body
have been sent; that server should consider this message complete. have been sent; that server should consider this message complete.
The method, `response.end()`, MUST be called on each The method, `response.end()`, MUST be called on each
response. response.
If `data` is specified, it is equivalent to calling `response.write(data, encoding)` If `data` is specified, it is equivalent to calling
followed by `response.end()`. `response.write(data, encoding)` followed by `response.end(callback)`.
## http.request(options[, callback]) ## 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
data isn't sent until possibly much later. `request.flush()` lets you bypass data isn't sent until possibly much later. `request.flush()` lets you bypass
the optimization and kickstart the request. the optimization and kickstart the request.
### request.write(chunk[, encoding]) ### request.write(chunk[, encoding][, callback])
Sends a chunk of the body. By calling this method Sends a chunk of the body. By calling this method
many times, the user can stream a request body to a 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.
The `encoding` argument is optional and only applies when `chunk` is a string. The `encoding` argument is optional and only applies when `chunk` is a string.
Defaults to `'utf8'`. Defaults to `'utf8'`.
The `callback` argument is optional and will be called when this chunk of data
is flushed.
### request.end([data][, encoding]) ### request.end([data][, encoding][, callback])
Finishes sending the request. If any parts of the body are Finishes sending the request. If any parts of the body are
unsent, it will flush them to the stream. If the request is unsent, it will flush them to the stream. If the request is
chunked, this will send the terminating `'0\r\n\r\n'`. chunked, this will send the terminating `'0\r\n\r\n'`.
If `data` is specified, it is equivalent to calling If `data` is specified, it is equivalent to calling
`request.write(data, encoding)` followed by `request.end()`. `request.write(data, encoding)` followed by `request.end(callback)`.
### request.abort() ### request.abort()

Loading…
Cancel
Save