Skip to content

Commit

Permalink
Updated tests and dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris Kowal committed Jun 15, 2011
1 parent 7a20a34 commit 95c519e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
6 changes: 3 additions & 3 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "q-http",
"description": "Q promise based HTTP client and server interface",
"version": "0.1.0",
"version": "0.1.1",
"homepage": "http://github.com/kriskowal/q-http/",
"author": "Kris Kowal <kris@cixar.com> (http://github.com/kriskowal/)",
"bugs": {
Expand All @@ -16,8 +16,8 @@
],
"main": "q-http.js",
"dependencies": {
"q-util": ">=0.0.1",
"q-io": ">=0.0.4"
"q": ">=0.5.0",
"q-io": ">=0.0.6"
},
"repository": {
"type": "git",
Expand Down
19 changes: 14 additions & 5 deletions q-http.js
Expand Up @@ -9,7 +9,7 @@
var HTTP = require("http"); // node
var HTTPS = require("https"); // node
var URL = require("url"); // node
var Q = require("q-util");
var Q = require("q");
var IO = require("q-io");

/**
Expand Down Expand Up @@ -50,8 +50,13 @@ exports.Server = function (respond) {
) {
_response.end(body[0]);
} else if (body) {
var end = Q.forEach(body, function (chunk) {
_response.write(chunk, "binary");
var end;
body.forEach(function (chunk) {
end = Q.when(end, function () {
return Q.when(chunk, function (chunk) {
_response.write(chunk, "binary");
});
});
});
return Q.when(end, function () {
_response.end();
Expand Down Expand Up @@ -199,8 +204,12 @@ exports.request = function (request) {
Q.when(request.body, function (body) {
var end;
if (body) {
end = Q.forEach(body, function (chunk) {
_request.write(chunk, request.charset);
body.forEach(function (chunk) {
end = Q.when(end, function () {
return Q.when(chunk, function (chunk) {
_request.write(chunk, request.charset);
});
});
});
}
Q.when(end, function () {
Expand Down
5 changes: 0 additions & 5 deletions test/bad-url.js

This file was deleted.

8 changes: 5 additions & 3 deletions test/basic.js
@@ -1,5 +1,4 @@

var SYS = require("sys");
var Q = require("q");
var HTTP = require("q-http");

Expand Down Expand Up @@ -28,9 +27,12 @@ var server = HTTP.Server(function () {
Q.when(server.listen(8080), function () {
return Q.when(HTTP.request(request), function (response) {
return Q.when(response.body, function (body) {
var done = body.forEach(SYS.puts);
var done = body.forEach(function (chunk) {
console.log(chunk.toString("utf-8"));
});
Q.when(done, server.stop);
});
});
}, Q.error);
})
.end();

21 changes: 10 additions & 11 deletions test/keep-alive.js
@@ -1,6 +1,5 @@

var SYS = require("sys");
var Q = require("q-util");
var Q = require("q");
var HTTP = require("q-http");

var request = {
Expand All @@ -27,17 +26,17 @@ var server = HTTP.Server(function () {

Q.when(server.listen(8080), function () {

var client = HTTP.Client(8080, "localhost");

var done = Q.times(3, function () {
return Q.when(client.request(request), function (response) {
var done = [1,2,3].reduce(function (done) {
return Q.when(HTTP.request(request), function (response) {
return Q.when(response.body, function (body) {
return body.forEach(SYS.puts);
return Q.when(body.forEach(function (chunk) {
console.log(chunk.toString('utf-8'));
})).wait(done);
});
});
});

Q.when(done, server.stop);
}, undefined);

}, Q.error);
return Q.when(done, server.stop);
})
.end();

0 comments on commit 95c519e

Please sign in to comment.