+libDir = node.path.join(node.path.dirname(__filename), "../lib");
+node.libraryPaths.unshift(libDir);
+
+include("/utils.js");
+http = require("/http.js");
+
fixed = ""
for (var i = 0; i < 20*1024; i++) {
fixed += "C";
}
stored = {};
-node.http.createServer(function (req, res) {
+http.createServer(function (req, res) {
var commands = req.uri.path.split("/");
var command = commands[1];
var body = "";
+libDir = node.path.join(node.path.dirname(__filename), "../lib");
+node.libraryPaths.unshift(libDir);
+include("/utils.js");
function next (i) {
if (i <= 0) return;
+libDir = node.path.join(node.path.dirname(__filename), "../lib");
+node.libraryPaths.unshift(libDir);
+include("/utils.js");
var benchmarks = [ "static_http_server.js"
, "timers.js"
, "process_loop.js"
+libDir = node.path.join(node.path.dirname(__filename), "../lib");
+node.libraryPaths.unshift(libDir);
+http = require("/http.js");
var concurrency = 30;
var port = 8000;
var n = 700;
body += "C";
}
-var server = node.http.createServer(function (req, res) {
+var server = http.createServer(function (req, res) {
res.sendHeader(200, {
"Content-Type": "text/plain",
"Content-Length": body.length
}
for (var i = 0; i < concurrency; i++) {
- var client = node.http.createClient(port);
+ var client = http.createClient(port);
client.id = i;
client.get("/").finish(responseListener);
requests++;
<div class="listingblock">\r
<div class="content">\r
<pre><tt>include("/utils.js");\r
-node.http.createServer(function (request, response) {\r
+include("/http.js");\r
+createServer(function (request, response) {\r
response.sendHeader(200, {"Content-Type": "text/plain"});\r
response.sendBody("Hello World\n");\r
response.finish();\r
</dd>\r
</dl></div>\r
<h3 id="_http">HTTP</h3><div style="clear:left"></div>\r
+<div class="paragraph"><p>To use the HTTP server and client one must <tt>require("/http.js")</tt> or\r
+<tt>include("/http.js")</tt>.</p></div>\r
<div class="paragraph"><p>The HTTP interfaces in Node are designed to support many features\r
of the protocol which have been traditionally difficult to use.\r
In particular, large, possibly chunk-encoded, messages. The interface is\r
<div class="paragraph"><p>HTTP message headers are represented by an object like this</p></div>\r
<div class="listingblock">\r
<div class="content">\r
-<pre><tt> { "Content-Length": "123"\r
- , "Content-Type": "text/plain"\r
- , "Connection": "keep-alive"\r
- , "Accept": "*/*"\r
- }</tt></pre>\r
+<pre><tt>{ "Content-Length": "123"\r
+, "Content-Type": "text/plain"\r
+, "Connection": "keep-alive"\r
+, "Accept": "*/*"\r
+}</tt></pre>\r
</div></div>\r
<div class="paragraph"><p>In order to support the full spectrum of possible HTTP applications, Node’s\r
HTTP API is very low-level. It deals with connection handling and message\r
parse the actual headers or the body. That means, for example, that Node\r
does not, and will never, provide API to access or manipulate Cookies or\r
multi-part bodies. <em>This is left to the user.</em></p></div>\r
-<h4 id="_tt_node_http_server_tt"><tt>node.http.Server</tt></h4>\r
+<h4 id="_tt_http_server_tt"><tt>http.Server</tt></h4>\r
<div class="tableblock">\r
<table rules="all"\r
width="100%"\r
<tr>\r
<td align="left" valign="top"><p class="table"><tt>"request"</tt></p></td>\r
<td align="left" valign="top"><p class="table"><tt>request, response</tt></p></td>\r
-<td align="left" valign="top"><p class="table"><tt>request</tt> is an instance of <tt>node.http.ServerRequest</tt><br />\r
-<tt>response</tt> is an instance of <tt>node.http.ServerResponse</tt></p></td>\r
+<td align="left" valign="top"><p class="table"><tt>request</tt> is an instance of <tt>http.ServerRequest</tt><br />\r
+<tt>response</tt> is an instance of <tt>http.ServerResponse</tt></p></td>\r
</tr>\r
<tr>\r
<td align="left" valign="top"><p class="table"><tt>"connection"</tt></p></td>\r
<td align="left" valign="top"><p class="table"><tt>connection</tt></p></td>\r
<td align="left" valign="top"><p class="table">When a new TCP connection is established.\r
-<tt>connection</tt> is an object of type <tt>node.http.Connection</tt>. Usually users will not\r
+<tt>connection</tt> is an object of type <tt>http.Connection</tt>. Usually users will not\r
want to access this event. The <tt>connection</tt> can also be accessed at\r
<tt>request.connection</tt>.</p></td>\r
</tr>\r
</div>\r
<div class="dlist"><dl>\r
<dt class="hdlist1">\r
-<tt>node.http.createServer(request_listener, options);</tt> \r
+<tt>http.createServer(request_listener, options);</tt> \r
</dt>\r
<dd>\r
<p>\r
</p>\r
</dd>\r
</dl></div>\r
-<h4 id="_tt_node_http_serverrequest_tt"><tt>node.http.ServerRequest</tt></h4>\r
+<h4 id="_tt_http_serverrequest_tt"><tt>http.ServerRequest</tt></h4>\r
<div class="paragraph"><p>This object is created internally by a HTTP server—not by\r
the user—and passed as the first argument to a <tt>"request"</tt> listener.</p></div>\r
<div class="tableblock">\r
</dt>\r
<dd>\r
<p>\r
-The <tt>node.http.Connection</tt> object.\r
+The <tt>http.Connection</tt> object.\r
</p>\r
</dd>\r
</dl></div>\r
-<h4 id="_tt_node_http_serverresponse_tt"><tt>node.http.ServerResponse</tt></h4>\r
+<h4 id="_tt_http_serverresponse_tt"><tt>http.ServerResponse</tt></h4>\r
<div class="paragraph"><p>This object is created internally by a HTTP server—not by the user. It is\r
passed as the second parameter to the <tt>"request"</tt> event.</p></div>\r
<div class="dlist"><dl>\r
</p>\r
</dd>\r
</dl></div>\r
-<h4 id="_tt_node_http_client_tt"><tt>node.http.Client</tt></h4>\r
+<h4 id="_tt_http_client_tt"><tt>http.Client</tt></h4>\r
<div class="paragraph"><p>An HTTP client is constructed with a server address as its\r
argument, the returned handle is then used to issue one or more\r
requests. Depending on the server connected to, the client might\r
<div class="paragraph"><p>Example of connecting to <tt>google.com</tt></p></div>\r
<div class="listingblock">\r
<div class="content">\r
-<pre><tt>var google = node.http.createClient(80, "google.com");\r
+<pre><tt>var google = http.createClient(80, "google.com");\r
var request = google.get("/");\r
request.finish(function (response) {\r
puts("STATUS: " + response.statusCode);\r
</div></div>\r
<div class="dlist"><dl>\r
<dt class="hdlist1">\r
-<tt>node.http.createClient(port, host)</tt> \r
+<tt>http.createClient(port, host)</tt> \r
</dt>\r
<dd>\r
<p>\r
</dt>\r
<dd>\r
<p>\r
-Issues a request; if necessary establishes connection. Returns a <tt>node.http.ClientRequest</tt> instance.\r
+Issues a request; if necessary establishes connection. Returns a <tt>http.ClientRequest</tt> instance.\r
</p>\r
<div class="paragraph"><p><tt>request_headers</tt> is optional.\r
Additional request headers might be added internally\r
</div>\r
</dd>\r
</dl></div>\r
-<h4 id="_tt_node_http_clientrequest_tt"><tt>node.http.ClientRequest</tt></h4>\r
+<h4 id="_tt_http_clientrequest_tt"><tt>http.ClientRequest</tt></h4>\r
<div class="paragraph"><p>This object is created internally and returned from the request methods of a\r
-<tt>node.http.Client</tt>. It represents an <em>in-progress</em> request whose header has\r
+<tt>http.Client</tt>. It represents an <em>in-progress</em> request whose header has\r
already been sent.</p></div>\r
<div class="tableblock">\r
<table rules="all"\r
<td align="left" valign="top"><p class="table">Emitted when a response is received to this request. Typically the user will\r
set a listener to this via the <tt>request.finish()</tt> method.<br />\r
This event is emitted only once.<br />\r
-The <tt>response</tt> argument will be an instance of <tt>node.http.ClientResponse</tt>.</p></td>\r
+The <tt>response</tt> argument will be an instance of <tt>http.ClientResponse</tt>.</p></td>\r
</tr>\r
</tbody>\r
</table>\r
<div class="paragraph"><p>The parameter <tt>responseListener</tt> is a callback which\r
will be executed when the response headers have been received.\r
The <tt>responseListener</tt> callback is executed with one\r
-argument which is an instance of <tt>node.http.ClientResponse</tt>.</p></div>\r
+argument which is an instance of <tt>http.ClientResponse</tt>.</p></div>\r
<div class="paragraph"><p>In the <tt>responseListener</tt> callback, one can add more listeners to the\r
response, in particular listening for the <tt>"body"</tt> event. Note that\r
the <tt>responseListener</tt> is called before any part of the body is receieved,\r
</div></div>\r
</dd>\r
</dl></div>\r
-<h4 id="_tt_node_http_clientresponse_tt"><tt>node.http.ClientResponse</tt></h4>\r
+<h4 id="_tt_http_clientresponse_tt"><tt>http.ClientResponse</tt></h4>\r
<div class="paragraph"><p>This object is created internally and passed to the <tt>"response"</tt> event.</p></div>\r
<div class="tableblock">\r
<table rules="all"\r
</dt>\r
<dd>\r
<p>\r
- A reference to the <tt>node.http.Client</tt> that this response belongs to.\r
+ A reference to the <tt>http.Client</tt> that this response belongs to.\r
</p>\r
</dd>\r
</dl></div>\r
<div id="footer">\r
<div id="footer-text">\r
Version 0.1.12<br />\r
-Last updated 2009-09-28 12:04:19 CEST\r
+Last updated 2009-09-28 12:23:06 CEST\r
</div>\r
</div>\r
</body>\r
----------------------------------------
include("/utils.js");
-node.http.createServer(function (request, response) {
+include("/http.js");
+createServer(function (request, response) {
response.sendHeader(200, {"Content-Type": "text/plain"});
response.sendBody("Hello World\n");
response.finish();
=== HTTP
+To use the HTTP server and client one must +require("/http.js")+ or
++include("/http.js")+.
+
The HTTP interfaces in Node are designed to support many features
of the protocol which have been traditionally difficult to use.
In particular, large, possibly chunk-encoded, messages. The interface is
HTTP message headers are represented by an object like this
----------------------------------------
- { "Content-Length": "123"
- , "Content-Type": "text/plain"
- , "Connection": "keep-alive"
- , "Accept": "*/*"
- }
+{ "Content-Length": "123"
+, "Content-Type": "text/plain"
+, "Connection": "keep-alive"
+, "Accept": "*/*"
+}
----------------------------------------
In order to support the full spectrum of possible HTTP applications, Node's
multi-part bodies. _This is left to the user._
-==== +node.http.Server+
+==== +http.Server+
[cols="1,2,10",options="header"]
|=========================================================
|Event | Parameters | Notes
|+"request"+ | +request, response+ |
-+request+ is an instance of +node.http.ServerRequest+
++request+ is an instance of +http.ServerRequest+
+
-+response+ is an instance of +node.http.ServerResponse+
++response+ is an instance of +http.ServerResponse+
|+"connection"+ | +connection+ |
When a new TCP connection is established.
-+connection+ is an object of type +node.http.Connection+. Usually users will not
++connection+ is an object of type +http.Connection+. Usually users will not
want to access this event. The +connection+ can also be accessed at
+request.connection+.
|=========================================================
-+node.http.createServer(request_listener, options);+ ::
++http.createServer(request_listener, options);+ ::
Returns a new web server object.
+
The +options+ argument is optional. The
-==== +node.http.ServerRequest+
+==== +http.ServerRequest+
This object is created internally by a HTTP server--not by
the user--and passed as the first argument to a +"request"+ listener.
+request.connection+ ::
-The +node.http.Connection+ object.
+The +http.Connection+ object.
-==== +node.http.ServerResponse+
+==== +http.ServerResponse+
This object is created internally by a HTTP server--not by the user. It is
passed as the second parameter to the +"request"+ event.
-==== +node.http.Client+
+==== +http.Client+
An HTTP client is constructed with a server address as its
argument, the returned handle is then used to issue one or more
Example of connecting to +google.com+
----------------------------------------
-var google = node.http.createClient(80, "google.com");
+var google = http.createClient(80, "google.com");
var request = google.get("/");
request.finish(function (response) {
puts("STATUS: " + response.statusCode);
});
----------------------------------------
-+node.http.createClient(port, host)+ ::
++http.createClient(port, host)+ ::
Constructs a new HTTP client. +port+ and
+host+ refer to the server to be connected to. A
+client.get(path, request_headers)+, +client.head(path, request_headers)+, +client.post(path, request_headers)+, +client.del(path, request_headers)+, +client.put(path, request_headers)+ ::
-Issues a request; if necessary establishes connection. Returns a +node.http.ClientRequest+ instance.
+Issues a request; if necessary establishes connection. Returns a +http.ClientRequest+ instance.
+
+request_headers+ is optional.
Additional request headers might be added internally
+request.sendBody()+.)
-==== +node.http.ClientRequest+
+==== +http.ClientRequest+
This object is created internally and returned from the request methods of a
-+node.http.Client+. It represents an _in-progress_ request whose header has
++http.Client+. It represents an _in-progress_ request whose header has
already been sent.
[cols="1,2,10",options="header"]
+
This event is emitted only once.
+
-The +response+ argument will be an instance of +node.http.ClientResponse+.
+The +response+ argument will be an instance of +http.ClientResponse+.
|=========================================================
The parameter +responseListener+ is a callback which
will be executed when the response headers have been received.
The +responseListener+ callback is executed with one
-argument which is an instance of +node.http.ClientResponse+.
+argument which is an instance of +http.ClientResponse+.
+
In the +responseListener+ callback, one can add more listeners to the
response, in particular listening for the +"body"+ event. Note that
-==== +node.http.ClientResponse+
+==== +http.ClientResponse+
This object is created internally and passed to the +"response"+ event.
Resumes a paused response.
+response.client+ ::
- A reference to the +node.http.Client+ that this response belongs to.
+ A reference to the +http.Client+ that this response belongs to.
<simpara>An example of a web server written with Node which responds with "Hello\r
World":</simpara>\r
<screen>include("/utils.js");\r
-node.http.createServer(function (request, response) {\r
+include("/http.js");\r
+createServer(function (request, response) {\r
response.sendHeader(200, {"Content-Type": "text/plain"});\r
response.sendBody("Hello World\n");\r
response.finish();\r
</refsect2>\r
<refsect2 id="_http">\r
<title>HTTP</title>\r
+<simpara>To use the HTTP server and client one must <literal>require("/http.js")</literal> or\r
+<literal>include("/http.js")</literal>.</simpara>\r
<simpara>The HTTP interfaces in Node are designed to support many features\r
of the protocol which have been traditionally difficult to use.\r
In particular, large, possibly chunk-encoded, messages. The interface is\r
careful to never buffer entire requests or responses—the\r
user is able to stream data.</simpara>\r
<simpara>HTTP message headers are represented by an object like this</simpara>\r
-<screen> { "Content-Length": "123"\r
- , "Content-Type": "text/plain"\r
- , "Connection": "keep-alive"\r
- , "Accept": "*/*"\r
- }</screen>\r
+<screen>{ "Content-Length": "123"\r
+, "Content-Type": "text/plain"\r
+, "Connection": "keep-alive"\r
+, "Accept": "*/*"\r
+}</screen>\r
<simpara>In order to support the full spectrum of possible HTTP applications, Node’s\r
HTTP API is very low-level. It deals with connection handling and message\r
parsing only. It parses a message into headers and body but it does not\r
parse the actual headers or the body. That means, for example, that Node\r
does not, and will never, provide API to access or manipulate Cookies or\r
multi-part bodies. <emphasis>This is left to the user.</emphasis></simpara>\r
-<refsect3 id="_literal_node_http_server_literal">\r
-<title><literal>node.http.Server</literal></title>\r
+<refsect3 id="_literal_http_server_literal">\r
+<title><literal>http.Server</literal></title>\r
<informaltable\r
frame="all"\r
rowsep="1" colsep="1"\r
<row>\r
<entry align="left" valign="top"><simpara><literal>"request"</literal></simpara></entry>\r
<entry align="left" valign="top"><simpara><literal>request, response</literal></simpara></entry>\r
-<entry align="left" valign="top"><simpara><literal>request</literal> is an instance of <literal>node.http.ServerRequest</literal><?asciidoc-br?>\r
-<literal>response</literal> is an instance of <literal>node.http.ServerResponse</literal></simpara></entry>\r
+<entry align="left" valign="top"><simpara><literal>request</literal> is an instance of <literal>http.ServerRequest</literal><?asciidoc-br?>\r
+<literal>response</literal> is an instance of <literal>http.ServerResponse</literal></simpara></entry>\r
</row>\r
<row>\r
<entry align="left" valign="top"><simpara><literal>"connection"</literal></simpara></entry>\r
<entry align="left" valign="top"><simpara><literal>connection</literal></simpara></entry>\r
<entry align="left" valign="top"><simpara>When a new TCP connection is established.\r
-<literal>connection</literal> is an object of type <literal>node.http.Connection</literal>. Usually users will not\r
+<literal>connection</literal> is an object of type <literal>http.Connection</literal>. Usually users will not\r
want to access this event. The <literal>connection</literal> can also be accessed at\r
<literal>request.connection</literal>.</simpara></entry>\r
</row>\r
<variablelist>\r
<varlistentry>\r
<term>\r
-<literal>node.http.createServer(request_listener, options);</literal> \r
+<literal>http.createServer(request_listener, options);</literal> \r
</term>\r
<listitem>\r
<simpara>\r
</varlistentry>\r
</variablelist>\r
</refsect3>\r
-<refsect3 id="_literal_node_http_serverrequest_literal">\r
-<title><literal>node.http.ServerRequest</literal></title>\r
+<refsect3 id="_literal_http_serverrequest_literal">\r
+<title><literal>http.ServerRequest</literal></title>\r
<simpara>This object is created internally by a HTTP server—not by\r
the user—and passed as the first argument to a <literal>"request"</literal> listener.</simpara>\r
<informaltable\r
</term>\r
<listitem>\r
<simpara>\r
-The <literal>node.http.Connection</literal> object.\r
+The <literal>http.Connection</literal> object.\r
</simpara>\r
</listitem>\r
</varlistentry>\r
</variablelist>\r
</refsect3>\r
-<refsect3 id="_literal_node_http_serverresponse_literal">\r
-<title><literal>node.http.ServerResponse</literal></title>\r
+<refsect3 id="_literal_http_serverresponse_literal">\r
+<title><literal>http.ServerResponse</literal></title>\r
<simpara>This object is created internally by a HTTP server—not by the user. It is\r
passed as the second parameter to the <literal>"request"</literal> event.</simpara>\r
<variablelist>\r
</varlistentry>\r
</variablelist>\r
</refsect3>\r
-<refsect3 id="_literal_node_http_client_literal">\r
-<title><literal>node.http.Client</literal></title>\r
+<refsect3 id="_literal_http_client_literal">\r
+<title><literal>http.Client</literal></title>\r
<simpara>An HTTP client is constructed with a server address as its\r
argument, the returned handle is then used to issue one or more\r
requests. Depending on the server connected to, the client might\r
pipeline the requests or reestablish the connection after each\r
connection. <emphasis>Currently the implementation does not pipeline requests.</emphasis></simpara>\r
<simpara>Example of connecting to <literal>google.com</literal></simpara>\r
-<screen>var google = node.http.createClient(80, "google.com");\r
+<screen>var google = http.createClient(80, "google.com");\r
var request = google.get("/");\r
request.finish(function (response) {\r
puts("STATUS: " + response.statusCode);\r
<variablelist>\r
<varlistentry>\r
<term>\r
-<literal>node.http.createClient(port, host)</literal> \r
+<literal>http.createClient(port, host)</literal> \r
</term>\r
<listitem>\r
<simpara>\r
</term>\r
<listitem>\r
<simpara>\r
-Issues a request; if necessary establishes connection. Returns a <literal>node.http.ClientRequest</literal> instance.\r
+Issues a request; if necessary establishes connection. Returns a <literal>http.ClientRequest</literal> instance.\r
</simpara>\r
<simpara><literal>request_headers</literal> is optional.\r
Additional request headers might be added internally\r
</varlistentry>\r
</variablelist>\r
</refsect3>\r
-<refsect3 id="_literal_node_http_clientrequest_literal">\r
-<title><literal>node.http.ClientRequest</literal></title>\r
+<refsect3 id="_literal_http_clientrequest_literal">\r
+<title><literal>http.ClientRequest</literal></title>\r
<simpara>This object is created internally and returned from the request methods of a\r
-<literal>node.http.Client</literal>. It represents an <emphasis>in-progress</emphasis> request whose header has\r
+<literal>http.Client</literal>. It represents an <emphasis>in-progress</emphasis> request whose header has\r
already been sent.</simpara>\r
<informaltable\r
frame="all"\r
<entry align="left" valign="top"><simpara>Emitted when a response is received to this request. Typically the user will\r
set a listener to this via the <literal>request.finish()</literal> method.<?asciidoc-br?>\r
This event is emitted only once.<?asciidoc-br?>\r
-The <literal>response</literal> argument will be an instance of <literal>node.http.ClientResponse</literal>.</simpara></entry>\r
+The <literal>response</literal> argument will be an instance of <literal>http.ClientResponse</literal>.</simpara></entry>\r
</row>\r
</tbody>\r
</tgroup>\r
<simpara>The parameter <literal>responseListener</literal> is a callback which\r
will be executed when the response headers have been received.\r
The <literal>responseListener</literal> callback is executed with one\r
-argument which is an instance of <literal>node.http.ClientResponse</literal>.</simpara>\r
+argument which is an instance of <literal>http.ClientResponse</literal>.</simpara>\r
<simpara>In the <literal>responseListener</literal> callback, one can add more listeners to the\r
response, in particular listening for the <literal>"body"</literal> event. Note that\r
the <literal>responseListener</literal> is called before any part of the body is receieved,\r
</varlistentry>\r
</variablelist>\r
</refsect3>\r
-<refsect3 id="_literal_node_http_clientresponse_literal">\r
-<title><literal>node.http.ClientResponse</literal></title>\r
+<refsect3 id="_literal_http_clientresponse_literal">\r
+<title><literal>http.ClientResponse</literal></title>\r
<simpara>This object is created internally and passed to the <literal>"response"</literal> event.</simpara>\r
<informaltable\r
frame="all"\r
</term>\r
<listitem>\r
<simpara>\r
- A reference to the <literal>node.http.Client</literal> that this response belongs to.\r
+ A reference to the <literal>http.Client</literal> that this response belongs to.\r
</simpara>\r
</listitem>\r
</varlistentry>\r
</p>
<pre>
-utils = require("/utils.js");
-server = node.http.createServer(function (req, res) {
+include("/utils.js");
+include("/http.js");
+createServer(function (req, res) {
setTimeout(function () {
res.sendHeader(200, {"Content-Type": "text/plain"});
res.sendBody("Hello World");
res.finish();
}, 2000);
-});
-server.listen(8000);
-utils.puts("Server running at http://127.0.0.1:8000/");</pre>
+}).listen(8000);
+puts("Server running at http://127.0.0.1:8000/");</pre>
</pre>
<p>
.RS 4
.nf
include("/utils\.js");
-node\.http\.createServer(function (request, response) {
+include("/http\.js");
+createServer(function (request, response) {
response\.sendHeader(200, {"Content\-Type": "text/plain"});
response\.sendBody("Hello World\en");
response\.finish();
.RE
.RE
.SS "HTTP"
+To use the HTTP server and client one must require("/http\.js") or include("/http\.js")\.
+.sp
The HTTP interfaces in Node are designed to support many features of the protocol which have been traditionally difficult to use\. In particular, large, possibly chunk\-encoded, messages\. The interface is careful to never buffer entire requests or responses\(emthe user is able to stream data\.
.sp
HTTP message headers are represented by an object like this
.sp
.RS 4
.nf
- { "Content\-Length": "123"
- , "Content\-Type": "text/plain"
- , "Connection": "keep\-alive"
- , "Accept": "*/*"
- }
+{ "Content\-Length": "123"
+, "Content\-Type": "text/plain"
+, "Connection": "keep\-alive"
+, "Accept": "*/*"
+}
.fi
.RE
In order to support the full spectrum of possible HTTP applications, Node\(cqs HTTP API is very low\-level\. It deals with connection handling and message parsing only\. It parses a message into headers and body but it does not parse the actual headers or the body\. That means, for example, that Node does not, and will never, provide API to access or manipulate Cookies or multi\-part bodies\. \fIThis is left to the user\.\fR
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
-node.http.Server
+http.Server
.RS
.TS
allbox tab(:);
request, response
.sp
T}:T{
-request is an instance of node\.http\.ServerRequest response is an instance of node\.http\.ServerResponse
+request is an instance of http\.ServerRequest response is an instance of http\.ServerResponse
.sp
T}
T{
connection
.sp
T}:T{
-When a new TCP connection is established\. connection is an object of type node\.http\.Connection\. Usually users will not want to access this event\. The connection can also be accessed at request\.connection\.
+When a new TCP connection is established\. connection is an object of type http\.Connection\. Usually users will not want to access this event\. The connection can also be accessed at request\.connection\.
.sp
T}
T{
T}
.TE
.PP
-node\.http\.createServer(request_listener, options);
+http\.createServer(request_listener, options);
.RS 4
Returns a new web server object\.
.sp
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
-node.http.ServerRequest
+http.ServerRequest
.RS
This object is created internally by a HTTP server\(emnot by the user\(emand passed as the first argument to a "request" listener\.
.sp
request\.connection
.RS 4
The
-node\.http\.Connection
+http\.Connection
object\.
.RE
.RE
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
-node.http.ServerResponse
+http.ServerResponse
.RS
This object is created internally by a HTTP server\(emnot by the user\. It is passed as the second parameter to the "request" event\.
.PP
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
-node.http.Client
+http.Client
.RS
An HTTP client is constructed with a server address as its argument, the returned handle is then used to issue one or more requests\. Depending on the server connected to, the client might pipeline the requests or reestablish the connection after each connection\. \fICurrently the implementation does not pipeline requests\.\fR
.sp
.sp
.RS 4
.nf
-var google = node\.http\.createClient(80, "google\.com");
+var google = http\.createClient(80, "google\.com");
var request = google\.get("/");
request\.finish(function (response) {
puts("STATUS: " + response\.statusCode);
.fi
.RE
.PP
-node\.http\.createClient(port, host)
+http\.createClient(port, host)
.RS 4
Constructs a new HTTP client\.
port
client\.get(path, request_headers), client\.head(path, request_headers), client\.post(path, request_headers), client\.del(path, request_headers), client\.put(path, request_headers)
.RS 4
Issues a request; if necessary establishes connection\. Returns a
-node\.http\.ClientRequest
+http\.ClientRequest
instance\.
.sp
request_headers
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
-node.http.ClientRequest
+http.ClientRequest
.RS
-This object is created internally and returned from the request methods of a node\.http\.Client\. It represents an \fIin\-progress\fR request whose header has already been sent\.
+This object is created internally and returned from the request methods of a http\.Client\. It represents an \fIin\-progress\fR request whose header has already been sent\.
.sp
.TS
allbox tab(:);
response
.sp
T}:T{
-Emitted when a response is received to this request\. Typically the user will set a listener to this via the request\.finish() method\. This event is emitted only once\. The response argument will be an instance of node\.http\.ClientResponse\.
+Emitted when a response is received to this request\. Typically the user will set a listener to this via the request\.finish() method\. This event is emitted only once\. The response argument will be an instance of http\.ClientResponse\.
.sp
T}
.TE
is a callback which will be executed when the response headers have been received\. The
responseListener
callback is executed with one argument which is an instance of
-node\.http\.ClientResponse\.
+http\.ClientResponse\.
.sp
In the
responseListener
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
-node.http.ClientResponse
+http.ClientResponse
.RS
This object is created internally and passed to the "response" event\.
.sp
response\.client
.RS 4
A reference to the
-node\.http\.Client
+http\.Client
that this response belongs to\.
.RE
.RE
-(function () {
-CRLF = "\r\n";
-node.http.STATUS_CODES = {
+var utils = require("/utils.js");
+
+var CRLF = "\r\n";
+var STATUS_CODES = {
100 : 'Continue',
101 : 'Switching Protocols',
200 : 'OK',
return decodeURIComponent(s.replace(/\+/g, ' '));
}
-node.http.parseUri = function (str) {
- var o = node.http.parseUri.options,
+exports.parseUri = function (str) {
+ var o = exports.parseUri.options,
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
uri = {},
i = 14;
return uri;
};
-node.http.parseUri.options = {
+exports.parseUri.options = {
strictMode: false,
key: [
"source",
node.inherits(ServerResponse, OutgoingMessage);
ServerResponse.prototype.sendHeader = function (statusCode, headers) {
- var reason = node.http.STATUS_CODES[statusCode] || "unknown";
+ var reason = STATUS_CODES[statusCode] || "unknown";
var status_line = "HTTP/1.1 " + statusCode.toString() + " " + reason + CRLF;
this.sendHeaderLines(status_line, headers);
};
if (info.method) {
// server only
incoming.method = info.method;
- incoming.uri = node.http.parseUri(incoming.uri); // TODO parse the URI lazily?
+ incoming.uri = exports.parseUri(incoming.uri); // TODO parse the URI lazily?
} else {
// client only
incoming.statusCode = info.statusCode;
}
-node.http.createServer = function (requestListener, options) {
+exports.createServer = function (requestListener, options) {
var server = new node.http.Server();
//server.setOptions(options);
server.addListener("request", requestListener);
}
-node.http.createClient = function (port, host) {
+exports.createClient = function (port, host) {
var client = new node.http.Client();
var requests = [];
client._pushRequest = function (req) {
req.addListener("flush", function () {
if (client.readyState == "closed") {
- //node.debug("HTTP CLIENT request flush. reconnect. readyState = " + client.readyState);
+ //utils.debug("HTTP CLIENT request flush. reconnect. readyState = " + client.readyState);
client.connect(port, host); // reconnect
return;
}
- //node.debug("client flush readyState = " + client.readyState);
+ //utils.debug("client flush readyState = " + client.readyState);
if (req == requests[0]) flushMessageQueue(client, [req]);
});
requests.push(req);
});
client.addListener("eof", function () {
- //node.debug("client got eof closing. readyState = " + client.readyState);
+ //utils.debug("client got eof closing. readyState = " + client.readyState);
client.close();
});
return;
}
- //node.debug("HTTP CLIENT onClose. readyState = " + client.readyState);
+ //utils.debug("HTTP CLIENT onClose. readyState = " + client.readyState);
// If there are more requests to handle, reconnect.
if (requests.length > 0 && client.readyState != "opening") {
- //node.debug("HTTP CLIENT: reconnecting readyState = " + client.readyState);
+ //utils.debug("HTTP CLIENT: reconnecting readyState = " + client.readyState);
client.connect(port, host); // reconnect
}
});
createIncomingMessageStream(client, function (res) {
- //node.debug("incoming response!");
+ //utils.debug("incoming response!");
res.addListener("complete", function ( ) {
- //node.debug("request complete disconnecting. readyState = " + client.readyState);
+ //utils.debug("request complete disconnecting. readyState = " + client.readyState);
client.close();
});
};
-node.http.cat = function (url, encoding) {
+exports.cat = function (url, encoding) {
var promise = new node.Promise();
encoding = encoding || "utf8";
- var uri = node.http.parseUri(url);
- var client = node.http.createClient(uri.port || 80, uri.host);
+ var uri = exports.parseUri(url);
+ var client = exports.createClient(uri.port || 80, uri.host);
var req = client.get(uri.path || "/");
client.addListener("error", function () {
return promise;
};
-
-})(); // anonymous namespace
ExecuteNativeJS("util.js", native_util);
ExecuteNativeJS("events.js", native_events);
- ExecuteNativeJS("http.js", native_http);
ExecuteNativeJS("file.js", native_file);
ExecuteNativeJS("node.js", native_node);
throw new Error("node.exec() has moved. Use include('/utils.js') to bring it back.");
}
+node.http.createServer = function () {
+ throw new Error("node.http.createServer() has moved. Use require('/http.js') to access it.");
+}
+
+node.http.createClient = function () {
+ throw new Error("node.http.createClient() has moved. Use require('/http.js') to access it.");
+}
+
node.tcp.createConnection = function (port, host) {
var connection = new node.tcp.Connection();
connection.connect(port, host);
node.cat = function(location, encoding) {
var url_re = new RegExp("^http:\/\/");
- var f = url_re.exec(location) ? node.http.cat : node.fs.cat;
- return f(location, encoding);
+ if (url_re.exec(location)) {
+ throw new Error("node.cat for http urls is temporarally disabled.");
+ }
+ //var f = url_re.exec(location) ? node.http.cat : node.fs.cat;
+ //return f(location, encoding);
+ return node.fs.cat(location, encoding);
};
node.path = new function () {
include("common.js");
+http = require("/http.js");
PORT = 8888;
puts("hello world");
var body = "exports.A = function() { return 'A';}";
-var server = node.http.createServer(function (req, res) {
+var server = http.createServer(function (req, res) {
puts("req?");
res.sendHeader(200, {
"Content-Length": body.length,
include("common.js");
+http = require("/http.js");
PORT = 8888;
var body = "exports.A = function() { return 'A';}";
-var server = node.http.createServer(function (req, res) {
+var server = http.createServer(function (req, res) {
puts("got request");
res.sendHeader(200, [
["Content-Length", body.length],
var got_good_server_content = false;
var bad_server_got_error = false;
-node.http.cat("http://localhost:"+PORT+"/", "utf8").addCallback(function (content) {
+http.cat("http://localhost:"+PORT+"/", "utf8").addCallback(function (content) {
puts("got response");
got_good_server_content = true;
assertEquals(body, content);
server.close();
});
-node.http.cat("http://localhost:12312/", "utf8").addErrback(function () {
+http.cat("http://localhost:12312/", "utf8").addErrback(function () {
puts("got error (this should happen)");
bad_server_got_error = true;
});
process.addListener("exit", function () {
+ puts("exit");
assertTrue(got_good_server_content);
assertTrue(bad_server_got_error);
});
include("common.js");
+http = require("/http.js");
PORT = 8888;
var body1_s = "1111111111111111";
var body2_s = "22222";
-var server = node.http.createServer(function (req, res) {
+var server = http.createServer(function (req, res) {
var body = req.uri.path === "/1" ? body1_s : body2_s;
res.sendHeader(200, { "Content-Type": "text/plain"
, "Content-Length": body.length
});
server.listen(PORT);
-var client = node.http.createClient(PORT);
+var client = http.createClient(PORT);
var body1 = "";
var body2 = "";
include("common.js");
+http = require("/http.js");
var PORT = 18032;
var sent_body = "";
var server_req_complete = false;
var client_res_complete = false;
-var server = node.http.createServer(function(req, res) {
+var server = http.createServer(function(req, res) {
assertEquals("POST", req.method);
req.setBodyEncoding("utf8");
});
server.listen(PORT);
-var client = node.http.createClient(PORT);
+var client = http.createClient(PORT);
var req = client.post('/');
req.sendBody('1\n');
include("common.js");
+http = require("/http.js");
// Make sure no exceptions are thrown when receiving malformed HTTP
// requests.
nrequests_completed = 0;
nrequests_expected = 1;
-var s = node.http.createServer(function (req, res) {
+var s = http.createServer(function (req, res) {
puts("req: " + JSON.stringify(req.uri));
res.sendHeader(200, {"Content-Type": "text/plain"});
include("common.js");
+http = require("/http.js");
var PROXY_PORT = 8869;
var BACKEND_PORT = 8870;
-var backend = node.http.createServer(function (req, res) {
+var backend = http.createServer(function (req, res) {
// debug("backend");
res.sendHeader(200, {"content-type": "text/plain"});
res.sendBody("hello world\n");
// debug("listen backend")
backend.listen(BACKEND_PORT);
-var proxy_client = node.http.createClient(BACKEND_PORT);
-var proxy = node.http.createServer(function (req, res) {
+var proxy_client = http.createClient(BACKEND_PORT);
+var proxy = http.createServer(function (req, res) {
debug("proxy req headers: " + JSON.stringify(req.headers));
var proxy_req = proxy_client.get(req.uri.path);
proxy_req.finish(function(proxy_res) {
var body = "";
-var client = node.http.createClient(PROXY_PORT);
+var client = http.createClient(PROXY_PORT);
var req = client.get("/test");
// debug("client req")
req.finish(function (res) {
include("common.js");
+http = require("/http.js");
var port = 8222;
var server_response = "";
var client_got_eof = false;
-node.http.createServer(function (req, res) {
+http.createServer(function (req, res) {
res.id = request_number;
req.id = request_number++;
include("common.js");
+http = require("/http.js");
PORT = 8888;
var responses_sent = 0;
var body0 = "";
var body1 = "";
-node.http.createServer(function (req, res) {
+http.createServer(function (req, res) {
if (responses_sent == 0) {
assertEquals("GET", req.method);
assertEquals("/hello", req.uri.path);
//assertEquals("127.0.0.1", res.connection.remoteAddress);
}).listen(PORT);
-var client = node.http.createClient(PORT);
+var client = http.createClient(PORT);
var req = client.get("/hello", {"Accept": "*/*", "Foo": "bar"});
req.finish(function (res) {
assertEquals(200, res.statusCode);
include("common.js");
+http = require("/http.js");
var multipart = require('/multipart.js');
var port = 8222;
var parts_complete = 0;
var parts = {};
-var server = node.http.createServer(function(req, res) {
+var server = http.createServer(function(req, res) {
var stream = new multipart.Stream(req);
stream.addListener('part', function(part) {
source = """
src/util.js
src/events.js
- src/http.js
src/file.js
src/node.js
""",