Add GZip Support thru SharpGIS.GZipWebClient

139 views
Skip to first unread message

Pedro Lamas

unread,
Jan 23, 2012, 6:25:42 AM1/23/12
to RestSharp
Since Windows Phone doesn't support GZip out of the box and after
reading an excellent article from Jeff Wilcox on
SharpGIS.GZipWebClient (you can find it here:
http://www.jeff.wilcox.name/2012/01/windows-phone-gzip-support-by-morten/),
I ask why not support SharpGIS.GZipWebClient on RestSharp?

I know that there will be some rearranging work over the classes, but
it does sound "doable" to me! :)

Jake Ginnivan

unread,
Jan 23, 2012, 7:23:02 AM1/23/12
to rest...@googlegroups.com
+1 to this, it would a quick win for anyone using RestSharp on WP7.

Pedro Lamas

unread,
Jan 23, 2012, 12:26:14 PM1/23/12
to RestSharp
Just noticed that RestClient has a property called HttpFactory of type
IHttpFactory.

IHttpFactory has a single method, Create, that return an IHttp
instance.

So, how hard can it be to just make an IHttpFactory and an IHttp class
that works as a shell for SharpGIS.GZipWebClient? :)

Jeremy Brayton

unread,
Jan 23, 2012, 2:25:22 PM1/23/12
to rest...@googlegroups.com
Have you looked at GZipWebClient? the bulk of the work is in the Zlib implementation and the client itself is just basically overriding the internal WebRequest/WebResponse.

You could likely get away with WebClient but restsharp goes much deeper. If it were my undertaking, I'd match it tit for tat and use request/response instead. The problem with that is it is pretty extensive to create a 1:1 branch of everything using 2 possible outcomes. Luckily you don't really have to as Morten just overrides the base classes and only does decompression if the gzip header is present. You would just have to understand the added layer if you wanted to inspect the code as you wouldn't be looking at the "traditional" request/response directly but that's hardly a reason not to include it.

Considering the Zlib code is ripped from DotNetZip which has mono support, it should "just work" on the mono side of things. Of course I'm not too aware of all the clients supported like monodroid but hopefully it wouldn't introduce too much of a headache. It's almost amazing to wonder why this wasn't included as part of the core framework on all CLR platforms a while back.

dkarzon

unread,
Jan 23, 2012, 5:37:26 PM1/23/12
to RestSharp
I have implemented this in my RestSharp fork but not too sure how I
can test this.

Anyone want to give it a go?

https://github.com/dkarzon/RestSharp/commit/06ecbee6ba5e99119b8c510a6b213f42f73d78aa#diff-10

John Sheehan

unread,
Jan 23, 2012, 6:04:40 PM1/23/12
to rest...@googlegroups.com
I thought there was a way to deflate gzip content without a dependency. I did it once but I can't find the code. 

If we can add this for WP7 without another library dependency I'm all for it. Otherwise, you can use OnBeforeDeserialization to deflate it before it hits the deserializer.

dkarzon

unread,
Jan 23, 2012, 6:15:10 PM1/23/12
to RestSharp
Yeh didnt really want to use the extra dependency for it.
OnBeforeDeserialization is a good idea, might give that a go.

Pedro Lamas

unread,
Jan 24, 2012, 4:31:05 AM1/24/12
to RestSharp

I like the way you're thinking John! :)

Frankly, dependencies are a pain (like the problem with Json.net
you're getting right now -- by the day, Json.net was updated
yesterday, so RestSharp Silverlight version is broken once more... :
\ )
Reply all
Reply to author
Forward
0 new messages