Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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(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.
| |
| 712 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.
| |
| 713 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.
| |
| 714 if (!location.isAbsolute) { | |
| 715 Uri base = | |
| 716 new Uri(scheme: _httpRequest._httpServer._secure ? "https" : "http", | |
| 717 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.
| |
| 718 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.
| |
| 719 path: _uri.path); | |
| 720 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.
| |
| 721 location = base.resolveUri(location); | |
| 722 } | |
| 723 statusCode = status; | |
| 724 headers.set("Location", location.toString()); | |
| 725 return close(); | |
| 726 } | |
| 727 | |
| 711 Future<Socket> detachSocket() { | 728 Future<Socket> detachSocket() { |
| 712 if (_headersWritten) throw new StateError("Headers already sent"); | 729 if (_headersWritten) throw new StateError("Headers already sent"); |
| 713 deadline = null; // Be sure to stop any deadline. | 730 deadline = null; // Be sure to stop any deadline. |
| 714 var future = _httpRequest._httpConnection.detachSocket(); | 731 var future = _httpRequest._httpConnection.detachSocket(); |
| 715 _writeHeaders(drainRequest: false).then((_) => close()); | 732 _writeHeaders(drainRequest: false).then((_) => close()); |
| 716 // Close connection so the socket is 'free'. | 733 // Close connection so the socket is 'free'. |
| 717 close(); | 734 close(); |
| 718 done.catchError((_) { | 735 done.catchError((_) { |
| 719 // Catch any error on done, as they automatically will be | 736 // Catch any error on done, as they automatically will be |
| 720 // propagated to the websocket. | 737 // propagated to the websocket. |
| (...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1882 bool get _isActive => _state == _ACTIVE; | 1899 bool get _isActive => _state == _ACTIVE; |
| 1883 bool get _isIdle => _state == _IDLE; | 1900 bool get _isIdle => _state == _IDLE; |
| 1884 bool get _isClosing => _state == _CLOSING; | 1901 bool get _isClosing => _state == _CLOSING; |
| 1885 bool get _isDetached => _state == _DETACHED; | 1902 bool get _isDetached => _state == _DETACHED; |
| 1886 } | 1903 } |
| 1887 | 1904 |
| 1888 | 1905 |
| 1889 // HTTP server waiting for socket connections. | 1906 // HTTP server waiting for socket connections. |
| 1890 class _HttpServer extends Stream<HttpRequest> implements HttpServer { | 1907 class _HttpServer extends Stream<HttpRequest> implements HttpServer { |
| 1891 String serverHeader = _getHttpVersion(); | 1908 String serverHeader = _getHttpVersion(); |
| 1909 var _address; | |
| 1910 bool _secure; | |
| 1892 | 1911 |
| 1893 static Future<HttpServer> bind(address, int port, int backlog) { | 1912 static Future<HttpServer> bind(address, int port, int backlog) { |
| 1894 return ServerSocket.bind(address, port, backlog: backlog).then((socket) { | 1913 return ServerSocket.bind(address, port, backlog: backlog).then((socket) { |
| 1895 return new _HttpServer._(socket, true); | 1914 return new _HttpServer._(address, socket, true, false); |
| 1896 }); | 1915 }); |
| 1897 } | 1916 } |
| 1898 | 1917 |
| 1899 static Future<HttpServer> bindSecure(address, | 1918 static Future<HttpServer> bindSecure(address, |
| 1900 int port, | 1919 int port, |
| 1901 int backlog, | 1920 int backlog, |
| 1902 String certificate_name, | 1921 String certificate_name, |
| 1903 bool requestClientCertificate) { | 1922 bool requestClientCertificate) { |
| 1904 return SecureServerSocket.bind( | 1923 return SecureServerSocket.bind( |
| 1905 address, | 1924 address, |
| 1906 port, | 1925 port, |
| 1907 certificate_name, | 1926 certificate_name, |
| 1908 backlog: backlog, | 1927 backlog: backlog, |
| 1909 requestClientCertificate: requestClientCertificate) | 1928 requestClientCertificate: requestClientCertificate) |
| 1910 .then((socket) { | 1929 .then((socket) { |
| 1911 return new _HttpServer._(socket, true); | 1930 return new _HttpServer._(address, socket, true, true); |
| 1912 }); | 1931 }); |
| 1913 } | 1932 } |
| 1914 | 1933 |
| 1915 _HttpServer._(this._serverSocket, this._closeServer) { | 1934 _HttpServer._(this._address, |
| 1935 this._serverSocket, | |
| 1936 this._closeServer, | |
| 1937 this._secure) { | |
| 1916 _controller = new StreamController<HttpRequest>(sync: true, | 1938 _controller = new StreamController<HttpRequest>(sync: true, |
| 1917 onCancel: close); | 1939 onCancel: close); |
| 1918 } | 1940 } |
| 1919 | 1941 |
| 1920 _HttpServer.listenOn(ServerSocket this._serverSocket) | 1942 _HttpServer.listenOn(ServerSocket this._serverSocket) |
| 1921 : _closeServer = false { | 1943 : _closeServer = false { |
| 1922 _controller = new StreamController<HttpRequest>(sync: true, | 1944 _controller = new StreamController<HttpRequest>(sync: true, |
| 1923 onCancel: close); | 1945 onCancel: close); |
| 1924 } | 1946 } |
| 1925 | 1947 |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2424 final Uri location; | 2446 final Uri location; |
| 2425 } | 2447 } |
| 2426 | 2448 |
| 2427 String _getHttpVersion() { | 2449 String _getHttpVersion() { |
| 2428 var version = Platform.version; | 2450 var version = Platform.version; |
| 2429 // Only include major and minor version numbers. | 2451 // Only include major and minor version numbers. |
| 2430 int index = version.indexOf('.', version.indexOf('.') + 1); | 2452 int index = version.indexOf('.', version.indexOf('.') + 1); |
| 2431 version = version.substring(0, index); | 2453 version = version.substring(0, index); |
| 2432 return 'Dart/$version (dart:io)'; | 2454 return 'Dart/$version (dart:io)'; |
| 2433 } | 2455 } |
| OLD | NEW |