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

Unified Diff: runtime/bin/http_impl.dart

Issue 10262031: Add a web socket client (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/http.dart ('k') | runtime/bin/http_parser.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/http_impl.dart
diff --git a/runtime/bin/http_impl.dart b/runtime/bin/http_impl.dart
index e8e5ff14bf0c59d36a626089939a763f320d03c0..c7977a66344e5392579f0eb7a3da443751285484 100644
--- a/runtime/bin/http_impl.dart
+++ b/runtime/bin/http_impl.dart
@@ -467,7 +467,7 @@ class _HttpResponse extends _HttpRequestResponseBase implements HttpResponse {
return _outputStream;
}
- Socket detachSocket() {
+ DetachedSocket detachSocket() {
if (_state >= DONE) throw new HttpException("Response closed");
// Ensure that headers are written.
if (_state == START) {
@@ -602,7 +602,7 @@ class _HttpResponse extends _HttpRequestResponseBase implements HttpResponse {
// whether the content length is known.
if (_contentLength > 0) {
_headers.set("Content-Length", _contentLength.toString());
- } else {
+ } else if (_contentLength < 0) {
_headers.set("Transfer-Encoding", "chunked");
}
@@ -745,8 +745,10 @@ class _HttpConnectionBase implements Hashable {
int parsed = _httpParser.writeList(buffer, 0, bytesRead);
if (!_httpParser.upgrade) {
if (parsed != bytesRead) {
- // TODO(sgjesse): Error handling.
- _close();
+ if (_socket != null) {
+ // TODO(sgjesse): Error handling.
+ _close();
+ }
}
}
}
@@ -766,16 +768,15 @@ class _HttpConnectionBase implements Hashable {
_onConnectionClosed(e);
}
- Socket _detachSocket() {
+ DetachedSocket _detachSocket() {
_socket.onData = null;
- // TODO(sgjesse): Handle getting the write handler when using output stream.
- //_socket.onWrite = null;
_socket.onClosed = null;
_socket.onError = null;
+ _socket.outputStream.onNoPendingWrites = null;
Socket socket = _socket;
_socket = null;
- if (onDetach) onDetach();
- return socket;
+ if (onDetach != null) onDetach();
+ return new _DetachedSocket(socket, _httpParser.unparsedData);
}
abstract void _onConnectionClosed(e);
@@ -1231,6 +1232,10 @@ class _HttpClientConnection
return _request;
}
+ DetachedSocket detachSocket() {
+ return _detachSocket();
+ }
+
void _onConnectionClosed(e) {
// Socket is closed either due to an error or due to normal socket close.
if (e != null) {
@@ -1506,3 +1511,12 @@ class _HttpClient implements HttpClient {
Timer _evictionTimer;
bool _shutdown; // Has this HTTP client been shutdown?
}
+
+
+class _DetachedSocket implements DetachedSocket {
+ _DetachedSocket(this._socket, this._unparsedData);
+ Socket get socket() => _socket;
+ List<int> get unparsedData() => _unparsedData;
+ Socket _socket;
+ List<int> _unparsedData;
+}
« no previous file with comments | « runtime/bin/http.dart ('k') | runtime/bin/http_parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698