Skip to content

Commit 6f31a37

Browse files
committed
Add more explanation to docs for request.finish().
1 parent b54fad9 commit 6f31a37

File tree

3 files changed

+94
-12
lines changed

3 files changed

+94
-12
lines changed

doc/api.html

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,18 +1319,42 @@ <h4 id="_tt_node_http_clientrequest_tt"><tt>node.http.ClientRequest</tt></h4>
13191319
as it is faster.</p></div>
13201320
</dd>
13211321
<dt class="hdlist1">
1322-
<tt>request.finish(response_listener)</tt>
1322+
<tt>request.finish(responseListener)</tt>
13231323
</dt>
13241324
<dd>
13251325
<p>
13261326
Finishes sending the request. If any parts of the body are
13271327
unsent, it will flush them to the socket. If the request is
13281328
chunked, this will send the terminating <tt>"0\r\n\r\n"</tt>.
13291329
</p>
1330-
<div class="paragraph"><p>The parameter <tt>response_listener</tt> is a callback which
1330+
<div class="paragraph"><p>The parameter <tt>responseListener</tt> is a callback which
13311331
will be executed when the response headers have been received.
1332-
The <tt>response_listener</tt> callback is executed with one
1332+
The <tt>responseListener</tt> callback is executed with one
13331333
argument which is an instance of <tt>node.http.ClientResponse</tt>.</p></div>
1334+
<div class="paragraph"><p>In the <tt>responseListener</tt> callback, one can add more listeners to the
1335+
response, in particular listening for the <tt>"body"</tt> event. Note that
1336+
the <tt>responseListener</tt> is called before any part of the body is receieved,
1337+
so there is no need to worry about racing to catch the first part of the
1338+
body. As long as a listener for <tt>"body"</tt> is added during the
1339+
<tt>responseListener</tt> callback, the entire body will be caught.</p></div>
1340+
<div class="listingblock">
1341+
<div class="content">
1342+
<pre><tt>// Good
1343+
request.finish(function (response) {
1344+
response.addListener("body", function (chunk) {
1345+
puts("BODY: " + chunk);
1346+
});
1347+
});
1348+
1349+
// Bad - misses all or part of the body
1350+
request.finish(function (response) {
1351+
setTimeout(function () {
1352+
response.addListener("body", function (chunk) {
1353+
puts("BODY: " + chunk);
1354+
});
1355+
}, 10);
1356+
});</tt></pre>
1357+
</div></div>
13341358
</dd>
13351359
</dl></div>
13361360
<h4 id="_tt_node_http_clientresponse_tt"><tt>node.http.ClientResponse</tt></h4>
@@ -1906,7 +1930,7 @@ <h2 id="_extension_api">Extension API</h2>
19061930
<div id="footer">
19071931
<div id="footer-text">
19081932
Version 0.1.10<br />
1909-
Last updated 2009-09-15 22:34:24 CEST
1933+
Last updated 2009-09-17 15:13:13 CEST
19101934
</div>
19111935
</div>
19121936
</body>

doc/api.txt

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -845,16 +845,42 @@ argument should be either +"utf8"+ or
845845
as it is faster.
846846

847847

848-
+request.finish(response_listener)+ ::
848+
+request.finish(responseListener)+ ::
849849

850850
Finishes sending the request. If any parts of the body are
851851
unsent, it will flush them to the socket. If the request is
852852
chunked, this will send the terminating +"0\r\n\r\n"+.
853853
+
854-
The parameter +response_listener+ is a callback which
854+
The parameter +responseListener+ is a callback which
855855
will be executed when the response headers have been received.
856-
The +response_listener+ callback is executed with one
856+
The +responseListener+ callback is executed with one
857857
argument which is an instance of +node.http.ClientResponse+.
858+
+
859+
In the +responseListener+ callback, one can add more listeners to the
860+
response, in particular listening for the +"body"+ event. Note that
861+
the +responseListener+ is called before any part of the body is receieved,
862+
so there is no need to worry about racing to catch the first part of the
863+
body. As long as a listener for +"body"+ is added during the
864+
+responseListener+ callback, the entire body will be caught.
865+
+
866+
----------------------------------------
867+
// Good
868+
request.finish(function (response) {
869+
response.addListener("body", function (chunk) {
870+
puts("BODY: " + chunk);
871+
});
872+
});
873+
874+
// Bad - misses all or part of the body
875+
request.finish(function (response) {
876+
setTimeout(function () {
877+
response.addListener("body", function (chunk) {
878+
puts("BODY: " + chunk);
879+
});
880+
}, 10);
881+
});
882+
----------------------------------------
883+
858884

859885

860886

doc/node.1

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
.\" Title: node
22
.\" Author:
33
.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
4-
.\" Date: 09/15/2009
4+
.\" Date: 09/17/2009
55
.\" Manual:
66
.\" Source:
77
.\"
8-
.TH "NODE" "1" "09/15/2009" "" ""
8+
.TH "NODE" "1" "09/17/2009" "" ""
99
.\" disable hyphenation
1010
.nh
1111
.\" disable justification (adjust text to left margin only)
@@ -1226,17 +1226,49 @@ or
12261226
"ascii"\. By default the body uses ASCII encoding, as it is faster\.
12271227
.RE
12281228
.PP
1229-
request\.finish(response_listener)
1229+
request\.finish(responseListener)
12301230
.RS 4
12311231
Finishes sending the request\. If any parts of the body are unsent, it will flush them to the socket\. If the request is chunked, this will send the terminating
12321232
"0\er\en\er\en"\.
12331233
.sp
12341234
The parameter
1235-
response_listener
1235+
responseListener
12361236
is a callback which will be executed when the response headers have been received\. The
1237-
response_listener
1237+
responseListener
12381238
callback is executed with one argument which is an instance of
12391239
node\.http\.ClientResponse\.
1240+
.sp
1241+
In the
1242+
responseListener
1243+
callback, one can add more listeners to the response, in particular listening for the
1244+
"body"
1245+
event\. Note that the
1246+
responseListener
1247+
is called before any part of the body is receieved, so there is no need to worry about racing to catch the first part of the body\. As long as a listener for
1248+
"body"
1249+
is added during the
1250+
responseListener
1251+
callback, the entire body will be caught\.
1252+
.sp
1253+
.RS 4
1254+
.nf
1255+
// Good
1256+
request\.finish(function (response) {
1257+
response\.addListener("body", function (chunk) {
1258+
puts("BODY: " + chunk);
1259+
});
1260+
});
1261+
1262+
// Bad \- misses all or part of the body
1263+
request\.finish(function (response) {
1264+
setTimeout(function () {
1265+
response\.addListener("body", function (chunk) {
1266+
puts("BODY: " + chunk);
1267+
});
1268+
}, 10);
1269+
});
1270+
.fi
1271+
.RE
12401272
.RE
12411273
.RE
12421274
.sp

0 commit comments

Comments
 (0)