Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

restsharp accept-encoding disabling compression

In a particular case I need to be able to disable compression in the requst/response.

Using Firefox RestClient I am able to post some xml to a web service and get some response xml successfully with a single header parameter "Accept-Encoding" : " " which if I do not set this header, the response body would come back compressed with some binary data in the response body(that's why I want to disable gzip in response)

Now using the same header value in my app (using RestSharp in C#), I still get the binary data (gzip) in response.

Can someone please shed some light? Is it supported in RestSharp?

like image 832
user3801443 Avatar asked Jul 03 '14 12:07

user3801443


2 Answers

RestSharp does not support disabling compression.

If you look at the source code in Http.Sync.cs line 267 (assuming a sync request, async has the same code duplicated in Http.Async.cs line 424)

webRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip | DecompressionMethods.None;

that is, the underlying WebRequest that Restsharp uses to make the http call has the compression options hardcoded. There is an open issue that documents this

like image 60
wal Avatar answered Nov 19 '22 15:11

wal


The feature (only just) seems to have been added, but stealthily - without a note on the issue's status nor on the changelogs. Possibly as it hasn't been sufficiently tested?

Nevertheless I recently had a need for this functionality and tested it - and it works. Just set the RestClient instance's AutomaticDecompression property to false.

If you intend to keep your RestClient instance long-lived remember to do this before its first use - the setting seems to be 'locked in' after use and cannot change after. In my case I needed to make calls with and without AutomaticDecompression so i simply created two different RestClient instances.

like image 29
Bo Ngoh Avatar answered Nov 19 '22 15:11

Bo Ngoh