0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

More node.http.Client docs

This commit is contained in:
Ryan 2009-05-20 16:02:53 +02:00
parent 6a582a4d9a
commit 691467670d
2 changed files with 97 additions and 7 deletions

View File

@ -17,6 +17,8 @@ body {
top: 2em;
left: 0;
width: 10em;
font-size: 14pt;
line-height: 120%;
}
#toc ol {
list-style: none;
@ -28,7 +30,7 @@ body {
margin: 0;
padding: 0;
}
#toc a { color: #777; }
#toc a { color: #aaa; }
h1, h2, h3, h4 {
color: #B0C4DE;
@ -84,12 +86,22 @@ a:hover { text-decoration: underline; }
<li><a href="#timers">Timers</a>
<li><a href="#files">File System I/O</a>
<li><a href="#tcp">TCP</a>
<ol>
<li><a href="#tcp_server">Server</a>
<li><a href="#tcp_connection">Connection</a>
</ol>
<li><a href="#http">HTTP</a>
<ol>
<li><a href="#http_server">Server</a>
<li><a href="#http_server_request">ServerRequest</a>
<li><a href="#http_server_response">ServerResponse</a>
<ol>
<li><a href="#http_server_request">Request</a>
<li><a href="#http_server_response">Response</a>
</ol>
<li><a href="#http_client">Client</a>
<ol>
<li><a href="#http_client_request">Request</a>
<li><a href="#http_client_response">Response</a>
</ol>
</ol>
<li><a href="#modules">Modules</a>
</ol>
@ -119,7 +131,7 @@ puts("Server running at http://127.0.0.1:8000/");</pre>
Node is an evented sandbox where users cannot execute blocking I/O.
This is
already natural for Javascript programmers, as the DOM is almost entirely
asynchronous and allows for effieceny. The goal is to provide an easy way to create
asynchronous. The goal is to provide an easy way to create
efficient network applications.
@ -146,7 +158,7 @@ make
make install</pre>
<h2 id="api">Application Programming Interface</h2>
<h2 id="api">API</h2>
<p>Conventions: Callbacks are object members which are prefixed with
<code class="sh_javascript">on</code>. All methods and members are camel cased. Constructors
@ -279,7 +291,6 @@ req.onBody = function (chunk) {
<dd>
Set the encoding for the request body. Either <code class="sh_javascript">"utf8"</code> or
<code class="sh_javascript">"raw"</code>. Defaults to raw.
<big>TODO</big>
</dl>
<h4 id="http_server_response"><code class="sh_javascript">node.http.ServerResponse</code></h4>
@ -366,6 +377,84 @@ normally are without bodies but HTTP does not forbid it, so neither do we.)
</dl>
<h4 id="http_client_request"><code class="sh_javascript">node.http.ClientRequest</code></h4>
<p>This object created internally and returned from the request methods of a
<code>node.http.Client</code>. It represents an <i>in-progress</i> request
whose header has already been sent.
<dl>
<dt><code class="sh_javascript">req.sendBody(chunk, encoding)</code></dt>
<dd> Sends a sucessive peice of the body. By calling this method many times,
the user can stream a request body to a server&mdash;in that case it is
suggested to use the <code class="sh_javascript">["Transfer-Encoding",
"chunked"]</code> header line when creating the request.
<p>The <code>chunk</code> argument should be an array of integers or a string.
<p>The <code>encoding</code> argument is optional and only applies when
<code>chunk</code> is a string. The encoding argument should be either
<code>"utf8"</code> or <code>"ascii"</code>. By default the body uses ASCII
encoding, as it is faster.
<p> TODO
<dt><code class="sh_javascript">req.finish(response_handler)</code></dt>
<dd> 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 <code class="sh_javascript">"0\r\n\r\n"</code>.
<p>The parameter <code>response_handler</code> is a user-supplied callback which will
be executed exactly once when the server response headers have been received.
The <code>response_handler</code> callback is executed with one argument: a
<code>ClientResponse</code> object.
</dl>
<h4 id="http_client_response"><code class="sh_javascript">node.http.ClientResponse</code></h4>
<p>This object is created internally and passed to the
<code>response_handler</code> callback (is given to the client in
<code>req.finish</code> function). The response object appears exactly as the
header is completely received but before any part of the response body has been
read.
<dl>
<dt><code class="sh_javascript">res.status_code</code></dt>
<dd>The 3-digit HTTP response status code. (E.G. <code class="sh_javascript">404</code>.)</dd>
<dt><code class="sh_javascript">res.http_version</code></dt>
<dd>The HTTP version of the connected-to server. Probably either
<code class="sh_javascript">"1.1"</code> or
<code class="sh_javascript">"1.0"</code>.
</dd>
<dt><code class="sh_javascript">res.headers</code></dt>
<dd>The response headers. An Array of 2-element arrays.</dd>
<dt><code class="sh_javascript">res.onBody</code></dt>
<dd>Callback. Should be set by the user to be informed of when a piece
of the message body is received.
A chunk of the body is given as the single argument. The transfer-encoding
has been removed.
<p>The body chunk is either a <code>String</code> in the case of UTF-8
encoding or an array of numbers in the case of raw encoding. The body
encoding is set with <code class="sh_javascript">res.setBodyEncoding()</code>.
<dt><code class="sh_javascript">res.onBodyComplete</code></dt>
<dd>Callback. Made exactly once for each message. No arguments. After
<code class="sh_javascript">onBodyComplete</code> is executed
<code class="sh_javascript">onBody</code> will no longer be called.
</dd>
<dt><code class="sh_javascript">res.setBodyEncoding(encoding)</code></dt>
<dd>
Set the encoding for the response body. Either <code class="sh_javascript">"utf8"</code> or
<code class="sh_javascript">"raw"</code>. Defaults to raw.
</dd>
</dl>
<h3 id="modules">Modules</h3>
<p>Node has a simple module loading system. In Node, files and modules are

View File

@ -12,7 +12,8 @@
font-style: italic;
}
.sh_sourceCode .sh_string, .sh_sourceCode .sh_regexp, .sh_sourceCode .sh_number
.sh_sourceCode .sh_string, .sh_sourceCode .sh_regexp, .sh_sourceCode .sh_number,
.sh_sourceCode .sh_specialchar
{
color: #B0C4DE;
}