Chromium Code Reviews| Index: sdk/lib/core/uri.dart |
| diff --git a/sdk/lib/core/uri.dart b/sdk/lib/core/uri.dart |
| index c0a7fdf9f5d2d3623c816a15d502116374085a00..ae20ee54e69182b2c113639765130f39b1ce6e41 100644 |
| --- a/sdk/lib/core/uri.dart |
| +++ b/sdk/lib/core/uri.dart |
| @@ -178,6 +178,84 @@ class Uri { |
| } |
| /** |
| + * Create a new `http` URI with authority, path and query. |
|
floitsch
2013/06/17 14:29:01
Creates
Søren Gjesse
2013/06/18 06:05:34
Done.
|
| + * |
| + * // Create the URI http://example.org/path?q=abc. |
| + * Uri uri = new Uri.http("example.org", "/path", { "q" : "abc" }); |
| + * |
| + * The `scheme` is always set to `http`. |
| + * |
| + * The `userInfo`, `host` and `port` components are set from the |
| + * [authority] argument. |
| + * |
| + * The `path` component is set from the [unencodedPath] |
| + * argument. The path passed should not be encoded as this |
|
floitsch
2013/06/17 14:29:01
must not
Søren Gjesse
2013/06/18 06:05:34
Done.
|
| + * constructor will encode the path. |
|
floitsch
2013/06/17 14:29:01
encodes
Søren Gjesse
2013/06/18 06:05:34
Done.
|
| + * |
| + * The `query` component is set from the [queryParameters] argument. |
|
floitsch
2013/06/17 14:29:01
from the optional
Søren Gjesse
2013/06/18 06:05:34
Done.
|
| + */ |
|
floitsch
2013/06/17 14:29:01
Maybe add some examples. In particular showing wha
floitsch
2013/06/17 14:31:34
Also add example with space in path.
Søren Gjesse
2013/06/18 06:05:34
Done.
Søren Gjesse
2013/06/18 06:05:34
Done.
|
| + factory Uri.http(String authority, |
| + String unencodedPath, |
| + [Map<String, String> queryParameters]) { |
| + return _makeHttpUri("http", authority, unencodedPath, queryParameters); |
| + } |
| + |
| + /** |
| + * Create a new `https` URI with authority, path and query. |
|
floitsch
2013/06/17 14:29:01
Creates
Søren Gjesse
2013/06/18 06:05:34
Done.
|
| + * |
| + * See [Uri.http] constructor for information on the arguments. |
|
floitsch
2013/06/17 14:29:01
This constructor is the same as [Uri.http] except
Søren Gjesse
2013/06/18 06:05:34
Done.
|
| + */ |
| + factory Uri.https(String authority, |
| + String unencodedPath, |
| + [Map<String, String> queryParameters]) { |
| + return _makeHttpUri("https", authority, unencodedPath, queryParameters); |
| + } |
| + |
| + static Uri _makeHttpUri(String scheme, |
| + String authority, |
| + String unencodedPath, |
| + Map<String, String> queryParameters) { |
| + var userInfo = ""; |
| + var host = ""; |
| + var port = 0; |
| + |
| + var hostStart = 0; |
| + // Split off the user info. |
| + bool hasUserInfo = false; |
| + for (int i = 0; i < authority.length; i++) { |
| + if (authority.codeUnitAt(i) == _AT_SIGN) { |
| + hasUserInfo = true; |
| + userInfo = authority.substring(0, i); |
| + hostStart = i + 1; |
| + break; |
| + } |
| + } |
| + // Split host and port. |
| + bool hasPort = false; |
| + for (int i = hostStart; i < authority.length; i++) { |
| + if (authority.codeUnitAt(i) == _COLON) { |
| + hasPort = true; |
| + host = authority.substring(hostStart, i); |
| + if (!host.isEmpty) { |
| + var portString = authority.substring(i + 1); |
| + if (portString.isNotEmpty) port = int.parse(portString); |
| + } |
| + break; |
| + } |
| + } |
| + if (!hasPort) { |
| + host = hasUserInfo ? authority.substring(hostStart) : authority; |
| + } |
| + |
| + return new Uri(scheme: scheme, |
| + userInfo: userInfo, |
| + host: host, |
| + port: port, |
| + pathSegments: unencodedPath.split("/"), |
| + queryParameters: queryParameters); |
| + } |
| + |
| + /** |
| * Returns the URI path split into its segments. Each of the |
| * segments in the returned list have been decoded. If the path is |
| * empty the empty list will be returned. A leading slash `/` does |
| @@ -746,6 +824,7 @@ class Uri { |
| static const int _ZERO = 0x30; |
| static const int _NINE = 0x39; |
| static const int _COLON = 0x3A; |
| + static const int _AT_SIGN = 0x40; |
| static const int _UPPER_CASE_A = 0x41; |
| static const int _UPPER_CASE_F = 0x46; |
| static const int _LOWER_CASE_A = 0x61; |