Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Api gzip compression

I have used this URL for the web API compression but when I see the out put in the fiddler header is not zip. there are multiple Zip option are available example GZIP, BZIP2 DEFLATE not sure which one to use kindly help here

I have tried with the below solution and both of them are not working :

http://benfoster.io/blog/aspnet-web-api-compression

like image 858
user3227615 Avatar asked Apr 23 '16 15:04

user3227615


1 Answers

there are multiple Zip option are available example GZIP, BZIP2 DEFLATE not sure which one to use kindly help here

This list will be sent to the server and let it know about the client side preferences about compression. It means "I first prefer GZIP. If GZIP not supported by the server side then fallback to BZIP2 DEFLATE compression. If BZIP2 DEFLATE not supported then the server will not do any compression."

There is someone who already create a nuget package that use that implementation you just put in your question. The package name is Microsoft.AspNet.WebApi.MessageHandlers.Compression which install the following two packages :

  • Microsoft.AspNet.WebApi.Extensions.Compression.Server
  • System.Net.Http.Extensions.Compression.Client

If you don't need the client side library then just just the server side package in your Web API project.

To use it you need to modify to add the following line at the end of your Application_Start method in Gloabl.asax.cs:

GlobalConfiguration.Configuration.MessageHandlers.Insert(0, new ServerCompressionHandler(new GZipCompressor(), new DeflateCompressor()));

To learn more about this package check this link.

like image 126
CodeNotFound Avatar answered Oct 05 '22 02:10

CodeNotFound