| 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 17 matching lines...) Expand all Loading... |
| 28 // the length of the massage body is not known due to transfer | 28 // the length of the massage body is not known due to transfer |
| 29 // codings. | 29 // codings. |
| 30 int get transferLength => _transferLength; | 30 int get transferLength => _transferLength; |
| 31 | 31 |
| 32 _HttpIncoming(_HttpHeaders this.headers, | 32 _HttpIncoming(_HttpHeaders this.headers, |
| 33 int this._transferLength, | 33 int this._transferLength, |
| 34 Stream<List<int>> this._stream) { | 34 Stream<List<int>> this._stream) { |
| 35 } | 35 } |
| 36 | 36 |
| 37 StreamSubscription<List<int>> listen(void onData(List<int> event), | 37 StreamSubscription<List<int>> listen(void onData(List<int> event), |
| 38 {void onError(AsyncError error), | 38 {void onError(error), |
| 39 void onDone(), | 39 void onDone(), |
| 40 bool cancelOnError}) { | 40 bool cancelOnError}) { |
| 41 return _stream.listen(onData, | 41 return _stream.listen(onData, |
| 42 onError: onError, | 42 onError: onError, |
| 43 onDone: onDone, | 43 onDone: onDone, |
| 44 cancelOnError: cancelOnError); | 44 cancelOnError: cancelOnError); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Is completed once all data have been received. | 47 // Is completed once all data have been received. |
| 48 Future get dataDone => _dataCompleter.future; | 48 Future get dataDone => _dataCompleter.future; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 _session = _httpServer._sessionManager.getSession(sessionId); | 99 _session = _httpServer._sessionManager.getSession(sessionId); |
| 100 if (_session != null) { | 100 if (_session != null) { |
| 101 _session._markSeen(); | 101 _session._markSeen(); |
| 102 break; | 102 break; |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 StreamSubscription<List<int>> listen(void onData(List<int> event), | 108 StreamSubscription<List<int>> listen(void onData(List<int> event), |
| 109 {void onError(AsyncError error), | 109 {void onError(error), |
| 110 void onDone(), | 110 void onDone(), |
| 111 bool cancelOnError}) { | 111 bool cancelOnError}) { |
| 112 return _incoming.listen(onData, | 112 return _incoming.listen(onData, |
| 113 onError: onError, | 113 onError: onError, |
| 114 onDone: onDone, | 114 onDone: onDone, |
| 115 cancelOnError: cancelOnError); | 115 cancelOnError: cancelOnError); |
| 116 } | 116 } |
| 117 | 117 |
| 118 Map<String, String> get queryParameters { | 118 Map<String, String> get queryParameters { |
| 119 if (_queryParameters == null) { | 119 if (_queryParameters == null) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 .then((request) { | 224 .then((request) { |
| 225 request._responseRedirects.addAll(this.redirects); | 225 request._responseRedirects.addAll(this.redirects); |
| 226 request._responseRedirects.add(new _RedirectInfo(statusCode, | 226 request._responseRedirects.add(new _RedirectInfo(statusCode, |
| 227 method, | 227 method, |
| 228 url)); | 228 url)); |
| 229 return request.close(); | 229 return request.close(); |
| 230 }); | 230 }); |
| 231 } | 231 } |
| 232 | 232 |
| 233 StreamSubscription<List<int>> listen(void onData(List<int> event), | 233 StreamSubscription<List<int>> listen(void onData(List<int> event), |
| 234 {void onError(AsyncError error), | 234 {void onError(error), |
| 235 void onDone(), | 235 void onDone(), |
| 236 bool cancelOnError}) { | 236 bool cancelOnError}) { |
| 237 var stream = _incoming; | 237 var stream = _incoming; |
| 238 if (headers.value(HttpHeaders.CONTENT_ENCODING) == "gzip") { | 238 if (headers.value(HttpHeaders.CONTENT_ENCODING) == "gzip") { |
| 239 stream = stream.transform(new ZLibInflater()); | 239 stream = stream.transform(new ZLibInflater()); |
| 240 } | 240 } |
| 241 return stream.listen(onData, | 241 return stream.listen(onData, |
| 242 onError: onError, | 242 onError: onError, |
| 243 onDone: onDone, | 243 onDone: onDone, |
| 244 cancelOnError: cancelOnError); | 244 cancelOnError: cancelOnError); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 | 435 |
| 436 void writeCharCode(int charCode) { | 436 void writeCharCode(int charCode) { |
| 437 _dataSink.writeCharCode(charCode); | 437 _dataSink.writeCharCode(charCode); |
| 438 } | 438 } |
| 439 | 439 |
| 440 void add(List<int> data) { | 440 void add(List<int> data) { |
| 441 if (data.length == 0) return; | 441 if (data.length == 0) return; |
| 442 _dataSink.add(data); | 442 _dataSink.add(data); |
| 443 } | 443 } |
| 444 | 444 |
| 445 void addError(AsyncError error) { | 445 void addError(error) { |
| 446 _dataSink.addError(error); | 446 _dataSink.addError(error); |
| 447 } | 447 } |
| 448 | 448 |
| 449 Future<T> addStream(Stream<List<int>> stream) { | 449 Future<T> addStream(Stream<List<int>> stream) { |
| 450 return _dataSink.addStream(stream); | 450 return _dataSink.addStream(stream); |
| 451 } | 451 } |
| 452 | 452 |
| 453 Future close() { | 453 Future close() { |
| 454 return _dataSink.close(); | 454 return _dataSink.close(); |
| 455 } | 455 } |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 } else { | 872 } else { |
| 873 future = new Future<HttpClientResponse>.immediate(response); | 873 future = new Future<HttpClientResponse>.immediate(response); |
| 874 } | 874 } |
| 875 future.then( | 875 future.then( |
| 876 (v) => _responseCompleter.complete(v), | 876 (v) => _responseCompleter.complete(v), |
| 877 onError: (e) { | 877 onError: (e) { |
| 878 _responseCompleter.completeError(e); | 878 _responseCompleter.completeError(e); |
| 879 }); | 879 }); |
| 880 } | 880 } |
| 881 | 881 |
| 882 void _onError(AsyncError error) { | 882 void _onError(error) { |
| 883 _responseCompleter.completeError(error); | 883 _responseCompleter.completeError(error); |
| 884 } | 884 } |
| 885 | 885 |
| 886 void _writeHeader() { | 886 void _writeHeader() { |
| 887 var buffer = new _BufferList(); | 887 var buffer = new _BufferList(); |
| 888 writeSP() => buffer.add(const [_CharCode.SP]); | 888 writeSP() => buffer.add(const [_CharCode.SP]); |
| 889 writeCRLF() => buffer.add(const [_CharCode.CR, _CharCode.LF]); | 889 writeCRLF() => buffer.add(const [_CharCode.CR, _CharCode.LF]); |
| 890 | 890 |
| 891 buffer.add(method.codeUnits); | 891 buffer.add(method.codeUnits); |
| 892 writeSP(); | 892 writeSP(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 class _ContentLengthValidator | 971 class _ContentLengthValidator |
| 972 extends StreamEventTransformer<List<int>, List<int>> { | 972 extends StreamEventTransformer<List<int>, List<int>> { |
| 973 final int expectedContentLength; | 973 final int expectedContentLength; |
| 974 int _bytesWritten = 0; | 974 int _bytesWritten = 0; |
| 975 | 975 |
| 976 _ContentLengthValidator(int this.expectedContentLength); | 976 _ContentLengthValidator(int this.expectedContentLength); |
| 977 | 977 |
| 978 void handleData(List<int> data, EventSink<List<int>> sink) { | 978 void handleData(List<int> data, EventSink<List<int>> sink) { |
| 979 _bytesWritten += data.length; | 979 _bytesWritten += data.length; |
| 980 if (_bytesWritten > expectedContentLength) { | 980 if (_bytesWritten > expectedContentLength) { |
| 981 sink.addError(new AsyncError(new HttpException( | 981 sink.addError(new HttpException( |
| 982 "Content size exceeds specified contentLength. " | 982 "Content size exceeds specified contentLength. " |
| 983 "$_bytesWritten bytes written while expected " | 983 "$_bytesWritten bytes written while expected " |
| 984 "$expectedContentLength. " | 984 "$expectedContentLength. " |
| 985 "[${new String.fromCharCodes(data)}]"))); | 985 "[${new String.fromCharCodes(data)}]")); |
| 986 sink.close(); | 986 sink.close(); |
| 987 } else { | 987 } else { |
| 988 sink.add(data); | 988 sink.add(data); |
| 989 } | 989 } |
| 990 } | 990 } |
| 991 | 991 |
| 992 void handleDone(EventSink<List<int>> sink) { | 992 void handleDone(EventSink<List<int>> sink) { |
| 993 if (_bytesWritten < expectedContentLength) { | 993 if (_bytesWritten < expectedContentLength) { |
| 994 sink.addError(new AsyncError(new HttpException( | 994 sink.addError(new HttpException( |
| 995 "Content size below specified contentLength. " | 995 "Content size below specified contentLength. " |
| 996 " $_bytesWritten bytes written while expected " | 996 " $_bytesWritten bytes written while expected " |
| 997 "$expectedContentLength."))); | 997 "$expectedContentLength.")); |
| 998 } | 998 } |
| 999 sink.close(); | 999 sink.close(); |
| 1000 } | 1000 } |
| 1001 } | 1001 } |
| 1002 | 1002 |
| 1003 | 1003 |
| 1004 // Extends StreamConsumer as this is an internal type, only used to pipe to. | 1004 // Extends StreamConsumer as this is an internal type, only used to pipe to. |
| 1005 class _HttpOutgoing implements StreamConsumer<List<int>> { | 1005 class _HttpOutgoing implements StreamConsumer<List<int>> { |
| 1006 final Completer _doneCompleter = new Completer(); | 1006 final Completer _doneCompleter = new Completer(); |
| 1007 final StreamConsumer _consumer; | 1007 final StreamConsumer _consumer; |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 port, | 1379 port, |
| 1380 sendClientCertificate: true) | 1380 sendClientCertificate: true) |
| 1381 : Socket.connect(host, port)) | 1381 : Socket.connect(host, port)) |
| 1382 .then((socket) { | 1382 .then((socket) { |
| 1383 socket.setOption(SocketOption.TCP_NODELAY, true); | 1383 socket.setOption(SocketOption.TCP_NODELAY, true); |
| 1384 var connection = new _HttpClientConnection(key, socket, this); | 1384 var connection = new _HttpClientConnection(key, socket, this); |
| 1385 _activeConnections.add(connection); | 1385 _activeConnections.add(connection); |
| 1386 return new _ConnnectionInfo(connection, proxy); | 1386 return new _ConnnectionInfo(connection, proxy); |
| 1387 }, onError: (error) { | 1387 }, onError: (error) { |
| 1388 // Continue with next proxy. | 1388 // Continue with next proxy. |
| 1389 return connect(error.error); | 1389 return connect(error); |
| 1390 }); | 1390 }); |
| 1391 } | 1391 } |
| 1392 return connect(new HttpException("No proxies given")); | 1392 return connect(new HttpException("No proxies given")); |
| 1393 } | 1393 } |
| 1394 | 1394 |
| 1395 _Credentials _findCredentials(Uri url, [_AuthenticationScheme scheme]) { | 1395 _Credentials _findCredentials(Uri url, [_AuthenticationScheme scheme]) { |
| 1396 // Look for credentials. | 1396 // Look for credentials. |
| 1397 _Credentials cr = | 1397 _Credentials cr = |
| 1398 _credentials.fold(null, (_Credentials prev, _Credentials value) { | 1398 _credentials.fold(null, (_Credentials prev, _Credentials value) { |
| 1399 if (value.applies(url, scheme)) { | 1399 if (value.applies(url, scheme)) { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1587 return new _HttpServer._(socket, true); | 1587 return new _HttpServer._(socket, true); |
| 1588 }); | 1588 }); |
| 1589 } | 1589 } |
| 1590 | 1590 |
| 1591 _HttpServer._(this._serverSocket, this._closeServer); | 1591 _HttpServer._(this._serverSocket, this._closeServer); |
| 1592 | 1592 |
| 1593 _HttpServer.listenOn(ServerSocket this._serverSocket) | 1593 _HttpServer.listenOn(ServerSocket this._serverSocket) |
| 1594 : _closeServer = false; | 1594 : _closeServer = false; |
| 1595 | 1595 |
| 1596 StreamSubscription<HttpRequest> listen(void onData(HttpRequest event), | 1596 StreamSubscription<HttpRequest> listen(void onData(HttpRequest event), |
| 1597 {void onError(AsyncError error), | 1597 {void onError(error), |
| 1598 void onDone(), | 1598 void onDone(), |
| 1599 bool cancelOnError}) { | 1599 bool cancelOnError}) { |
| 1600 _serverSocket.listen( | 1600 _serverSocket.listen( |
| 1601 (Socket socket) { | 1601 (Socket socket) { |
| 1602 socket.setOption(SocketOption.TCP_NODELAY, true); | 1602 socket.setOption(SocketOption.TCP_NODELAY, true); |
| 1603 // Accept the client connection. | 1603 // Accept the client connection. |
| 1604 _HttpConnection connection = new _HttpConnection(socket, this); | 1604 _HttpConnection connection = new _HttpConnection(socket, this); |
| 1605 _connections.add(connection); | 1605 _connections.add(connection); |
| 1606 }, | 1606 }, |
| 1607 onError: _controller.addError, | 1607 onError: _controller.addError, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1633 } | 1633 } |
| 1634 | 1634 |
| 1635 set sessionTimeout(int timeout) { | 1635 set sessionTimeout(int timeout) { |
| 1636 _sessionManager.sessionTimeout = timeout; | 1636 _sessionManager.sessionTimeout = timeout; |
| 1637 } | 1637 } |
| 1638 | 1638 |
| 1639 void _handleRequest(HttpRequest request) { | 1639 void _handleRequest(HttpRequest request) { |
| 1640 _controller.add(request); | 1640 _controller.add(request); |
| 1641 } | 1641 } |
| 1642 | 1642 |
| 1643 void _handleError(AsyncError error) { | 1643 void _handleError(error) { |
| 1644 if (!closed) _controller.addError(error); | 1644 if (!closed) _controller.addError(error); |
| 1645 } | 1645 } |
| 1646 | 1646 |
| 1647 void _connectionClosed(_HttpConnection connection) { | 1647 void _connectionClosed(_HttpConnection connection) { |
| 1648 _connections.remove(connection); | 1648 _connections.remove(connection); |
| 1649 } | 1649 } |
| 1650 | 1650 |
| 1651 _HttpSessionManager get _sessionManager { | 1651 _HttpSessionManager get _sessionManager { |
| 1652 // Lazy init. | 1652 // Lazy init. |
| 1653 if (_sessionManagerInstance == null) { | 1653 if (_sessionManagerInstance == null) { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1790 } | 1790 } |
| 1791 | 1791 |
| 1792 | 1792 |
| 1793 class _DetachedSocket extends Stream<List<int>> implements Socket { | 1793 class _DetachedSocket extends Stream<List<int>> implements Socket { |
| 1794 final Stream<List<int>> _incoming; | 1794 final Stream<List<int>> _incoming; |
| 1795 final Socket _socket; | 1795 final Socket _socket; |
| 1796 | 1796 |
| 1797 _DetachedSocket(this._socket, this._incoming); | 1797 _DetachedSocket(this._socket, this._incoming); |
| 1798 | 1798 |
| 1799 StreamSubscription<List<int>> listen(void onData(List<int> event), | 1799 StreamSubscription<List<int>> listen(void onData(List<int> event), |
| 1800 {void onError(AsyncError error), | 1800 {void onError(error), |
| 1801 void onDone(), | 1801 void onDone(), |
| 1802 bool cancelOnError}) { | 1802 bool cancelOnError}) { |
| 1803 return _incoming.listen(onData, | 1803 return _incoming.listen(onData, |
| 1804 onError: onError, | 1804 onError: onError, |
| 1805 onDone: onDone, | 1805 onDone: onDone, |
| 1806 cancelOnError: cancelOnError); | 1806 cancelOnError: cancelOnError); |
| 1807 } | 1807 } |
| 1808 | 1808 |
| 1809 Encoding get encoding => _socket.encoding; | 1809 Encoding get encoding => _socket.encoding; |
| 1810 | 1810 |
| 1811 void set encoding(Encoding value) { | 1811 void set encoding(Encoding value) { |
| 1812 _socket.encoding = value; | 1812 _socket.encoding = value; |
| 1813 } | 1813 } |
| 1814 | 1814 |
| 1815 void write(Object obj) => _socket.write(obj); | 1815 void write(Object obj) => _socket.write(obj); |
| 1816 | 1816 |
| 1817 void writeln([Object obj = ""]) => _socket.writeln(obj); | 1817 void writeln([Object obj = ""]) => _socket.writeln(obj); |
| 1818 | 1818 |
| 1819 void writeCharCode(int charCode) => _socket.writeCharCode(charCode); | 1819 void writeCharCode(int charCode) => _socket.writeCharCode(charCode); |
| 1820 | 1820 |
| 1821 void writeAll(Iterable objects, [String separator = ""]) { | 1821 void writeAll(Iterable objects, [String separator = ""]) { |
| 1822 _socket.writeAll(objects, separator); | 1822 _socket.writeAll(objects, separator); |
| 1823 } | 1823 } |
| 1824 | 1824 |
| 1825 void add(List<int> bytes) => _socket.add(bytes); | 1825 void add(List<int> bytes) => _socket.add(bytes); |
| 1826 | 1826 |
| 1827 void addError(AsyncError error) => _socket.addError(error); | 1827 void addError(error) => _socket.addError(error); |
| 1828 | 1828 |
| 1829 Future<Socket> addStream(Stream<List<int>> stream) { | 1829 Future<Socket> addStream(Stream<List<int>> stream) { |
| 1830 return _socket.addStream(stream); | 1830 return _socket.addStream(stream); |
| 1831 } | 1831 } |
| 1832 | 1832 |
| 1833 void destroy() => _socket.destroy(); | 1833 void destroy() => _socket.destroy(); |
| 1834 | 1834 |
| 1835 Future close() => _socket.close(); | 1835 Future close() => _socket.close(); |
| 1836 | 1836 |
| 1837 Future<Socket> get done => _socket.done; | 1837 Future<Socket> get done => _socket.done; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1988 | 1988 |
| 1989 | 1989 |
| 1990 class _RedirectInfo implements RedirectInfo { | 1990 class _RedirectInfo implements RedirectInfo { |
| 1991 const _RedirectInfo(int this.statusCode, | 1991 const _RedirectInfo(int this.statusCode, |
| 1992 String this.method, | 1992 String this.method, |
| 1993 Uri this.location); | 1993 Uri this.location); |
| 1994 final int statusCode; | 1994 final int statusCode; |
| 1995 final String method; | 1995 final String method; |
| 1996 final Uri location; | 1996 final Uri location; |
| 1997 } | 1997 } |
| OLD | NEW |