Chromium Code Reviews| 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); |
| } |