Added HttpResponseContext.detach
This commit is contained in:
parent
fdd1ca16c9
commit
be521dcd7f
1 changed files with 21 additions and 13 deletions
|
@ -15,10 +15,16 @@ class HttpResponseContext extends ResponseContext<HttpResponse> {
|
||||||
LockableBytesBuilder _buffer;
|
LockableBytesBuilder _buffer;
|
||||||
|
|
||||||
final HttpRequestContext _correspondingRequest;
|
final HttpRequestContext _correspondingRequest;
|
||||||
bool _isClosed = false, _streamInitialized = false;
|
bool _detached = false, _isClosed = false, _streamInitialized = false;
|
||||||
|
|
||||||
HttpResponseContext(this.rawResponse, this.app, [this._correspondingRequest]);
|
HttpResponseContext(this.rawResponse, this.app, [this._correspondingRequest]);
|
||||||
|
|
||||||
|
@override
|
||||||
|
HttpResponse detach() {
|
||||||
|
_detached = true;
|
||||||
|
return rawResponse;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
RequestContext get correspondingRequest {
|
RequestContext get correspondingRequest {
|
||||||
return _correspondingRequest;
|
return _correspondingRequest;
|
||||||
|
@ -166,22 +172,24 @@ class HttpResponseContext extends ResponseContext<HttpResponse> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future close() {
|
Future close() {
|
||||||
if (!_isClosed) {
|
if (!_detached) {
|
||||||
if (!isBuffered) {
|
if (!_isClosed) {
|
||||||
try {
|
if (!isBuffered) {
|
||||||
rawResponse.close();
|
try {
|
||||||
} catch (_) {
|
rawResponse.close();
|
||||||
// This only seems to occur on `MockHttpRequest`, but
|
} catch (_) {
|
||||||
// this try/catch prevents a crash.
|
// This only seems to occur on `MockHttpRequest`, but
|
||||||
|
// this try/catch prevents a crash.
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_buffer.lock();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
_buffer.lock();
|
_isClosed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_isClosed = true;
|
super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
super.close();
|
|
||||||
return new Future.value();
|
return new Future.value();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue