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

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

Issue 10356055: Make the HTTP server close non-persistent connections (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 | tests/standalone/io/http_connection_close_test.dart » ('j') | 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 bool allWritten = true; 310 bool allWritten = true;
311 if (_contentLength < 0) { 311 if (_contentLength < 0) {
312 // Terminate the content if transfer encoding is chunked. 312 // Terminate the content if transfer encoding is chunked.
313 allWritten = _httpConnection._write(_Const.END_CHUNKED); 313 allWritten = _httpConnection._write(_Const.END_CHUNKED);
314 } else { 314 } else {
315 if (_bodyBytesWritten < _contentLength) { 315 if (_bodyBytesWritten < _contentLength) {
316 throw new HttpException("Sending less than specified content length"); 316 throw new HttpException("Sending less than specified content length");
317 } 317 }
318 assert(_bodyBytesWritten == _contentLength); 318 assert(_bodyBytesWritten == _contentLength);
319 } 319 }
320 if (!persistentConnection) _httpConnection._close();
320 return allWritten; 321 return allWritten;
321 } 322 }
322 323
323 bool _writeHeaders() { 324 bool _writeHeaders() {
324 _headers._mutable = false; 325 _headers._mutable = false;
325 _headers._write(_httpConnection); 326 _headers._write(_httpConnection);
326 // Terminate header. 327 // Terminate header.
327 return _writeCRLF(); 328 return _writeCRLF();
328 } 329 }
329 330
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 } 748 }
748 749
749 bool _writeFrom(List<int> buffer, [int offset, int len]) { 750 bool _writeFrom(List<int> buffer, [int offset, int len]) {
750 if (!_error && !_closing) { 751 if (!_error && !_closing) {
751 return _socket.outputStream.writeFrom(buffer, offset, len); 752 return _socket.outputStream.writeFrom(buffer, offset, len);
752 } 753 }
753 } 754 }
754 755
755 bool _close() { 756 bool _close() {
756 _closing = true; 757 _closing = true;
758 _socket.outputStream.close();
759 }
760
761 bool _destroy() {
762 _closing = true;
757 _socket.close(); 763 _socket.close();
758 } 764 }
759 765
760 void _onData() { 766 void _onData() {
761 int available = _socket.available(); 767 int available = _socket.available();
762 if (available == 0) { 768 if (available == 0) {
763 return; 769 return;
764 } 770 }
765 771
766 List<int> buffer = new Uint8List(available); 772 List<int> buffer = new Uint8List(available);
767 int bytesRead = _socket.readList(buffer, 0, available); 773 int bytesRead = _socket.readList(buffer, 0, available);
768 if (bytesRead > 0) { 774 if (bytesRead > 0) {
769 int parsed = _httpParser.writeList(buffer, 0, bytesRead); 775 int parsed = _httpParser.writeList(buffer, 0, bytesRead);
770 if (!_httpParser.upgrade) { 776 if (!_httpParser.upgrade) {
771 if (parsed != bytesRead) { 777 if (parsed != bytesRead) {
772 if (_socket != null) { 778 if (_socket != null) {
773 // TODO(sgjesse): Error handling. 779 // TODO(sgjesse): Error handling.
774 _close(); 780 _destroy();
775 } 781 }
776 } 782 }
777 } 783 }
778 } 784 }
779 } 785 }
780 786
781 void _onClosed() { 787 void _onClosed() {
782 _closing = true; 788 _closing = true;
783 _onConnectionClosed(null); 789 _onConnectionClosed(null);
784 } 790 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 if (_request != null && _request._streamErrorHandler != null) { 862 if (_request != null && _request._streamErrorHandler != null) {
857 _request._streamErrorHandler(e); 863 _request._streamErrorHandler(e);
858 } 864 }
859 if (_response != null && _response._streamErrorHandler != null) { 865 if (_response != null && _response._streamErrorHandler != null) {
860 _response._streamErrorHandler(e); 866 _response._streamErrorHandler(e);
861 } 867 }
862 } 868 }
863 869
864 // If currently not processing any request just close the socket. 870 // If currently not processing any request just close the socket.
865 if (_httpParser.isIdle) { 871 if (_httpParser.isIdle) {
866 _close(); 872 _destroy();
867 if (onClosed != null && e == null) { 873 if (onClosed != null && e == null) {
868 // Don't call onClosed if onError has been called. 874 // Don't call onClosed if onError has been called.
869 onClosed(); 875 onClosed();
870 } 876 }
871 return; 877 return;
872 } 878 }
873 879
874 // Processing a request. 880 // Processing a request.
875 if (e == null) { 881 if (e == null) {
876 // Indicate connection close to the HTTP parser. 882 // Indicate connection close to the HTTP parser.
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 } 1549 }
1544 1550
1545 1551
1546 class _DetachedSocket implements DetachedSocket { 1552 class _DetachedSocket implements DetachedSocket {
1547 _DetachedSocket(this._socket, this._unparsedData); 1553 _DetachedSocket(this._socket, this._unparsedData);
1548 Socket get socket() => _socket; 1554 Socket get socket() => _socket;
1549 List<int> get unparsedData() => _unparsedData; 1555 List<int> get unparsedData() => _unparsedData;
1550 Socket _socket; 1556 Socket _socket;
1551 List<int> _unparsedData; 1557 List<int> _unparsedData;
1552 } 1558 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/http_connection_close_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698