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

Side by Side 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: Addressed review comments Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/http.dart ('k') | tests/standalone/io/http_redirect_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.io; 5 part of dart.io;
6 6
7 class _HttpIncoming extends Stream<List<int>> { 7 class _HttpIncoming extends Stream<List<int>> {
8 final int _transferLength; 8 final int _transferLength;
9 final Completer _dataCompleter = new Completer(); 9 final Completer _dataCompleter = new Completer();
10 Stream<List<int>> _stream; 10 Stream<List<int>> _stream;
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 if (_cookies == null) _cookies = new List<Cookie>(); 701 if (_cookies == null) _cookies = new List<Cookie>();
702 return _cookies; 702 return _cookies;
703 } 703 }
704 704
705 String get reasonPhrase => _findReasonPhrase(statusCode); 705 String get reasonPhrase => _findReasonPhrase(statusCode);
706 void set reasonPhrase(String reasonPhrase) { 706 void set reasonPhrase(String reasonPhrase) {
707 if (_headersWritten) throw new StateError("Header already sent"); 707 if (_headersWritten) throw new StateError("Header already sent");
708 _reasonPhrase = reasonPhrase; 708 _reasonPhrase = reasonPhrase;
709 } 709 }
710 710
711 Future redirect(Uri location, {int status: HttpStatus.MOVED_TEMPORARILY}) {
712 if (_headersWritten) throw new StateError("Header already sent");
713 statusCode = status;
714 headers.set("Location", location.toString());
715 return close();
716 }
717
711 Future<Socket> detachSocket() { 718 Future<Socket> detachSocket() {
712 if (_headersWritten) throw new StateError("Headers already sent"); 719 if (_headersWritten) throw new StateError("Headers already sent");
713 deadline = null; // Be sure to stop any deadline. 720 deadline = null; // Be sure to stop any deadline.
714 var future = _httpRequest._httpConnection.detachSocket(); 721 var future = _httpRequest._httpConnection.detachSocket();
715 _writeHeaders(drainRequest: false).then((_) => close()); 722 _writeHeaders(drainRequest: false).then((_) => close());
716 // Close connection so the socket is 'free'. 723 // Close connection so the socket is 'free'.
717 close(); 724 close();
718 done.catchError((_) { 725 done.catchError((_) {
719 // Catch any error on done, as they automatically will be 726 // Catch any error on done, as they automatically will be
720 // propagated to the websocket. 727 // propagated to the websocket.
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 int backlog, 1908 int backlog,
1902 String certificate_name, 1909 String certificate_name,
1903 bool requestClientCertificate) { 1910 bool requestClientCertificate) {
1904 return SecureServerSocket.bind( 1911 return SecureServerSocket.bind(
1905 address, 1912 address,
1906 port, 1913 port,
1907 certificate_name, 1914 certificate_name,
1908 backlog: backlog, 1915 backlog: backlog,
1909 requestClientCertificate: requestClientCertificate) 1916 requestClientCertificate: requestClientCertificate)
1910 .then((socket) { 1917 .then((socket) {
1911 return new _HttpServer._(socket, true); 1918 return new _HttpServer._(socket, true);
1912 }); 1919 });
1913 } 1920 }
1914 1921
1915 _HttpServer._(this._serverSocket, this._closeServer) { 1922 _HttpServer._(this._serverSocket, this._closeServer) {
1916 _controller = new StreamController<HttpRequest>(sync: true, 1923 _controller = new StreamController<HttpRequest>(sync: true,
1917 onCancel: close); 1924 onCancel: close);
1918 } 1925 }
1919 1926
1920 _HttpServer.listenOn(ServerSocket this._serverSocket) 1927 _HttpServer.listenOn(ServerSocket this._serverSocket)
1921 : _closeServer = false { 1928 : _closeServer = false {
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
2424 final Uri location; 2431 final Uri location;
2425 } 2432 }
2426 2433
2427 String _getHttpVersion() { 2434 String _getHttpVersion() {
2428 var version = Platform.version; 2435 var version = Platform.version;
2429 // Only include major and minor version numbers. 2436 // Only include major and minor version numbers.
2430 int index = version.indexOf('.', version.indexOf('.') + 1); 2437 int index = version.indexOf('.', version.indexOf('.') + 1);
2431 version = version.substring(0, index); 2438 version = version.substring(0, index);
2432 return 'Dart/$version (dart:io)'; 2439 return 'Dart/$version (dart:io)';
2433 } 2440 }
OLDNEW
« no previous file with comments | « sdk/lib/io/http.dart ('k') | tests/standalone/io/http_redirect_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698