Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
request: fixed npm-notice functionality
Browse files Browse the repository at this point in the history
PR-URL: #119
  • Loading branch information
Benjamin Coe authored and zkat committed Sep 17, 2015
1 parent a42ca70 commit 9f0cfda
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ function regRequest (uri, params, cb_) {
var self = this
this.attempt(function (operation) {
makeRequest.call(self, uri, params, function (er, parsed, raw, response) {
if (response) {
self.log.verbose('headers', response.headers)
if (response.headers['npm-notice']) {
self.log.warn('notice', response.headers['npm-notice'])
}
}

if (!er || (er.message && er.message.match(/^SSL Error/))) {
if (er) er.code = 'ESSL'
return cb(er, parsed, raw, response)
Expand All @@ -79,12 +86,6 @@ function regRequest (uri, params, cb_) {
self.log.info('retry', 'will retry, error on last attempt: ' + er)
return undefined
}
if (response) {
self.log.verbose('headers', response.headers)
if (response.headers['npm-notice']) {
self.log.warn('notice', response.headers['npm-notice'])
}
}
cb.apply(null, arguments)
})
})
Expand Down
34 changes: 34 additions & 0 deletions test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,40 @@ test('run request through its paces', function (t) {
})
})

test('outputs notice if npm-notice header is set', function (t) {
var client = common.freshClient({
log: {
error: noop,
warn: function (prefix, msg) {
warnings.push(msg)
},
info: noop,
verbose: noop,
silly: noop,
http: noop,
pause: noop,
resume: noop
}
})
var message = 'notice me!'
var warnings = []

function noop () {}

server.expect('GET', '/npm-notice', function (req, res) {
req.pipe(concat(function () {
res.statusCode = 200
res.setHeader('npm-notice', message)
res.end()
}))
})

client.request(common.registry + '/npm-notice', {}, function (er) {
t.notEqual(warnings.indexOf(message), -1, 'notice not printed')
t.end()
})
})

test('cleanup', function (t) {
server.close()
t.end()
Expand Down

0 comments on commit 9f0cfda

Please sign in to comment.