-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Closed
Labels
area-System.NetenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additions
Milestone
Description
Hi.
I'm trying to write some tests on our custom protocol over http. So, I passed a fake message handler to client, like this (we don't use C#6 yet, so):
public class CachingRequestsHandler : DelegatingHandler
{
public CachingRequestsHandler()
{
this.Requests = new List<HttpRequestMessage>();
}
public List<HttpRequestMessage> Requests { get; private set; }
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
this.Requests.Add(request);
return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK));
}
}
When in test I'm trying to inspect request's Content
, I'm getting an ObjectDisposedException
. As I found HttpClient
unconditionally disposes Content
.
I have two questions:
- will this behavior change in future to give user some control over Content?
- how should I work around this issue, because I want to assert and test all parts of request: headers and content? Is there a fast and easy way to clone
HttpRequestMessage
?
Gladskih
Metadata
Metadata
Assignees
Labels
area-System.NetenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additions