public void Cleanup() // not called Dispose because the request may still be in use after it's cleaned up { // Don't dispose of the ResponseMessage.ResponseStream as it may still be in use // by code reading data stored in the stream. Also don't dispose of the request content // stream; that'll be handled by the disposal of the request content by the HttpClient, // and doing it here prevents reuse by an intermediate handler sitting between the client // and this handler. // However, if we got an original position for the request stream, we seek back to that position, // for the corner case where the stream does get reused before it's disposed by the HttpClient // (if the same request object is used multiple times from an intermediate handler, we'll be using // ReadAsStreamAsync, which on the same request object will return the same stream object, which // we've already advanced). if (_requestContentStream != null && _requestContentStream.CanSeek) { Debug.Assert(_requestContentStreamStartingPosition.HasValue, "The stream is seekable, but we don't have a starting position?"); _requestContentStream.Position = _requestContentStreamStartingPosition.GetValueOrDefault(); } // Dispose of the underlying easy handle. We're no longer processing it. _easyHandle?.Dispose(); // Dispose of the request headers if we had any. We had to keep this handle // alive as long as the easy handle was using it. We didn't need to do any // ref counting on the safe handle, though, as the only processing happens // in Process, which ensures the handle will be rooted while libcurl is // doing any processing that assumes it's valid. _requestHeaders?.Dispose(); // Dispose native callback resources _callbackHandle?.Dispose(); // Release any send transfer state, which will return its buffer to the pool _sendTransferState?.Dispose(); }
public void Cleanup() // not called Dispose because the request may still be in use after it's cleaned up { _responseMessage.ResponseStream.SignalComplete(); // No more callbacks so no more data // Don't dispose of the ResponseMessage.ResponseStream as it may still be in use // by code reading data stored in the stream. // Dispose of the input content stream if there was one. Nothing should be using it any more. if (_requestContentStream != null) { _requestContentStream.Dispose(); } // Dispose of the underlying easy handle. We're no longer processing it. if (_easyHandle != null) { _easyHandle.Dispose(); } // Dispose of the request headers if we had any. We had to keep this handle // alive as long as the easy handle was using it. We didn't need to do any // ref counting on the safe handle, though, as the only processing happens // in Process, which ensures the handle will be rooted while libcurl is // doing any processing that assumes it's valid. if (_requestHeaders != null) { _requestHeaders.Dispose(); } if (_callbackHandle != null) { _callbackHandle.Dispose(); } }