Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Temporary Streams2 support #507

Closed
wants to merge 3 commits into from

2 participants

@hueniverse

Not sure how to test this since you need node 0.10 to really try the stream. But fully tested within hapi.

@mikeal
Owner

I really don't want to split support from streams1 -> steams2.

I'd rather just take readable-stream as a dependency and move all of request to the streams2 API.

@hueniverse

Yeah... don't have time to contribute that for at least 2 weeks. For now will just treat 'request' as old style streams and call Readable.wrap() on it.

@mikeal mikeal closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 20 additions and 12 deletions.
  1. +20 −12 index.js
View
32 index.js
@@ -145,6 +145,10 @@ Request.prototype.init = function (options) {
self.on('complete', self.callback.bind(self, null))
}
+ if (self.callback) {
+ self.streams2 = false;
+ }
+
if (self.url) {
// People use this property instead all the time so why not just support it.
self.uri = self.url
@@ -624,11 +628,13 @@ Request.prototype.onResponse = function (response) {
}
if (self._aborted) {
debug('aborted', self.uri.href)
- response.resume()
+ !self.streams2 && response.resume()
return
}
- if (self._paused) response.pause()
- else response.resume()
+ if (!self.streams2) {
+ if (self._paused) response.pause()
+ else response.resume()
+ }
self.response = response
response.request = self
@@ -737,7 +743,7 @@ Request.prototype.onResponse = function (response) {
// ignore any potential response body. it cannot possibly be useful
// to us at this point.
- if (self._paused) response.resume()
+ if (self._paused && !self.streams2) response.resume()
if (self._redirectsFollowed >= self.maxRedirects) {
self.emit('error', new Error("Exceeded maxRedirects. Probably stuck in a redirect loop "+self.uri.href))
@@ -801,10 +807,12 @@ Request.prototype.onResponse = function (response) {
self.pipeDest(dest)
})
- response.on("data", function (chunk) {
- self._destdata = true
- self.emit("data", chunk)
- })
+ if (!self.streams2) {
+ response.on("data", function (chunk) {
+ self._destdata = true
+ self.emit("data", chunk)
+ })
+ }
response.on("end", function (chunk) {
self._ended = true
self.emit("end", chunk)
@@ -968,10 +976,10 @@ Request.prototype.multipart = function (multipart) {
Request.prototype.json = function (val) {
var self = this;
var setAcceptHeader = function() {
- if (!self.headers['accept'] && !self.headers['Accept']) {
- self.setHeader('accept', 'application/json')
- }
- }
+ if (!self.headers['accept'] && !self.headers['Accept']) {
+ self.setHeader('accept', 'application/json')
+ }
+ }
setAcceptHeader();
this._json = true
if (typeof val === 'boolean') {
Something went wrong with that request. Please try again.