jgiacomini / Tiny.RestClient

Simpliest Fluent REST client for .NET
MIT License
210 stars 30 forks source link

Compressed responses dispose before they can be read #114

Closed Arithmomaniac closed 3 years ago

Arithmomaniac commented 4 years ago

I couldn't get GZip result decompression to return anything but null, so I took a look.

In TinyRestClient.DecompressAsync:

https://github.com/jgiacomini/Tiny.RestClient/blob/213a8bc5e74a51d284cf2d559b42dde6736069a0/Tiny.RestClient/TinyRestClient.cs#L784-L791

Because this is a finally clause instead of a catch clause, it's always disposed. Which means the stream.CanRead fails here:

https://github.com/jgiacomini/Tiny.RestClient/blob/213a8bc5e74a51d284cf2d559b42dde6736069a0/Tiny.RestClient/TinyRestClient.cs#L336-L339

Would it be sufficient to switch this to a catch? Will it be disposed later otherwise?

jgiacomini commented 3 years ago

Hello @ Arithmomaniac, Sorry for the very late answer. My automatic decompression is very problematic because when you use HttpClient you don't have same behavior between each framework.

For example => Xamarin.iOS, have a different behavior .NET or .NET Core.

I think I will remove it, in the next versions because lot of bugs come from this feature.

I suggest to remove the automatic Decompression in your side : client.Settings.Compressions.Clear

And configure the HttpClient to let it decompress the HttpResponses : https://stackoverflow.com/questions/20990601/decompressing-gzip-stream-from-httpclient-response Jérôme.