File tree Expand file tree Collapse file tree 2 files changed +38
-8
lines changed
Expand file tree Collapse file tree 2 files changed +38
-8
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ unreleased
22==========
33
44 * Fix regression matching multiple ETags in ` If-None-Match `
5+ * perf: improve ` If-None-Match ` token parsing
56
670.5.1 / 2017-09-11
78==================
Original file line number Diff line number Diff line change 1414
1515var CACHE_CONTROL_NO_CACHE_REGEXP = / (?: ^ | , ) \s * ?n o - c a c h e \s * ?(?: , | $ ) /
1616
17- /**
18- * Simple expression to split token list.
19- * @private
20- */
21-
22- var TOKEN_LIST_REGEXP = / * , * /
23-
2417/**
2518 * Module exports.
2619 * @public
@@ -64,7 +57,7 @@ function fresh (reqHeaders, resHeaders) {
6457 }
6558
6659 var etagStale = true
67- var matches = noneMatch . split ( TOKEN_LIST_REGEXP )
60+ var matches = parseTokenList ( noneMatch )
6861 for ( var i = 0 ; i < matches . length ; i ++ ) {
6962 var match = matches [ i ]
7063 if ( match === etag || match === 'W/' + etag || 'W/' + match === etag ) {
@@ -106,3 +99,39 @@ function parseHttpDate (date) {
10699 ? timestamp
107100 : NaN
108101}
102+
103+ /**
104+ * Parse a HTTP token list.
105+ *
106+ * @param {string } str
107+ * @private
108+ */
109+
110+ function parseTokenList ( str ) {
111+ var end = 0
112+ var list = [ ]
113+ var start = 0
114+
115+ // gather tokens
116+ for ( var i = 0 , len = str . length ; i < len ; i ++ ) {
117+ switch ( str . charCodeAt ( i ) ) {
118+ case 0x20 : /* */
119+ if ( start === end ) {
120+ start = end = i + 1
121+ }
122+ break
123+ case 0x2c : /* , */
124+ list . push ( str . substring ( start , end ) )
125+ start = end = i + 1
126+ break
127+ default :
128+ end = i + 1
129+ break
130+ }
131+ }
132+
133+ // final token
134+ list . push ( str . substring ( start , end ) )
135+
136+ return list
137+ }
You can’t perform that action at this time.
0 commit comments