Skip to content

Commit

Permalink
Configurable Decompression Methods on Http Request
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabrizio Mancin committed Sep 1, 2015
1 parent 0ef81fd commit 85c2048
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 2 deletions.
Binary file modified .nuget/RestSharp.Build.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion RestSharp.Net45/RestSharp.Net45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- <Import Project="$(SolutionDir)\.nuget\nuget.targets" /> -->
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
6 changes: 5 additions & 1 deletion RestSharp/Http.Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace RestSharp
{
using RestSharp.Authenticators.OAuth.Extensions;

/// <summary>
/// HttpWebRequest wrapper (sync methods)
/// </summary>
Expand Down Expand Up @@ -264,7 +266,9 @@ private HttpWebRequest ConfigureWebRequest(string method, Uri url)
webRequest.ContentLength = 0;
}

webRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip | DecompressionMethods.None;
// webRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip | DecompressionMethods.None;
// Fabrizio
AllowedDecompressionMethods.ForEach(x => { webRequest.AutomaticDecompression |= x; });

#if FRAMEWORK
if (this.ClientCertificates != null)
Expand Down
5 changes: 5 additions & 0 deletions RestSharp/Http.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ public Encoding Encoding
/// </summary>
public Uri Url { get; set; }

/// <summary>
/// List of Allowed Decompression Methods
/// </summary>
public IList<DecompressionMethods> AllowedDecompressionMethods { get; set; }

/// <summary>
/// Flag to send authorisation header with the HttpWebRequest
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions RestSharp/IHttp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public interface IHttp

Uri Url { get; set; }

IList<DecompressionMethods> AllowedDecompressionMethods { get; set; }

HttpWebRequest DeleteAsync(Action<HttpResponse> action);

HttpWebRequest GetAsync(Action<HttpResponse> action);
Expand Down
7 changes: 7 additions & 0 deletions RestSharp/IRestRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public interface IRestRequest
/// </summary>
bool UseDefaultCredentials { get; set; }

/// <summary>
/// List of Allowed Decompression Methods
/// </summary>
IList<DecompressionMethods> AllowedDecompressionMethods { get; }

#if FRAMEWORK
/// <summary>
/// Adds a file to the Files collection to be included with a POST or PUT request
Expand Down Expand Up @@ -307,6 +312,8 @@ public interface IRestRequest
/// <returns></returns>
IRestRequest AddQueryParameter(string name, string value);

IRestRequest AddDecompressionMethod(DecompressionMethods decompressionMethod);

Action<IRestResponse> OnBeforeDeserialization { get; set; }

void IncreaseNumAttempts();
Expand Down
4 changes: 4 additions & 0 deletions RestSharp/RestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,10 @@ private void ConfigureHttp(IRestRequest request, IHttp http)
});
}
}

// Fabrizio: Set Request Allowed Decompression Methods to Http Allowed Decompression Methods
http.AllowedDecompressionMethods = request.AllowedDecompressionMethods;

#if FRAMEWORK
this.ConfigureProxy(http);
#endif
Expand Down
21 changes: 21 additions & 0 deletions RestSharp/RestRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public class RestRequest : IRestRequest
/// </summary>
public bool UseDefaultCredentials { get; set; }

/// <summary>
/// List of Allowed Decompresison Methods
/// </summary>
public IList<DecompressionMethods> AllowedDecompressionMethods { get; private set; }

/// <summary>
/// Default constructor
/// </summary>
Expand All @@ -75,6 +80,7 @@ public RestRequest()
this.Files = new List<FileParameter>();
this.XmlSerializer = new XmlSerializer();
this.JsonSerializer = new JsonSerializer();
this.AllowedDecompressionMethods = new[] { DecompressionMethods.None };

this.OnBeforeDeserialization = r => { };
}
Expand Down Expand Up @@ -504,6 +510,21 @@ public IRestRequest AddQueryParameter(string name, string value)
return this.AddParameter(name, value, ParameterType.QueryString);
}

/// <summary>
/// Add a Decompression Method to the request
/// </summary>
/// <param name="decompressionMethod">None | GZip | Deflate</param>
/// <returns></returns>
public IRestRequest AddDecompressionMethod(DecompressionMethods decompressionMethod)
{
if (!this.AllowedDecompressionMethods.Contains(decompressionMethod))
{
this.AllowedDecompressionMethods.Add(decompressionMethod);
}

return this;
}

/// <summary>
/// Container of all HTTP parameters to be passed with the request.
/// See AddParameter() for explanation of the types of parameters that can be passed
Expand Down

0 comments on commit 85c2048

Please sign in to comment.