| 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 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 | 702 |
| 703 void _updateContentLength(int bytes) { | 703 void _updateContentLength(int bytes) { |
| 704 if (_bodyBytesWritten + bytes > _contentLength) { | 704 if (_bodyBytesWritten + bytes > _contentLength) { |
| 705 throw new HttpException("Writing more than specified content length"); | 705 throw new HttpException("Writing more than specified content length"); |
| 706 } | 706 } |
| 707 _bodyBytesWritten += bytes; | 707 _bodyBytesWritten += bytes; |
| 708 } | 708 } |
| 709 | 709 |
| 710 HttpConnectionInfo get connectionInfo() => _httpConnection.connectionInfo; | 710 HttpConnectionInfo get connectionInfo() => _httpConnection.connectionInfo; |
| 711 | 711 |
| 712 bool get _done() => _state == DONE; |
| 713 |
| 712 int _state; | 714 int _state; |
| 713 bool _headResponse; | 715 bool _headResponse; |
| 714 | 716 |
| 715 _HttpConnectionBase _httpConnection; | 717 _HttpConnectionBase _httpConnection; |
| 716 _HttpHeaders _headers; | 718 _HttpHeaders _headers; |
| 717 List<Cookie> _cookies; | 719 List<Cookie> _cookies; |
| 718 String _protocolVersion = "1.1"; | 720 String _protocolVersion = "1.1"; |
| 719 | 721 |
| 720 // Length of the content body. If this is set to -1 (default value) | 722 // Length of the content body. If this is set to -1 (default value) |
| 721 // when starting to send data chunked transfer encoding will be | 723 // when starting to send data chunked transfer encoding will be |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 // Stop tracking no pending write events. | 940 // Stop tracking no pending write events. |
| 939 _httpConnection._onNoPendingWrites = null; | 941 _httpConnection._onNoPendingWrites = null; |
| 940 // Ensure that any trailing data is written. | 942 // Ensure that any trailing data is written. |
| 941 _writeDone(); | 943 _writeDone(); |
| 942 // Indicate to the connection that the response handling is done. | 944 // Indicate to the connection that the response handling is done. |
| 943 _httpConnection._responseDone(); | 945 _httpConnection._responseDone(); |
| 944 } | 946 } |
| 945 | 947 |
| 946 // Delegate functions for the HttpOutputStream implementation. | 948 // Delegate functions for the HttpOutputStream implementation. |
| 947 bool _streamWrite(List<int> buffer, bool copyBuffer) { | 949 bool _streamWrite(List<int> buffer, bool copyBuffer) { |
| 948 if (_state == DONE) throw new HttpException("Response closed"); | 950 if (_done) throw new HttpException("Response closed"); |
| 949 return _write(buffer, copyBuffer); | 951 return _write(buffer, copyBuffer); |
| 950 } | 952 } |
| 951 | 953 |
| 952 bool _streamWriteFrom(List<int> buffer, int offset, int len) { | 954 bool _streamWriteFrom(List<int> buffer, int offset, int len) { |
| 953 if (_state == DONE) throw new HttpException("Response closed"); | 955 if (_done) throw new HttpException("Response closed"); |
| 954 return _writeList(buffer, offset, len); | 956 return _writeList(buffer, offset, len); |
| 955 } | 957 } |
| 956 | 958 |
| 957 void _streamClose() { | 959 void _streamClose() { |
| 958 _responseEnd(); | 960 _responseEnd(); |
| 959 } | 961 } |
| 960 | 962 |
| 961 void _streamSetNoPendingWriteHandler(callback()) { | 963 void _streamSetNoPendingWriteHandler(callback()) { |
| 962 if (_state != DONE) { | 964 if (_state != DONE) { |
| 963 _httpConnection._onNoPendingWrites = callback; | 965 _httpConnection._onNoPendingWrites = callback; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 } | 1132 } |
| 1131 | 1133 |
| 1132 bool writeFrom(List<int> buffer, [int offset = 0, int len]) { | 1134 bool writeFrom(List<int> buffer, [int offset = 0, int len]) { |
| 1133 return _requestOrResponse._streamWriteFrom(buffer, offset, len); | 1135 return _requestOrResponse._streamWriteFrom(buffer, offset, len); |
| 1134 } | 1136 } |
| 1135 | 1137 |
| 1136 void close() { | 1138 void close() { |
| 1137 _requestOrResponse._streamClose(); | 1139 _requestOrResponse._streamClose(); |
| 1138 } | 1140 } |
| 1139 | 1141 |
| 1142 bool get closed() => _requestOrResponse._done; |
| 1143 |
| 1140 void destroy() { | 1144 void destroy() { |
| 1141 throw "Not implemented"; | 1145 throw "Not implemented"; |
| 1142 } | 1146 } |
| 1143 | 1147 |
| 1144 void set onNoPendingWrites(void callback()) { | 1148 void set onNoPendingWrites(void callback()) { |
| 1145 _requestOrResponse._streamSetNoPendingWriteHandler(callback); | 1149 _requestOrResponse._streamSetNoPendingWriteHandler(callback); |
| 1146 } | 1150 } |
| 1147 | 1151 |
| 1148 void set onClosed(void callback()) { | 1152 void set onClosed(void callback()) { |
| 1149 _requestOrResponse._streamSetCloseHandler(callback); | 1153 _requestOrResponse._streamSetCloseHandler(callback); |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1510 if (_state >= HEADER_SENT) throw new HttpException("Header already sent"); | 1514 if (_state >= HEADER_SENT) throw new HttpException("Header already sent"); |
| 1511 _contentLength = contentLength; | 1515 _contentLength = contentLength; |
| 1512 } | 1516 } |
| 1513 | 1517 |
| 1514 List<Cookie> get cookies() { | 1518 List<Cookie> get cookies() { |
| 1515 if (_cookies == null) _cookies = new List<Cookie>(); | 1519 if (_cookies == null) _cookies = new List<Cookie>(); |
| 1516 return _cookies; | 1520 return _cookies; |
| 1517 } | 1521 } |
| 1518 | 1522 |
| 1519 OutputStream get outputStream() { | 1523 OutputStream get outputStream() { |
| 1520 if (_state == DONE) throw new HttpException("Request closed"); | 1524 if (_done) throw new HttpException("Request closed"); |
| 1521 if (_outputStream == null) { | 1525 if (_outputStream == null) { |
| 1522 _outputStream = new _HttpOutputStream(this); | 1526 _outputStream = new _HttpOutputStream(this); |
| 1523 } | 1527 } |
| 1524 return _outputStream; | 1528 return _outputStream; |
| 1525 } | 1529 } |
| 1526 | 1530 |
| 1527 // Delegate functions for the HttpOutputStream implementation. | 1531 // Delegate functions for the HttpOutputStream implementation. |
| 1528 bool _streamWrite(List<int> buffer, bool copyBuffer) { | 1532 bool _streamWrite(List<int> buffer, bool copyBuffer) { |
| 1529 if (_state == DONE) throw new HttpException("Request closed"); | 1533 if (_done) throw new HttpException("Request closed"); |
| 1530 return _write(buffer, copyBuffer); | 1534 return _write(buffer, copyBuffer); |
| 1531 } | 1535 } |
| 1532 | 1536 |
| 1533 bool _streamWriteFrom(List<int> buffer, int offset, int len) { | 1537 bool _streamWriteFrom(List<int> buffer, int offset, int len) { |
| 1534 if (_state == DONE) throw new HttpException("Request closed"); | 1538 if (_done) throw new HttpException("Request closed"); |
| 1535 return _writeList(buffer, offset, len); | 1539 return _writeList(buffer, offset, len); |
| 1536 } | 1540 } |
| 1537 | 1541 |
| 1538 void _streamClose() { | 1542 void _streamClose() { |
| 1539 _ensureHeadersSent(); | 1543 _ensureHeadersSent(); |
| 1540 _state = DONE; | 1544 _state = DONE; |
| 1541 // Stop tracking no pending write events. | 1545 // Stop tracking no pending write events. |
| 1542 _httpConnection._onNoPendingWrites = null; | 1546 _httpConnection._onNoPendingWrites = null; |
| 1543 // Ensure that any trailing data is written. | 1547 // Ensure that any trailing data is written. |
| 1544 _writeDone(); | 1548 _writeDone(); |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2131 | 2135 |
| 2132 | 2136 |
| 2133 class _RedirectInfo implements RedirectInfo { | 2137 class _RedirectInfo implements RedirectInfo { |
| 2134 const _RedirectInfo(int this.statusCode, | 2138 const _RedirectInfo(int this.statusCode, |
| 2135 String this.method, | 2139 String this.method, |
| 2136 Uri this.location); | 2140 Uri this.location); |
| 2137 final int statusCode; | 2141 final int statusCode; |
| 2138 final String method; | 2142 final String method; |
| 2139 final Uri location; | 2143 final Uri location; |
| 2140 } | 2144 } |
| OLD | NEW |