Skip to content

Commit

Permalink
Hook into request's automatic setting of headers and statusCode
Browse files Browse the repository at this point in the history
  • Loading branch information
jhs committed Jan 2, 2012
1 parent cd62791 commit 64c95b0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ function Changes (opts) {
self.readable = true
self.writable = true

self.headers = {}
self.statusCode = null

opts = opts || {}
self.feed = opts.feed || null // "continuous" or "longpoll"
self.encoding = opts.encoding || 'utf8'
Expand All @@ -65,6 +68,15 @@ function Changes (opts) {
}


Changes.prototype.setHeader = function(key, val) {
var self = this
self.headers[key] = val
}

//
// Readable stream API
//

Changes.prototype.setEncoding = function(encoding) {
var self = this
self.encoding = encoding // TODO
Expand Down
16 changes: 14 additions & 2 deletions test/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ var couch = require('./couch')

couch.setup(test)

test('The Changes stream API', function(t) {
var feed = new follow.Changes

t.type(feed.statusCode, 'null', 'Changes has a .statusCode (initially null)')
t.type(feed.setHeader, 'function', 'Changes has a .setHeader() method')
t.type(feed.headers, 'object', 'Changes has a .headers object')
t.same(feed.headers, {}, 'Changes headers are initially empty')

t.end()
})

test('Readable Stream API', function(t) {
var feed = new follow.Changes

Expand Down Expand Up @@ -301,6 +312,9 @@ test('Feeds from couch', function(t) {
t.ok(req.response, 'The request object has its '+type+' response by now')

req.pipe(feed)

t.equal(feed.statusCode, 200, 'Upon piping from request, the statusCode is set')
t.ok('content-type' in feed.headers, 'Upon piping from request, feed has headers set')
}

function check_changes() {
Expand Down Expand Up @@ -334,5 +348,3 @@ test('Feeds from couch', function(t) {
}
})
})

// TODO: See if I can get request to copy the headers to me, and statusCode, etc. (see main.js line 397)

0 comments on commit 64c95b0

Please sign in to comment.