Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
73 lines (57 sloc) 2.63 KB
A simple to use (hopefully) http client for the node.js platform.
It adds easy control of HTTPS, gzip compression and cookie handling
to the basic http functionality provided by node.js http library.
- if you want to use gzip you will need the node-compress module
built and available in the lib directory (or the same directory
as httpclient.js). node-compress is here:
- better Error handling
- full set of http client tests to compare with other http clients
(e.g. libcurl, libwww, winhttp)
- handle all cookies correctly according to RFC
- allow saving and restoring of cookies
- handle gzip encoding from client to server (should be simple)
- allow specification of timeouts for connection and response
- allow explicit closing of connection
- allow option to automatically follow redirects (should be a simple change)
- property content handling (binary, text encodings etc) based on http headers
- handle http expiration headers and cacheing policies
- handle head, put and delete requests
etc, etc, etc...
- currently, the httpclient object will only allow one request at a time
for a given protocol and host name (e.g. this
behaviour is handled in http.js where requests get queued up and executed
in sequence. if you want to send parallel requests to the same site, then
create a new httpclient object for each of the parallel requests. Am not
sure whether this is the correct behaviour but it seems to work well for
what i need right now.
(see example.js)
var sys = require("sys");
var httpcli = require("./httpclient");
var url = "";
var surl = "";
function verifyTLS(request) {
return true;
var client = new httpcli.httpclient();
// a simple http request with default options (gzip off, keepalive off, https off)
client.perform(url, "GET", function(result) {
}, null);
var client2 = new httpcli.httpclient();
// nested calls with gzip compression and keep-alive
client2.perform(url, "GET", function(result) {
client2.perform(url, "GET", function(result) {
// https request with callback handling of certificate validation
client2.perform(surl, "GET", function(result) {
}, null, {"Accept-Encoding" : "none,gzip", "Connection" : "close"}, verifyTLS);
}, null, {"Accept-Encoding" : "none,gzip", "Connection" : "Keep-Alive"});
}, null, {"Accept-Encoding" : "none,gzip", "Connection" : "Keep-Alive"});