Skip to content

Commit 06e69b1

Browse files
committed
Ignore requests without "url" property
1 parent 061f378 commit 06e69b1

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
unreleased
22
==========
33

4+
* Ignore requests without `url` property
45
* deps: ms@2.1.1
56
- Add `week`
67
- Add `w`

index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function favicon (path, options) {
6464
}
6565

6666
return function favicon (req, res, next) {
67-
if (parseUrl(req).pathname !== '/favicon.ico') {
67+
if (getPathname(req) !== '/favicon.ico') {
6868
next()
6969
return
7070
}
@@ -144,6 +144,21 @@ function createIsDirError (path) {
144144
return error
145145
}
146146

147+
/**
148+
* Get the request pathname.
149+
*
150+
* @param {object} req
151+
* @return {string}
152+
*/
153+
154+
function getPathname (req) {
155+
try {
156+
return parseUrl(req).pathname
157+
} catch (e) {
158+
return undefined
159+
}
160+
}
161+
147162
/**
148163
* Determine if the cached representation is fresh.
149164
*

test/test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ describe('favicon()', function () {
183183
.expect('Content-Type', 'image/x-icon')
184184
.expect(200, done)
185185
})
186+
187+
describe('missing req.url', function () {
188+
it('should ignore the request', function (done) {
189+
var fn = favicon(ICON_PATH)
190+
fn({}, {}, done)
191+
})
192+
})
186193
})
187194

188195
describe('icon', function () {

0 commit comments

Comments
 (0)