Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 just close the socket. |
| 1353 if (_httpParser.isIdle) { | 1357 if (_httpParser.isIdle) { |
| 1358 // If the client closes and we are done writing the response | |
| 1359 // the connection should be closed. | |
| 1360 if (_response == null) _close(); | |
|
Anders Johnsen
2012/09/11 12:49:40
Nice. Would it make sense to move this to below th
Mads Ager (google)
2012/09/11 14:43:11
I can do that. Thanks. :)
| |
| 1354 _socket.outputStream.onClosed = () { | 1361 _socket.outputStream.onClosed = () { |
| 1355 _destroy(); | 1362 _destroy(); |
| 1356 if (onClosed != null && e == null) { | 1363 if (onClosed != null && e == null) { |
| 1357 // Don't call onClosed if onError has been called. | 1364 // Don't call onClosed if onError has been called. |
| 1358 onClosed(); | 1365 onClosed(); |
| 1359 } | 1366 } |
| 1360 }; | 1367 }; |
| 1361 return; | 1368 return; |
| 1362 } | 1369 } |
| 1363 | 1370 |
| (...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2171 | 2178 |
| 2172 | 2179 |
| 2173 class _RedirectInfo implements RedirectInfo { | 2180 class _RedirectInfo implements RedirectInfo { |
| 2174 const _RedirectInfo(int this.statusCode, | 2181 const _RedirectInfo(int this.statusCode, |
| 2175 String this.method, | 2182 String this.method, |
| 2176 Uri this.location); | 2183 Uri this.location); |
| 2177 final int statusCode; | 2184 final int statusCode; |
| 2178 final String method; | 2185 final String method; |
| 2179 final Uri location; | 2186 final Uri location; |
| 2180 } | 2187 } |
| OLD | NEW |