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 19 matching lines...) Expand all Loading... |
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(AsyncError error), |
39 void onDone(), | 39 void onDone(), |
40 bool unsubscribeOnError}) { | 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 unsubscribeOnError: unsubscribeOnError); | 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; |
49 | 49 |
50 void close() { | 50 void close() { |
51 fullBodyRead = true; | 51 fullBodyRead = true; |
52 _dataCompleter.complete(); | 52 _dataCompleter.complete(); |
53 } | 53 } |
54 } | 54 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(AsyncError error), |
110 void onDone(), | 110 void onDone(), |
111 bool unsubscribeOnError}) { | 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 unsubscribeOnError: unsubscribeOnError); | 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) { |
120 _queryParameters = _HttpUtils.splitQueryString(uri.query); | 120 _queryParameters = _HttpUtils.splitQueryString(uri.query); |
121 } | 121 } |
122 return _queryParameters; | 122 return _queryParameters; |
123 } | 123 } |
124 | 124 |
125 Uri get uri => _incoming.uri; | 125 Uri get uri => _incoming.uri; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(AsyncError error), |
235 void onDone(), | 235 void onDone(), |
236 bool unsubscribeOnError}) { | 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 unsubscribeOnError: unsubscribeOnError); | 244 cancelOnError: cancelOnError); |
245 } | 245 } |
246 | 246 |
247 Future<Socket> detachSocket() { | 247 Future<Socket> detachSocket() { |
248 _httpClient._connectionClosed(_httpRequest._httpClientConnection); | 248 _httpClient._connectionClosed(_httpRequest._httpClientConnection); |
249 return _httpRequest._httpClientConnection.detachSocket(); | 249 return _httpRequest._httpClientConnection.detachSocket(); |
250 } | 250 } |
251 | 251 |
252 HttpConnectionInfo get connectionInfo => _httpRequest.connectionInfo; | 252 HttpConnectionInfo get connectionInfo => _httpRequest.connectionInfo; |
253 | 253 |
254 bool get _shouldAuthenticateProxy { | 254 bool get _shouldAuthenticateProxy { |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 _subscription = stream.listen( | 579 _subscription = stream.listen( |
580 (data) { | 580 (data) { |
581 _controller.add(data); | 581 _controller.add(data); |
582 }, | 582 }, |
583 onDone: () { | 583 onDone: () { |
584 _done(); | 584 _done(); |
585 }, | 585 }, |
586 onError: (error) { | 586 onError: (error) { |
587 _done(error); | 587 _done(error); |
588 }, | 588 }, |
589 unsubscribeOnError: true); | 589 cancelOnError: true); |
590 return _completer.future; | 590 return _completer.future; |
591 } | 591 } |
592 | 592 |
593 Future close() { | 593 Future close() { |
594 Future closeOutbound() { | 594 Future closeOutbound() { |
595 return _outbound._close().then((_) => _outbound); | 595 return _outbound._close().then((_) => _outbound); |
596 } | 596 } |
597 if (_controller == null) return closeOutbound(); | 597 if (_controller == null) return closeOutbound(); |
598 _controller.close(); | 598 _controller.close(); |
599 return _closeCompleter.future.then((_) => closeOutbound()); | 599 return _closeCompleter.future.then((_) => closeOutbound()); |
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 } | 1587 } |
1588 | 1588 |
1589 _HttpServer._(this._serverSocket, this._closeServer); | 1589 _HttpServer._(this._serverSocket, this._closeServer); |
1590 | 1590 |
1591 _HttpServer.listenOn(ServerSocket this._serverSocket) | 1591 _HttpServer.listenOn(ServerSocket this._serverSocket) |
1592 : _closeServer = false; | 1592 : _closeServer = false; |
1593 | 1593 |
1594 StreamSubscription<HttpRequest> listen(void onData(HttpRequest event), | 1594 StreamSubscription<HttpRequest> listen(void onData(HttpRequest event), |
1595 {void onError(AsyncError error), | 1595 {void onError(AsyncError error), |
1596 void onDone(), | 1596 void onDone(), |
1597 bool unsubscribeOnError}) { | 1597 bool cancelOnError}) { |
1598 _serverSocket.listen( | 1598 _serverSocket.listen( |
1599 (Socket socket) { | 1599 (Socket socket) { |
1600 socket.setOption(SocketOption.TCP_NODELAY, true); | 1600 socket.setOption(SocketOption.TCP_NODELAY, true); |
1601 // Accept the client connection. | 1601 // Accept the client connection. |
1602 _HttpConnection connection = new _HttpConnection(socket, this); | 1602 _HttpConnection connection = new _HttpConnection(socket, this); |
1603 _connections.add(connection); | 1603 _connections.add(connection); |
1604 }, | 1604 }, |
1605 onError: _controller.addError, | 1605 onError: _controller.addError, |
1606 onDone: _controller.close); | 1606 onDone: _controller.close); |
1607 return _controller.stream.listen(onData, | 1607 return _controller.stream.listen(onData, |
1608 onError: onError, | 1608 onError: onError, |
1609 onDone: onDone, | 1609 onDone: onDone, |
1610 unsubscribeOnError: unsubscribeOnError); | 1610 cancelOnError: cancelOnError); |
1611 } | 1611 } |
1612 | 1612 |
1613 void close() { | 1613 void close() { |
1614 closed = true; | 1614 closed = true; |
1615 if (_serverSocket != null && _closeServer) { | 1615 if (_serverSocket != null && _closeServer) { |
1616 _serverSocket.close(); | 1616 _serverSocket.close(); |
1617 } | 1617 } |
1618 if (_sessionManagerInstance != null) { | 1618 if (_sessionManagerInstance != null) { |
1619 _sessionManagerInstance.close(); | 1619 _sessionManagerInstance.close(); |
1620 _sessionManagerInstance = null; | 1620 _sessionManagerInstance = null; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1790 | 1790 |
1791 class _DetachedSocket extends Stream<List<int>> implements Socket { | 1791 class _DetachedSocket extends Stream<List<int>> implements Socket { |
1792 final Stream<List<int>> _incoming; | 1792 final Stream<List<int>> _incoming; |
1793 final Socket _socket; | 1793 final Socket _socket; |
1794 | 1794 |
1795 _DetachedSocket(this._socket, this._incoming); | 1795 _DetachedSocket(this._socket, this._incoming); |
1796 | 1796 |
1797 StreamSubscription<List<int>> listen(void onData(List<int> event), | 1797 StreamSubscription<List<int>> listen(void onData(List<int> event), |
1798 {void onError(AsyncError error), | 1798 {void onError(AsyncError error), |
1799 void onDone(), | 1799 void onDone(), |
1800 bool unsubscribeOnError}) { | 1800 bool cancelOnError}) { |
1801 return _incoming.listen(onData, | 1801 return _incoming.listen(onData, |
1802 onError: onError, | 1802 onError: onError, |
1803 onDone: onDone, | 1803 onDone: onDone, |
1804 unsubscribeOnError: unsubscribeOnError); | 1804 cancelOnError: cancelOnError); |
1805 } | 1805 } |
1806 | 1806 |
1807 Encoding get encoding => _socket.encoding; | 1807 Encoding get encoding => _socket.encoding; |
1808 | 1808 |
1809 void set encoding(Encoding value) { | 1809 void set encoding(Encoding value) { |
1810 _socket.encoding = value; | 1810 _socket.encoding = value; |
1811 } | 1811 } |
1812 | 1812 |
1813 void write(Object obj) => _socket.write(obj); | 1813 void write(Object obj) => _socket.write(obj); |
1814 | 1814 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1986 | 1986 |
1987 | 1987 |
1988 class _RedirectInfo implements RedirectInfo { | 1988 class _RedirectInfo implements RedirectInfo { |
1989 const _RedirectInfo(int this.statusCode, | 1989 const _RedirectInfo(int this.statusCode, |
1990 String this.method, | 1990 String this.method, |
1991 Uri this.location); | 1991 Uri this.location); |
1992 final int statusCode; | 1992 final int statusCode; |
1993 final String method; | 1993 final String method; |
1994 final Uri location; | 1994 final Uri location; |
1995 } | 1995 } |
OLD | NEW |