Skip to content

Decode npm-notice heder according to the rfc2047 rule. #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

### ⚠ BREAKING CHANGES

* Decode `npm-notice` heder according to the rfc2047 rule.

### Dependencies
* add rfc2047

### [13.1.1](https://github.com/npm/npm-registry-fetch/compare/v13.1.0...v13.1.1) (2022-04-13)


Expand Down
8 changes: 7 additions & 1 deletion lib/check-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ const { Response } = require('minipass-fetch')
const defaultOpts = require('./default-opts.js')
const log = require('proc-log')
const cleanUrl = require('./clean-url.js')
const rfc2047 = require('rfc2047')

/* eslint-disable-next-line max-len */
const moreInfoUrl = 'https://github.com/npm/cli/wiki/No-auth-for-URI,-but-auth-present-for-scoped-registry'
const checkResponse =
async ({ method, uri, res, startTime, auth, opts }) => {
opts = { ...defaultOpts, ...opts }
if (res.headers.has('npm-notice') && !res.headers.has('x-local-cache')) {
log.notice('', res.headers.get('npm-notice'))
let notice = res.headers.get('npm-notice')
try {
notice = rfc2047.decode(notice)
} catch {
}
log.notice('', notice)
}

if (res.status >= 400) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"minipass-json-stream": "^1.0.1",
"minizlib": "^2.1.2",
"npm-package-arg": "^9.0.1",
"proc-log": "^2.0.0"
"proc-log": "^2.0.0",
"rfc2047": "^4.0.1"
},
"devDependencies": {
"@npmcli/eslint-config": "^3.0.1",
Expand Down
21 changes: 21 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,27 @@ t.test('npm-notice header logging', async t => {
t.equal(msg, 'npm <3 u', 'logged out npm-notice at NOTICE level')
})

t.test('npm-notice encoded header logging', async t => {
tnock(t, defaultOpts.registry)
.get('/hello')
.reply(200, { hello: 'world' }, {
'npm-notice': 'npm=?utf-8?Q?_=E2=98=BA?=',
})

let header, msg
process.on('log', (level, ...args) => {
if (level === 'notice') {
;[header, msg] = args
}
})

t.plan(3)
const res = await fetch('/hello', { ...OPTS })
t.equal(res.status, 200, 'got successful response')
t.equal(header, '', 'empty log header thing')
t.equal(msg, 'npm ☺', 'logged out npm-notice at NOTICE level')
})

t.test('optionally verifies request body integrity', t => {
t.plan(3)
tnock(t, defaultOpts.registry)
Expand Down