Skip to content

Commit

Permalink
include original request message in the response container, necessary…
Browse files Browse the repository at this point in the history
… if its contents need to be read as the HttpClient disposes automatically after sending (see https://github.com/dotnet/corefx/issues/1794)
  • Loading branch information
marcinjakubowski committed Apr 21, 2017
1 parent afc8a9f commit 2b2a508
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions ScraperClientLib/Engine/ClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,16 @@ public HttpRequestMessage BuildPost(Uri uri, IEnumerable<KeyValuePair<string, st

private ResponseContainer IssueRequestInternal(HttpRequestMessage request, bool save = true)
{
if (save && _retry == 0) _original = CloneHttpRequestMessage(request);
if (save && _retry == 0)
{
_original = CloneHttpRequestMessage(request);
}
try
{
HttpResponseMessage response = _httpClient.SendAsync(request).Sync();
LastRequestUtc = DateTime.UtcNow;

ResponseContainer result = new ResponseContainer(request, response);
ResponseContainer result = new ResponseContainer(request, _original, response);
_retry = 0;
return result;
}
Expand Down
5 changes: 3 additions & 2 deletions ScraperClientLib/Engine/ResponseContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace ScraperClientLib.Engine
public class ResponseContainer
{
public HttpRequestMessage RequestMessage { get; }

public HttpRequestMessage OriginalRequest { get; }
public HttpResponseMessage ResponseMessage { get; }
public Lazy<string> Raw { get; }

Expand All @@ -29,9 +29,10 @@ public class ResponseContainer

public List<DataObject> ParsedObjects { get; set; }

public ResponseContainer(HttpRequestMessage requestMessage, HttpResponseMessage responseMessage)
public ResponseContainer(HttpRequestMessage requestMessage, HttpRequestMessage originalRequest, HttpResponseMessage responseMessage)
{
RequestMessage = requestMessage;
OriginalRequest = originalRequest;
ResponseMessage = responseMessage;

ParsedObjects = new List<DataObject>();
Expand Down

0 comments on commit 2b2a508

Please sign in to comment.