Permalink
Browse files

[dist] Merge flatiron/gh10

  • Loading branch information...
2 parents b9b0a93 + 66e9501 commit d4dd52e7752d2cd3d060b1098e5af52a0a5c46c1 @indexzero indexzero committed May 27, 2012
Showing with 63 additions and 6 deletions.
  1. +4 −4 lib/core.js
  2. +9 −0 lib/request-stream.js
  3. +1 −1 lib/response-stream.js
  4. +1 −1 lib/routing-stream.js
  5. +48 −0 test/body-parser-test.js
View
@@ -27,10 +27,10 @@ core.createServer = function (options) {
before: options.before,
// without new after is a huge memory leak that pipes to every
// single open connection
- after: isArray &&
- options.after.map(function (a) {
- return new a;
- }),
+ after: isArray && options.after.map(function (a) {
+ return new a;
+ }),
+ request: req,
response: res,
limit: options.limit,
headers: options.headers
@@ -16,6 +16,7 @@ var RequestStream = module.exports = function (options) {
HttpStream.call(this, options);
this.on('pipe', this.pipeRequest);
+ this.request = options.request;
};
util.inherits(RequestStream, HttpStream);
@@ -44,3 +45,11 @@ RequestStream.prototype.pipeRequest = function (source) {
: {};
}
};
+
+// http.serverRequest methods
+['setEncoding'].forEach(function (method) {
+ RequestStream.prototype[method] = function () {
+ return this.request[method].apply(this.request, arguments);
+ };
+});
+
@@ -11,7 +11,7 @@ var util = require('util'),
HttpStream = require('./http-stream');
//
-// ### function RequestStream (options)
+// ### function ResponseStream (options)
//
//
var ResponseStream = module.exports = function (options) {
@@ -13,7 +13,7 @@ var util = require('util'),
ResponseStream = require('./response-stream');
//
-// ### function RequestStream (options)
+// ### function RoutingStream (options)
//
//
var RoutingStream = module.exports = function (options) {
@@ -0,0 +1,48 @@
+/*
+ * simple-test.js: Simple tests for basic streaming and non-streaming HTTP requests with union.
+ *
+ * (C) 2011, Nodejitsu Inc.
+ * MIT LICENSE
+ *
+ */
+
+var assert = require('assert'),
+ bodyParser = require('connect').bodyParser,
+ request = require('request'),
+ vows = require('vows'),
+ union = require('../');
+
+vows.describe('union/body-parser').addBatch({
+ "When using union with connect bodyParser()": {
+ topic: function () {
+ union.createServer({
+ before: [
+ bodyParser(),
+ function (req, res) {
+ res.end(JSON.stringify(req.body, true, 2));
+ }
+ ]
+ }).listen(8082, this.callback);
+ },
+ "a request to /": {
+ topic: function () {
+ request.post({
+ uri: 'http://localhost:8082/',
+ headers: {
+ 'content-type': 'application/json'
+ },
+ body: JSON.stringify({ a: "foo", b: "bar" })
+ }, this.callback);
+ },
+ "should respond with a qs-decoded object": function (err, res, body) {
+ assert.isNull(err);
+ assert.equal(res.statusCode, 200);
+ assert.deepEqual(
+ JSON.parse(body),
+ { a: 'foo', b: 'bar' }
+ );
+ }
+ }
+ }
+}).export(module);
+

0 comments on commit d4dd52e

Please sign in to comment.