diff --git a/CHANGELOG.md b/CHANGELOG.md index dae87e95..015f93cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.0.0-rc.1 +* Fix logic error that allowed content to be written to streaming responses after `close` was closed. + # 2.0.0-rc.0 * Log a warning when no `reflector` is provided. * Add `AngelEnvironment` class. diff --git a/lib/src/http/http_response_context.dart b/lib/src/http/http_response_context.dart index a4d140e2..3fc87659 100644 --- a/lib/src/http/http_response_context.dart +++ b/lib/src/http/http_response_context.dart @@ -159,29 +159,31 @@ class HttpResponseContext extends ResponseContext { if (_isClosed && isBuffered) throw ResponseContext.closed(); else if (!isBuffered) { - _openStream(); + if (!_isClosed) { + _openStream(); - if (encoders.isNotEmpty && correspondingRequest != null) { - if (_allowedEncodings != null) { - for (var encodingName in _allowedEncodings) { - Converter, List> encoder; - String key = encodingName; + if (encoders.isNotEmpty && correspondingRequest != null) { + if (_allowedEncodings != null) { + for (var encodingName in _allowedEncodings) { + Converter, List> encoder; + String key = encodingName; - if (encoders.containsKey(encodingName)) - encoder = encoders[encodingName]; - else if (encodingName == '*') { - encoder = encoders[key = encoders.keys.first]; - } + if (encoders.containsKey(encodingName)) + encoder = encoders[encodingName]; + else if (encodingName == '*') { + encoder = encoders[key = encoders.keys.first]; + } - if (encoder != null) { - data = encoders[key].convert(data); - break; + if (encoder != null) { + data = encoders[key].convert(data); + break; + } } } } - } - rawResponse.add(data); + rawResponse.add(data); + } } else buffer.add(data); } diff --git a/lib/src/http2/http2_response_context.dart b/lib/src/http2/http2_response_context.dart index bc5c0e4d..99557e53 100644 --- a/lib/src/http2/http2_response_context.dart +++ b/lib/src/http2/http2_response_context.dart @@ -166,27 +166,29 @@ class Http2ResponseContext extends ResponseContext { else if (!isBuffered) { _openStream(); - if (encoders.isNotEmpty && correspondingRequest != null) { - if (_allowedEncodings != null) { - for (var encodingName in _allowedEncodings) { - Converter, List> encoder; - String key = encodingName; + if (!_isClosed) { + if (encoders.isNotEmpty && correspondingRequest != null) { + if (_allowedEncodings != null) { + for (var encodingName in _allowedEncodings) { + Converter, List> encoder; + String key = encodingName; - if (encoders.containsKey(encodingName)) - encoder = encoders[encodingName]; - else if (encodingName == '*') { - encoder = encoders[key = encoders.keys.first]; - } + if (encoders.containsKey(encodingName)) + encoder = encoders[encodingName]; + else if (encodingName == '*') { + encoder = encoders[key = encoders.keys.first]; + } - if (encoder != null) { - data = encoders[key].convert(data); - break; + if (encoder != null) { + data = encoders[key].convert(data); + break; + } } } } - } - stream.sendData(data); + stream.sendData(data); + } } else buffer.add(data); }