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

Commit 9f0cfda

Browse files
Benjamin Coezkat
authored andcommitted
request: fixed npm-notice functionality
PR-URL: #119
1 parent a42ca70 commit 9f0cfda

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

lib/request.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ function regRequest (uri, params, cb_) {
6464
var self = this
6565
this.attempt(function (operation) {
6666
makeRequest.call(self, uri, params, function (er, parsed, raw, response) {
67+
if (response) {
68+
self.log.verbose('headers', response.headers)
69+
if (response.headers['npm-notice']) {
70+
self.log.warn('notice', response.headers['npm-notice'])
71+
}
72+
}
73+
6774
if (!er || (er.message && er.message.match(/^SSL Error/))) {
6875
if (er) er.code = 'ESSL'
6976
return cb(er, parsed, raw, response)
@@ -79,12 +86,6 @@ function regRequest (uri, params, cb_) {
7986
self.log.info('retry', 'will retry, error on last attempt: ' + er)
8087
return undefined
8188
}
82-
if (response) {
83-
self.log.verbose('headers', response.headers)
84-
if (response.headers['npm-notice']) {
85-
self.log.warn('notice', response.headers['npm-notice'])
86-
}
87-
}
8889
cb.apply(null, arguments)
8990
})
9091
})

test/request.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,40 @@ test('run request through its paces', function (t) {
277277
})
278278
})
279279

280+
test('outputs notice if npm-notice header is set', function (t) {
281+
var client = common.freshClient({
282+
log: {
283+
error: noop,
284+
warn: function (prefix, msg) {
285+
warnings.push(msg)
286+
},
287+
info: noop,
288+
verbose: noop,
289+
silly: noop,
290+
http: noop,
291+
pause: noop,
292+
resume: noop
293+
}
294+
})
295+
var message = 'notice me!'
296+
var warnings = []
297+
298+
function noop () {}
299+
300+
server.expect('GET', '/npm-notice', function (req, res) {
301+
req.pipe(concat(function () {
302+
res.statusCode = 200
303+
res.setHeader('npm-notice', message)
304+
res.end()
305+
}))
306+
})
307+
308+
client.request(common.registry + '/npm-notice', {}, function (er) {
309+
t.notEqual(warnings.indexOf(message), -1, 'notice not printed')
310+
t.end()
311+
})
312+
})
313+
280314
test('cleanup', function (t) {
281315
server.close()
282316
t.end()

0 commit comments

Comments
 (0)