Simplify implementation of auth header parsing

This commit is contained in:
Zaid Abdulla committed 2017-03-04 01:38:32 -08:00
1 parent ab26ff2058
commit 0788b93350
1 file changed
+4 -12
+4 -12
View File
@@ -19,18 +19,10 @@ crypto = require 'crypto'
exports.parseAuthHeader = (authHeader) -> exports.parseAuthHeader = (authHeader) ->
res = {} res = {method: authHeader.slice(0, authHeader.indexOf(' '))}
i = authHeader.indexOf(' ') re = /([a-z0-9_-]+)=(?:"([^"]+)"|([a-z0-9_-]+))/gi
res['method'] = authHeader.slice(0, i) while match = re.exec(authHeader)
res[match[1]] = match[2] or match[3]
options = authHeader.slice(i + 1)
regex = /([a-z]+)="([a-zA-Z0-9\/\.@\-\+,= ]+)"/g
while (r = regex.exec(options)) != null
res[r[1]] = r[2]
regex = /([a-z]+)=([a-zA-Z0-9\/\.@\-\+]+)/g
while (r = regex.exec(options)) != null
res[r[1]] = r[2]
return res return res