Permalink
Browse files

Updated tests and dependencies.

  • Loading branch information...
1 parent 7a20a34 commit 95c519e4eb508d2879db9583284f3ed2622a05ef Kris Kowal committed Jun 15, 2011
Showing with 33 additions and 27 deletions.
  1. +1 −0 .gitignore
  2. +3 −3 package.json
  3. +14 −5 q-http.js
  4. +0 −5 test/bad-url.js
  5. +5 −3 test/basic.js
  6. +10 −11 test/keep-alive.js
View
@@ -0,0 +1 @@
+node_modules
View
@@ -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": {
@@ -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",
View
@@ -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");
/**
@@ -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();
@@ -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 () {
View
@@ -1,5 +0,0 @@
-var Q = require("q");
-var HTTP = require("q-http");
-Q.when(HTTP.read("http://localhost:1/blah.js"), null, function (error) {
- console.log(error);
-});
View
@@ -1,5 +1,4 @@
-var SYS = require("sys");
var Q = require("q");
var HTTP = require("q-http");
@@ -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();
View
@@ -1,6 +1,5 @@
-var SYS = require("sys");
-var Q = require("q-util");
+var Q = require("q");
var HTTP = require("q-http");
var request = {
@@ -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.