Interesting little challenge today. I’m building an application that uses Web API and will run in an OWIN SelfHost and my payload as big enough to warrant GZip Compression. But, since my app is running as an Owin Selfhosted api, I can’t use IIS Compression.
So I created a little compression attribute. Seems to work great.
1: namespace eVision.AppShaping.Handlers.Controllers
2: {
3: using System.IO.Compression;
4: using System.Linq;
5: using System.Net.Http;
6: using System.Threading;
7: using System.Threading.Tasks;
8: using System.Web.Http.Filters;
9:
10: internal class GzipCompressedAttribute : System.Web.Http.Filters.ActionFilterAttribute
11: {
12: public override async Task OnActionExecutedAsync(HttpActionExecutedContext actContext, CancellationToken token)
13: {
14: bool supportGZip = actContext.Request.Headers.AcceptEncoding.Any(x => x.Value == "gzip");
15:
16: if (!supportGZip)
17: {
18: await base.OnActionExecutedAsync(actContext, token);
19: return;
20: }
21:
22: var contentStream = await actContext.Response.Content.ReadAsStreamAsync();
23:
24: actContext.Response.Content = new PushStreamContent(async (stream, content, context) =>
25: {
26: using(contentStream)
27: using (var zipStream = new GZipStream(stream, CompressionLevel.Optimal))
28: {
29: await contentStream.CopyToAsync(zipStream);
30: }
31: });
32:
33: actContext.Response.Content.Headers.Remove("Content-Type");
34: actContext.Response.Content.Headers.Add("Content-encoding", "gzip");
35: actContext.Response.Content.Headers.Add("Content-Type", "application/json");
36: }
37: }
38: }
Any working example?
ReplyDeletehere is another example, http://blog.developers.ba/asp-net-web-api-gzip-compression-actionfilter/ regards
DeleteThis is open source: https://github.com/Thorium/Owin.Compression
ReplyDeletedịch vụ dọn dẹp sổ sách kế toán
ReplyDeletedịch vụ dọn dẹp sổ sách kế toán tại thái bình
dịch vụ dọn dẹp sổ sách kế toán tại phú thọ
dịch vụ dọn dẹp sổ sách kế toán tại hưng yên
dịch vụ dọn dẹp sổ sách kế toán tại quận hải dương
dịch vụ dọn dẹp sổ sách kế toán tại hải phòng
dịch vụ dọn dẹp sổ sách kế toán tại quận thanh trì
dịch vụ dọn dẹp sổ sách kế toán tại quận hoàng mai
dịch vụ dọn dẹp sổ sách kế toán tại quận hai bà trưng
dịch vụ dọn dẹp sổ sách kế toán tại quận hoàn kiếm
dịch vụ dọn dẹp sổ sách kế toán tại quận từ liêm
dịch vụ dọn dẹp sổ sách kế toán tại quận ba đình
dịch vụ dọn dẹp sổ sách kế toán tại quận tây hồ
dịch vụ dọn dẹp sổ sách kế toán tại quận đống đa
dịch vụ dọn dẹp sổ sách kế toán tại bắc ninh
dịch vụ dọn dẹp sổ sách kế toán tại quận tphcm
dịch vụ dọn dẹp sổ sách kế toán tại quận cầu giấy
dịch vụ dọn dẹp sổ sách kế toán tại quận long biên
dịch vụ dọn dẹp sổ sách kế toán tại quận hà đông
dịch vụ dọn dẹp sổ sách kế toán tại quận thanh xuân
dich vu hoan thue
Great Article
DeleteCloud Computing Projects
Networking Projects
Final Year Projects for CSE
JavaScript Training in Chennai
JavaScript Training in Chennai
The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training
wow , thanks you shared
ReplyDeleteredhat certification in chennai | rhce training in chennai | redhat training in chennai |VMware training in chennai
Great useful Article
ReplyDeleteASP.NET Web API Training in Chennai
ASP.NET Web API Online Training
Dot Net Training in Chennai
ReplyDeleteExcellent post with valuable content. It is very helpful for me and a good post. Keep sharing...!
Social Media Marketing Courses in Chennai
Social Media Marketing Courses
Oracle Training in Chennai
Tableau Training in Chennai
Pega Training in Chennai
Embedded System Course Chennai
Oracle DBA Training in Chennai
Social Media Marketing Courses in Chennai
Social Media Marketing Training in Chennai
I have read your blog and I gathered some needful information from your blog. Keep update your blog. Awaiting for your next update. Thanks
ReplyDeleteDedicatedHosting4u.com
I am overwhelmed by your post with such a nice topic. Usually, I visit your blogs and get updated with the information you include but today’s blog would be the most appreciable...
ReplyDeleteThanks
Cpa offers
Your article is worth reading! You are providing a lot of valid information.This'll be really helpful for my reference. Do share more such articles.
ReplyDeleteR Training in Chennai
Data Analytics Training in Chennai
Data Science Training in Chennai
UiPath Training in Chennai
Cloud Computing Training in Chennai
R Training in OMR
R Training in Porur
R Training in Vadapalani
This is a fantastic idea! I like it a lot because it's super easy for the audience to see the value of opting in. wonderful and amazing post very use full your post thanks for sharing your article
ReplyDeleteAndroid Application development
Web application
ReplyDeleteYour post is very good. I got to learn a lot from your post. Thank you for sharing your article for us. it is amazing post
what is seo
types of seo
TreasureBox is operated by a group of young, passionate, and ambitious people that are working diligently towards the same goal - make your every dollar count, as we believe you deserve something better.
ReplyDeleteMattress
entertainment unit
furniture nz
Thanks for sharing such a nice info.I hope you will share more information like this. please keep on sharing!
ReplyDeleteRPA Training in Chennai
RPA course in Chennai
Robotics Process Automation Training in Chennai
RPA Training Institute in Chennai
RPA Classes in Chennai
Thanks for sharing such a nice info.I hope you will share more information like this. please keep on sharing!
ReplyDeleteRPA Training in Bangalore
RPA Course in Bangalore
Best RPA Training in Bangalore
RPA Training in Marathahalli
RPA Training in Coimbatore
RPA Training in Btm
Very good blog which explains really well about Selenium technology.
ReplyDeleteMicrosoft Windows Azure Training | Online Course | Certification in chennai | Microsoft Windows Azure Training | Online Course | Certification in bangalore | Microsoft Windows Azure Training | Online Course | Certification in hyderabad | Microsoft Windows Azure Training | Online Course | Certification in pune
wonderful article contains lot of valuable information. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
ReplyDeleteThis article resolved my all queries.good luck an best wishes to the team members.continue posting.learn digital marketing use these following link
Digital Marketing Course in Chennai