| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library utils; | 5 library utils; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:uri'; | 8 import 'dart:uri'; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 import 'dart:crypto'; | 10 import 'dart:crypto'; |
| 11 | 11 |
| 12 /// Adds additional query parameters to [url], overwriting the original | 12 /// Adds additional query parameters to [url], overwriting the original |
| 13 /// parameters if a name conflict occurs. | 13 /// parameters if a name conflict occurs. |
| 14 Uri addQueryParameters(Uri url, Map<String, String> parameters) { | 14 Uri addQueryParameters(Uri url, Map<String, String> parameters) { |
| 15 var queryMap = queryToMap(url.query); | 15 var queryMap = queryToMap(url.query); |
| 16 mapAddAll(queryMap, parameters); | 16 mapAddAll(queryMap, parameters); |
| 17 return url.resolve("?${mapToQuery(queryMap)}"); | 17 return url.resolve("?${mapToQuery(queryMap)}"); |
| 18 } | 18 } |
| 19 | 19 |
| 20 /// Convert a URL query string (or `application/x-www-form-urlencoded` body) | 20 /// Convert a URL query string (or `application/x-www-form-urlencoded` body) |
| 21 /// into a [Map] from parameter names to values. | 21 /// into a [Map] from parameter names to values. |
| 22 Map<String, String> queryToMap(String queryList) { | 22 Map<String, String> queryToMap(String queryList) { |
| 23 var map = <String, String>{}; | 23 var map = {}; |
| 24 for (var pair in queryList.split("&")) { | 24 for (var pair in queryList.split("&")) { |
| 25 var split = split1(pair, "="); | 25 var split = split1(pair, "="); |
| 26 if (split.isEmpty) continue; | 26 if (split.isEmpty) continue; |
| 27 var key = urlDecode(split[0]); | 27 var key = urlDecode(split[0]); |
| 28 var value = split.length > 1 ? urlDecode(split[1]) : ""; | 28 var value = split.length > 1 ? urlDecode(split[1]) : ""; |
| 29 map[key] = value; | 29 map[key] = value; |
| 30 } | 30 } |
| 31 return map; | 31 return map; |
| 32 } | 32 } |
| 33 | 33 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 if (!paramString.trim().isEmpty) { | 107 if (!paramString.trim().isEmpty) { |
| 108 throw new FormatException('Invalid WWW-Authenticate header: "$header"'); | 108 throw new FormatException('Invalid WWW-Authenticate header: "$header"'); |
| 109 } | 109 } |
| 110 | 110 |
| 111 return new AuthenticateHeader(scheme, parameters); | 111 return new AuthenticateHeader(scheme, parameters); |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 | 114 |
| 115 /// Returns a [Future] that asynchronously completes to `null`. | 115 /// Returns a [Future] that asynchronously completes to `null`. |
| 116 Future get async => new Future.delayed(0, () => null); | 116 Future get async => new Future.delayed(0, () => null); |
| OLD | NEW |