Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
doc: mention callback for http res/req write & end
Browse files Browse the repository at this point in the history
Add documentation for the callback parameter of http.ClientRequest's and
http.ServerResponse's write and end methods.
  • Loading branch information
JacksonTian authored and Julien Gilli committed Dec 5, 2014
1 parent fe6d5be commit 9653c4b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions doc/api/http.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ Example:
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,
it will switch to implicit header mode and flush the implicit headers.
Expand All @@ -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,
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
higher-level multi-part body encodings that may be used.
Expand Down Expand Up @@ -433,15 +434,15 @@ emit trailers, with a list of the header fields in its value. E.g.,
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
have been sent; that server should consider this message complete.
The method, `response.end()`, MUST be called on each
response.

If `data` is specified, it is equivalent to calling `response.write(data, encoding)`
followed by `response.end()`.
If `data` is specified, it is equivalent to calling
`response.write(data, encoding)` followed by `response.end(callback)`.

This comment has been minimized.

Copy link
@ronkorving

ronkorving Dec 8, 2014

Callback here is not mentioned as optional.

This comment has been minimized.

Copy link
@misterdjules

misterdjules Dec 8, 2014

@ronkorving The way [, callback] is mentioned in the list of parameters should make it clear that it's optional.

However, callback itself is not described properly in my opinion. It should at least say how and when it's called. That's something I should have caught in my previous review, sorry for that. @JacksonTian @ronkorving Would you have some time to fix that in another PR?

This comment has been minimized.

Copy link
@JacksonTian

JacksonTian via email Dec 8, 2014

Author

This comment has been minimized.

Copy link
@misterdjules

misterdjules Dec 8, 2014

@JacksonTian Yes, and same for request.end.

This comment has been minimized.

Copy link
@JacksonTian

JacksonTian via email Dec 9, 2014

Author


## http.request(options[, callback])
Expand Down Expand Up @@ -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
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
many times, the user can stream a request body to a
Expand All @@ -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.
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
unsent, it will flush them to the stream. If the request is
chunked, this will send the terminating `'0\r\n\r\n'`.

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)`.

This comment has been minimized.

Copy link
@ronkorving

ronkorving Dec 8, 2014

Same here

This comment has been minimized.

Copy link
@misterdjules

misterdjules Dec 8, 2014

See my response above.

Thanks @ronkorving!


### request.abort()

Expand Down

0 comments on commit 9653c4b

Please sign in to comment.