Skip to content

Commit

Permalink
Ignore requests without "url" property
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Jan 30, 2018
1 parent 061f378 commit 06e69b1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions HISTORY.md
@@ -1,6 +1,7 @@
unreleased
==========

* Ignore requests without `url` property
* deps: ms@2.1.1
- Add `week`
- Add `w`
Expand Down
17 changes: 16 additions & 1 deletion index.js
Expand Up @@ -64,7 +64,7 @@ function favicon (path, options) {
}

return function favicon (req, res, next) {
if (parseUrl(req).pathname !== '/favicon.ico') {
if (getPathname(req) !== '/favicon.ico') {
next()
return
}
Expand Down Expand Up @@ -144,6 +144,21 @@ function createIsDirError (path) {
return error
}

/**
* Get the request pathname.
*
* @param {object} req
* @return {string}
*/

function getPathname (req) {
try {
return parseUrl(req).pathname
} catch (e) {
return undefined
}
}

/**
* Determine if the cached representation is fresh.
*
Expand Down
7 changes: 7 additions & 0 deletions test/test.js
Expand Up @@ -183,6 +183,13 @@ describe('favicon()', function () {
.expect('Content-Type', 'image/x-icon')
.expect(200, done)
})

describe('missing req.url', function () {
it('should ignore the request', function (done) {
var fn = favicon(ICON_PATH)
fn({}, {}, done)
})
})
})

describe('icon', function () {
Expand Down

0 comments on commit 06e69b1

Please sign in to comment.