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

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

Issue 21411003: Add redirect method to HttpResponse (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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
Index: sdk/lib/io/http_impl.dart
diff --git a/sdk/lib/io/http_impl.dart b/sdk/lib/io/http_impl.dart
index 3af4000b2f300237c9b4346b3c006f582f1d6408..39ddc46e1e26133b98029c24e5caa98b5b006753 100644
--- a/sdk/lib/io/http_impl.dart
+++ b/sdk/lib/io/http_impl.dart
@@ -708,6 +708,23 @@ class _HttpResponse extends _HttpOutboundMessage<HttpResponse>
_reasonPhrase = reasonPhrase;
}
+ Future redirect(location, [int status = HttpStatus.MOVED_TEMPORARILY]) {
Anders Johnsen 2013/08/02 08:22:03 Add check for _headersWritten.
Søren Gjesse 2013/08/02 09:01:06 Done.
+ if (location is! String && location is !Uri) throw new ArgumentError();
Anders Johnsen 2013/08/02 08:22:03 "location is not a String or Uri". Could also be
Søren Gjesse 2013/08/02 09:01:06 Removed and changed type to Uri.
+ if (location is String) location =Uri.parse(location);
Anders Johnsen 2013/08/02 08:22:03 Nit: add space after =.
Bill Hesse 2013/08/02 08:27:36 = Uri.parse
Søren Gjesse 2013/08/02 09:01:06 Line removed.
Søren Gjesse 2013/08/02 09:01:06 Line removed.
+ if (!location.isAbsolute) {
+ Uri base =
+ new Uri(scheme: _httpRequest._httpServer._secure ? "https" : "http",
+ host: _httpRequest._httpServer._address,
Anders Johnsen 2013/08/02 08:22:03 Host field of request.
Bill Hesse 2013/08/02 08:27:36 _address can be either a String or an InternetAddr
Søren Gjesse 2013/08/02 09:01:06 Line removed.
Søren Gjesse 2013/08/02 09:01:06 Line removed.
+ port: _httpRequest._httpServer.port,
Anders Johnsen 2013/08/02 08:22:03 Port field of request.
Søren Gjesse 2013/08/02 09:01:06 Line removed.
+ path: _uri.path);
+ print(base);
Anders Johnsen 2013/08/02 08:22:03 No print ;)
Bill Hesse 2013/08/02 08:27:36 remove print statement.
Søren Gjesse 2013/08/02 09:01:06 Removed.
Søren Gjesse 2013/08/02 09:01:06 Done.
+ location = base.resolveUri(location);
+ }
+ statusCode = status;
+ headers.set("Location", location.toString());
+ return close();
+ }
+
Future<Socket> detachSocket() {
if (_headersWritten) throw new StateError("Headers already sent");
deadline = null; // Be sure to stop any deadline.
@@ -1889,10 +1906,12 @@ class _HttpConnection extends LinkedListEntry<_HttpConnection> {
// HTTP server waiting for socket connections.
class _HttpServer extends Stream<HttpRequest> implements HttpServer {
String serverHeader = _getHttpVersion();
+ var _address;
+ bool _secure;
static Future<HttpServer> bind(address, int port, int backlog) {
return ServerSocket.bind(address, port, backlog: backlog).then((socket) {
- return new _HttpServer._(socket, true);
+ return new _HttpServer._(address, socket, true, false);
});
}
@@ -1908,11 +1927,14 @@ class _HttpServer extends Stream<HttpRequest> implements HttpServer {
backlog: backlog,
requestClientCertificate: requestClientCertificate)
.then((socket) {
- return new _HttpServer._(socket, true);
+ return new _HttpServer._(address, socket, true, true);
});
}
- _HttpServer._(this._serverSocket, this._closeServer) {
+ _HttpServer._(this._address,
+ this._serverSocket,
+ this._closeServer,
+ this._secure) {
_controller = new StreamController<HttpRequest>(sync: true,
onCancel: close);
}

Powered by Google App Engine
This is Rietveld 408576698