OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:collection'; | 5 import 'dart:collection'; |
6 | 6 |
7 import 'package:string_scanner/string_scanner.dart'; | 7 import 'package:string_scanner/string_scanner.dart'; |
8 | 8 |
9 import 'case_insensitive_map.dart'; | 9 import 'case_insensitive_map.dart'; |
10 import 'scan.dart'; | 10 import 'scan.dart'; |
(...skipping 24 matching lines...) Expand all Loading... |
35 /// Throws a [FormatException] if the header is invalid. | 35 /// Throws a [FormatException] if the header is invalid. |
36 static List<AuthenticationChallenge> parseHeader(String header) { | 36 static List<AuthenticationChallenge> parseHeader(String header) { |
37 return wrapFormatException("authentication header", header, () { | 37 return wrapFormatException("authentication header", header, () { |
38 var scanner = new StringScanner(header); | 38 var scanner = new StringScanner(header); |
39 scanner.scan(whitespace); | 39 scanner.scan(whitespace); |
40 var challenges = parseList(scanner, () { | 40 var challenges = parseList(scanner, () { |
41 var scheme = _scanScheme(scanner, whitespaceName: '" " or "="'); | 41 var scheme = _scanScheme(scanner, whitespaceName: '" " or "="'); |
42 | 42 |
43 // Manually parse the inner list. We need to do some lookahead to | 43 // Manually parse the inner list. We need to do some lookahead to |
44 // disambiguate between an auth param and another challenge. | 44 // disambiguate between an auth param and another challenge. |
45 var params = {}; | 45 var params = <String, String>{}; |
46 | 46 |
47 // Consume initial empty values. | 47 // Consume initial empty values. |
48 while (scanner.scan(",")) { | 48 while (scanner.scan(",")) { |
49 scanner.scan(whitespace); | 49 scanner.scan(whitespace); |
50 } | 50 } |
51 | 51 |
52 _scanAuthParam(scanner, params); | 52 _scanAuthParam(scanner, params); |
53 | 53 |
54 var beforeComma = scanner.position; | 54 var beforeComma = scanner.position; |
55 while (scanner.scan(",")) { | 55 while (scanner.scan(",")) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 /// Parses a single WWW-Authenticate challenge value. | 93 /// Parses a single WWW-Authenticate challenge value. |
94 /// | 94 /// |
95 /// Throws a [FormatException] if the challenge is invalid. | 95 /// Throws a [FormatException] if the challenge is invalid. |
96 factory AuthenticationChallenge.parse(String challenge) { | 96 factory AuthenticationChallenge.parse(String challenge) { |
97 return wrapFormatException("authentication challenge", challenge, () { | 97 return wrapFormatException("authentication challenge", challenge, () { |
98 var scanner = new StringScanner(challenge); | 98 var scanner = new StringScanner(challenge); |
99 scanner.scan(whitespace); | 99 scanner.scan(whitespace); |
100 var scheme = _scanScheme(scanner); | 100 var scheme = _scanScheme(scanner); |
101 | 101 |
102 var params = {}; | 102 var params = <String, String>{}; |
103 parseList(scanner, () => _scanAuthParam(scanner, params)); | 103 parseList(scanner, () => _scanAuthParam(scanner, params)); |
104 | 104 |
105 scanner.expectDone(); | 105 scanner.expectDone(); |
106 return new AuthenticationChallenge(scheme, params); | 106 return new AuthenticationChallenge(scheme, params); |
107 }); | 107 }); |
108 } | 108 } |
109 | 109 |
110 /// Scans a single scheme name and asserts that it's followed by a space. | 110 /// Scans a single scheme name and asserts that it's followed by a space. |
111 /// | 111 /// |
112 /// If [whitespaceName] is passed, it's used as the name for exceptions thrown | 112 /// If [whitespaceName] is passed, it's used as the name for exceptions thrown |
(...skipping 29 matching lines...) Expand all Loading... |
142 } | 142 } |
143 | 143 |
144 scanner.scan(whitespace); | 144 scanner.scan(whitespace); |
145 } | 145 } |
146 | 146 |
147 /// Creates a new challenge value with [scheme] and [parameters]. | 147 /// Creates a new challenge value with [scheme] and [parameters]. |
148 AuthenticationChallenge(this.scheme, Map<String, String> parameters) | 148 AuthenticationChallenge(this.scheme, Map<String, String> parameters) |
149 : parameters = new UnmodifiableMapView( | 149 : parameters = new UnmodifiableMapView( |
150 new CaseInsensitiveMap.from(parameters)); | 150 new CaseInsensitiveMap.from(parameters)); |
151 } | 151 } |
OLD | NEW |