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

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

Issue 1281973004: Make HttpClient not send fragments as part of request. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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 | « sdk/lib/io/http.dart ('k') | tests/standalone/io/http_requested_uri_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 f06179b9dd4df7e6dde383b5965d797dd67833ac..49b6c7b46fc8f947dbb8b7ea43588e86c1d33f0b 100644
--- a/sdk/lib/io/http_impl.dart
+++ b/sdk/lib/io/http_impl.dart
@@ -791,13 +791,9 @@ class _HttpClientRequest extends _HttpOutboundMessage<HttpClientResponse>
// Generate the request URI starting from the path component.
String uriStartingFromPath() {
String result = uri.path;
- if (result.length == 0) result = "/";
- if (uri.query != "") {
- if (uri.fragment != "") {
- result = "${result}?${uri.query}#${uri.fragment}";
- } else {
- result = "${result}?${uri.query}";
- }
+ if (result.isEmpty) result = "/";
+ if (uri.hasQuery) {
+ result = "${result}?${uri.query}";
}
return result;
}
@@ -814,7 +810,7 @@ class _HttpClientRequest extends _HttpOutboundMessage<HttpClientResponse>
if (_httpClientConnection._proxyTunnel) {
return uriStartingFromPath();
} else {
- return uri.toString();
+ return uri.removeFragment().toString();
}
}
}
@@ -1702,9 +1698,26 @@ class _HttpClient implements HttpClient {
String host,
int port,
String path) {
- Uri uri = new Uri(scheme: "http", host: host, port: port).resolve(path);
- // TODO(sgjesse): The path set here can contain both query and
- // fragment. They should be cracked and set correctly.
+ const int hashMark = 0x23;
+ const int questionMark = 0x3f;
+ int fragmentStart = path.length;
+ int queryStart = path.length;
+ for (int i = path.length - 1; i >= 0; i--) {
+ var char = path.codeUnitAt(i);
+ if (char == hashMark) {
+ fragmentStart = i;
+ queryStart = i;
+ } else if (char == questionMark) {
+ queryStart = i;
+ }
+ }
+ String query = null;
+ if (queryStart < fragmentStart) {
+ query = path.substring(queryStart + 1, fragmentStart);
+ path = path.substring(0, queryStart);
+ }
+ Uri uri = new Uri(scheme: "http", host: host, port: port,
+ path: path, query: query);
return _openUrl(method, uri);
}
@@ -1772,6 +1785,9 @@ class _HttpClient implements HttpClient {
set findProxy(String f(Uri uri)) => _findProxy = f;
Future<HttpClientRequest> _openUrl(String method, Uri uri) {
+ // Ignore any fragments on the request URI.
+ uri = uri.removeFragment();
+
if (method == null) {
throw new ArgumentError(method);
}
« no previous file with comments | « sdk/lib/io/http.dart ('k') | tests/standalone/io/http_requested_uri_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698