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

Side by Side Diff: runtime/bin/http_impl.dart

Issue 10914200: Fix closing of server sockets. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments Created 8 years, 3 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 | « no previous file | no next file » | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 class _HttpHeaders implements HttpHeaders { 5 class _HttpHeaders implements HttpHeaders {
6 _HttpHeaders() : _headers = new Map<String, List<String>>(); 6 _HttpHeaders() : _headers = new Map<String, List<String>>();
7 7
8 List<String> operator[](String name) { 8 List<String> operator[](String name) {
9 name = name.toLowerCase(); 9 name = name.toLowerCase();
10 return _headers[name]; 10 return _headers[name];
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 bool allWritten = true; 683 bool allWritten = true;
684 if (_contentLength < 0) { 684 if (_contentLength < 0) {
685 // Terminate the content if transfer encoding is chunked. 685 // Terminate the content if transfer encoding is chunked.
686 allWritten = _httpConnection._write(_Const.END_CHUNKED); 686 allWritten = _httpConnection._write(_Const.END_CHUNKED);
687 } else { 687 } else {
688 if (!_headResponse && _bodyBytesWritten < _contentLength) { 688 if (!_headResponse && _bodyBytesWritten < _contentLength) {
689 throw new HttpException("Sending less than specified content length"); 689 throw new HttpException("Sending less than specified content length");
690 } 690 }
691 assert(_headResponse || _bodyBytesWritten == _contentLength); 691 assert(_headResponse || _bodyBytesWritten == _contentLength);
692 } 692 }
693 if (!persistentConnection) _httpConnection._close(); 693 // If we are done writing the response and the client has closed
694 // or the connection is not persistent we can close.
695 if (!persistentConnection || _httpConnection._closing) {
696 _httpConnection._close();
697 }
694 return allWritten; 698 return allWritten;
695 } 699 }
696 700
697 bool _writeHeaders() { 701 bool _writeHeaders() {
698 _headers._mutable = false; 702 _headers._mutable = false;
699 _headers._write(_httpConnection); 703 _headers._write(_httpConnection);
700 // Terminate header. 704 // Terminate header.
701 return _writeCRLF(); 705 return _writeCRLF();
702 } 706 }
703 707
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 onError(e); 1346 onError(e);
1343 // Propagate the error to the streams. 1347 // Propagate the error to the streams.
1344 if (_request != null && _request._streamErrorHandler != null) { 1348 if (_request != null && _request._streamErrorHandler != null) {
1345 _request._streamErrorHandler(e); 1349 _request._streamErrorHandler(e);
1346 } 1350 }
1347 if (_response != null && _response._streamErrorHandler != null) { 1351 if (_response != null && _response._streamErrorHandler != null) {
1348 _response._streamErrorHandler(e); 1352 _response._streamErrorHandler(e);
1349 } 1353 }
1350 } 1354 }
1351 1355
1352 // If currently not processing any request just close the socket. 1356 // If currently not processing any request close the socket when
1357 // we are done writing the response.
1353 if (_httpParser.isIdle) { 1358 if (_httpParser.isIdle) {
1354 _socket.outputStream.onClosed = () { 1359 _socket.outputStream.onClosed = () {
1355 _destroy(); 1360 _destroy();
1356 if (onClosed != null && e == null) { 1361 if (onClosed != null && e == null) {
1357 // Don't call onClosed if onError has been called. 1362 // Don't call onClosed if onError has been called.
1358 onClosed(); 1363 onClosed();
1359 } 1364 }
1360 }; 1365 };
1366 // If the client closes and we are done writing the response
1367 // the connection should be closed.
1368 if (_response == null) _close();
1361 return; 1369 return;
1362 } 1370 }
1363 1371
1364 // Processing a request. 1372 // Processing a request.
1365 if (e == null) { 1373 if (e == null) {
1366 // Indicate connection close to the HTTP parser. 1374 // Indicate connection close to the HTTP parser.
1367 _httpParser.connectionClosed(); 1375 _httpParser.connectionClosed();
1368 } 1376 }
1369 } 1377 }
1370 1378
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
2171 2179
2172 2180
2173 class _RedirectInfo implements RedirectInfo { 2181 class _RedirectInfo implements RedirectInfo {
2174 const _RedirectInfo(int this.statusCode, 2182 const _RedirectInfo(int this.statusCode,
2175 String this.method, 2183 String this.method,
2176 Uri this.location); 2184 Uri this.location);
2177 final int statusCode; 2185 final int statusCode;
2178 final String method; 2186 final String method;
2179 final Uri location; 2187 final Uri location;
2180 } 2188 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698