Skip to content

Commit c8a4e95

Browse files
committed
perf: hoist regular expression
1 parent 993e00f commit c8a4e95

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
unreleased
2+
==========
3+
4+
* perf: hoist regular expression
5+
16
1.0.1 / 2015-05-04
27
==================
38

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212

1313
module.exports = auth
1414

15+
/**
16+
* RegExp for basic auth user/pass
17+
*/
18+
19+
var userPassRegExp = /^([^:]*):(.*)$/
20+
1521
/**
1622
* Parse the Authorization header field of a request.
1723
*
@@ -34,7 +40,7 @@ function auth(req) {
3440

3541
// credentials
3642
auth = new Buffer(auth, 'base64').toString();
37-
auth = auth.match(/^([^:]*):(.*)$/);
43+
auth = auth.match(userPassRegExp)
3844
if (!auth) return;
3945

4046
return { name: auth[1], pass: auth[2] };

0 commit comments

Comments
 (0)