Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Unified Diff: sdk/lib/io/http_impl.dart

Issue 14988003: Support redirect to relative Uri, as specified by rfc3986#4.2. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Test for only-domain-missing, paths with '..', and simplify tests. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/standalone/io/http_redirect_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/http_impl.dart
diff --git a/sdk/lib/io/http_impl.dart b/sdk/lib/io/http_impl.dart
index e3e49450c67280e42e7432e8b3dcd5968faf4cd8..8ea7174e6a3040eb1135f88c507448b48d051a64 100644
--- a/sdk/lib/io/http_impl.dart
+++ b/sdk/lib/io/http_impl.dart
@@ -1412,6 +1412,29 @@ class _HttpClient implements HttpClient {
Future<HttpClientRequest> _openUrlFromRequest(String method,
Uri uri,
_HttpClientRequest previous) {
+ // If the new URI is relative (to either '/' or some sub-path),
+ // construct a full URI from the previous one.
+ // See http://tools.ietf.org/html/rfc3986#section-4.2
+ replaceComponents({scheme, domain, port, path}) {
+ uri = new Uri.fromComponents(
+ scheme: scheme != null ? scheme : uri.scheme,
+ domain: domain != null ? domain : uri.domain,
+ port: port != null ? port : uri.port,
+ path: path != null ? path : uri.path,
+ query: uri.query,
+ fragment: uri.fragment);
+ }
+ if (uri.domain == '') {
+ replaceComponents(domain: previous.uri.domain, port: previous.uri.port);
+ }
+ if (uri.scheme == '') {
+ replaceComponents(scheme: previous.uri.scheme);
+ }
+ if (!uri.path.startsWith('/') && previous.uri.path.startsWith('/')) {
+ var absolute = new Path.raw(previous.uri.path).directoryPath;
+ absolute = absolute.join(new Path.raw(uri.path));
+ replaceComponents(path: absolute.canonicalize().toString());
+ }
return openUrl(method, uri).then((_HttpClientRequest request) {
// Only follow redirects if initial request did.
request.followRedirects = previous.followRedirects;
« no previous file with comments | « no previous file | tests/standalone/io/http_redirect_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698