function responseListener (res) {
res.addListener("complete", function () {
if (requests < n) {
- res.client.get("/").finish(responseListener);
+ res.client.request("/").finish(responseListener);
requests++;
}
for (var i = 0; i < concurrency; i++) {
var client = http.createClient(port);
client.id = i;
- client.get("/").finish(responseListener);
+ client.request("/").finish(responseListener);
requests++;
}
var sys = require("sys"),
http = require("http");
var google = http.createClient(80, "www.google.com");
-var request = google.get("/", {"host": "www.google.com"});
+var request = google.request("GET", "/", {"host": "www.google.com"});
request.finish(function (response) {
sys.puts("STATUS: " + response.statusCode);
sys.puts("HEADERS: " + JSON.stringify(response.headers));
+host+ refer to the server to be connected to. A
connection is not established until a request is issued.
-+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)+ ::
++client.request([method], path, [request_headers])+ ::
Issues a request; if necessary establishes connection. Returns a +http.ClientRequest+ instance.
+
++
++method+ is optional and defaults to "GET" if omitted.
+
+request_headers+ is optional.
Additional request headers might be added internally
return client;
};
-process.http.Client.prototype.get = function (uri, headers) {
- var req = new ClientRequest("GET", uri, headers);
- this._pushRequest(req);
- return req;
+process.http.Client.prototype.get = function () {
+ throw new Error("client.get(...) is now client.request('GET', ...)");
};
-process.http.Client.prototype.head = function (uri, headers) {
- var req = new ClientRequest("HEAD", uri, headers);
- this._pushRequest(req);
- return req;
+process.http.Client.prototype.head = function () {
+ throw new Error("client.head(...) is now client.request('HEAD', ...)");
};
-process.http.Client.prototype.post = function (uri, headers) {
- var req = new ClientRequest("POST", uri, headers);
- this._pushRequest(req);
- return req;
+process.http.Client.prototype.post = function () {
+ throw new Error("client.post(...) is now client.request('POST', ...)");
};
-process.http.Client.prototype.del = function (uri, headers) {
- var req = new ClientRequest("DELETE", uri, headers);
- this._pushRequest(req);
- return req;
+process.http.Client.prototype.del = function () {
+ throw new Error("client.del(...) is now client.request('DELETE', ...)");
};
-process.http.Client.prototype.put = function (uri, headers) {
- var req = new ClientRequest("PUT", uri, headers);
+process.http.Client.prototype.put = function () {
+ throw new Error("client.put(...) is now client.request('PUT', ...)");
+};
+
+process.http.Client.prototype.request = function (method, uri, headers) {
+ if (typeof(uri) != "string") { // assume method was omitted, shift arguments
+ headers = uri;
+ uri = method;
+ method = null;
+ }
+ var req = new ClientRequest(method || "GET", uri, headers);
this._pushRequest(req);
return req;
};
}
var client = exports.createClient(uri.port || 80, uri.host);
- var req = client.get(uri.path || "/", headers);
+ var req = client.request(uri.path || "/", headers);
client.addListener("error", function () {
promise.emitError();
var body1 = "";
var body2 = "";
-client.get("/1").finish(function (res1) {
+client.request("/1").finish(function (res1) {
res1.setBodyEncoding("utf8");
res1.addListener("body", function (chunk) {
});
res1.addListener("complete", function () {
- client.get("/2").finish(function (res2) {
+ client.request("/2").finish(function (res2) {
res2.setBodyEncoding("utf8");
res2.addListener("body", function (chunk) { body2 += chunk; });
res2.addListener("complete", function () { server.close(); });
server.listen(PORT);
var client = http.createClient(PORT);
-var req = client.post('/');
+var req = client.request('POST', '/');
req.sendBody('1\n');
req.sendBody('2\n');
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);
+ var proxy_req = proxy_client.request(req.uri.path);
proxy_req.finish(function(proxy_res) {
res.sendHeader(proxy_res.statusCode, proxy_res.headers);
proxy_res.addListener("body", function(chunk) {
var body = "";
var client = http.createClient(PROXY_PORT);
-var req = client.get("/test");
+var req = client.request("/test");
// debug("client req")
req.finish(function (res) {
// debug("got res");
var client = http.createClient(PORT, HOST);
client.setSecure("x509_PEM", caPem, 0, keyPem, certPem);
-var req = client.get("/hello", {"Accept": "*/*", "Foo": "bar"});
+var req = client.request("/hello", {"Accept": "*/*", "Foo": "bar"});
req.finish(function (res) {
var verified = res.connection.verifyPeer();
var peerDN = res.connection.getPeerCertificate("DNstring");
});
setTimeout(function () {
- req = client.post("/world");
+ req = client.request("POST", "/world");
req.finish(function (res) {
var verified = res.connection.verifyPeer();
var peerDN = res.connection.getPeerCertificate("DNstring");
}).listen(PORT);
var client = http.createClient(PORT);
-var req = client.get("/hello", {"Accept": "*/*", "Foo": "bar"});
+var req = client.request("/hello", {"Accept": "*/*", "Foo": "bar"});
req.finish(function (res) {
assert.equal(200, res.statusCode);
responses_recvd += 1;
});
setTimeout(function () {
- req = client.post("/world");
+ req = client.request("POST", "/world");
req.finish(function (res) {
assert.equal(200, res.statusCode);
responses_recvd += 1;
server.listen(port);
var client = http.createClient(port);
-var request = client.post('/', {'Content-Type': 'multipart/form-data; boundary=AaB03x', 'Content-Length': fixture.reply.length});
+var request = client.request('POST', '/', {'Content-Type': 'multipart/form-data; boundary=AaB03x', 'Content-Length': fixture.reply.length});
request.sendBody(fixture.reply, 'binary');
request.finish();