Skip to content

Commit

Permalink
Fix memory leak around handling of Accepts header.
Browse files Browse the repository at this point in the history
When adding an Accepts header to the request, this shouldn't be put into
DefaultParameters.  Repeated requests through the same RestClient instance
were adding the Accepts header every time, resulting in a large memory
leak because DefaultParameters was growing without bound.

Instead, only add the header for this particular request.
  • Loading branch information
Ewan Mellor committed Jan 13, 2013
1 parent cc283fb commit aee34f0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 0 additions & 4 deletions RestSharp/RestClient.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ private RestRequestAsyncHandle ExecuteAsync(IRestRequest request, Action<IRestRe
var http = HttpFactory.Create();
AuthenticateIfNeeded(this, request);

// add Accept header based on registered deserializers
var accepts = string.Join(", ", AcceptTypes.ToArray());
this.AddDefaultParameter("Accept", accepts, ParameterType.HttpHeader);

ConfigureHttp(request, http);

var asyncHandle = new RestRequestAsyncHandle();
Expand Down
4 changes: 0 additions & 4 deletions RestSharp/RestClient.Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ private IRestResponse Execute(IRestRequest request, string httpMethod, Func<IHtt
{
AuthenticateIfNeeded(this, request);

// add Accept header based on registered deserializers
var accepts = string.Join(", ", AcceptTypes.ToArray());
this.AddDefaultParameter("Accept", accepts, ParameterType.HttpHeader);

IRestResponse response = new RestResponse();
try
{
Expand Down
7 changes: 7 additions & 0 deletions RestSharp/RestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,13 @@ private void ConfigureHttp(IRestRequest request, IHttp http)
request.AddParameter(p);
}

// Add Accept header based on registered deserializers if none has been set by the caller.
if (!request.Parameters.Any(p2 => p2.Name.ToLowerInvariant() == "accept"))
{
var accepts = string.Join(", ", AcceptTypes.ToArray());
request.AddParameter("Accept", accepts, ParameterType.HttpHeader);
}

http.Url = BuildUri(request);

var userAgent = UserAgent ?? http.UserAgent;
Expand Down

0 comments on commit aee34f0

Please sign in to comment.