LessCssHttpHandler compression implementation (GZIP/DEFLATE) #169

Closed
davetransom opened this Issue Apr 11, 2012 · 3 comments

Comments

Projects
None yet
2 participants
@davetransom

Wondering if you'd considered how compression has been implemented in the LessCssHttpHandler. Using acceptEncoding.Contains("GZIP") misses explicit exclusions of GZIP, but also doesn't account for the preferred encoding as specified in the header.

I wrote a blog post a few years ago detailing the behaviour (which seems to be commonly misused);
http://www.singular.co.nz/blog/archive/2008/07/06/finding-preferred-accept-encoding-header-in-csharp.aspx

I was going to fork, but thought I should get your opinion first.

It concerns: 'src/dotless.AspNet/LessCssHttpHandler.cs'

var acceptEncoding = (context.Request.Headers["Accept-Encoding"] ?? "").ToUpperInvariant();

if (acceptEncoding.Contains("GZIP"))
{
    context.Response.AppendHeader("Content-Encoding", "gzip");
    context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
}
else if (acceptEncoding.Contains("DEFLATE"))
{
    context.Response.AppendHeader("Content-Encoding", "deflate");
    context.Response.Filter = new DeflateStream(context.Response.Filter,
                                                CompressionMode.Compress);
}

Additionally, perhaps HttpCompression should also be configurable (on/off) - in case a user wants to handle compression through IIS or some middle tier.

@lukeapage

This comment has been minimized.

Show comment Hide comment
@lukeapage

lukeapage Apr 12, 2012

Member

Everything you say sounds sensible. If you give us a pull request I´m
sure we would accept, otherwise I can look at it at some point in the
future.

Thanks!

Member

lukeapage commented Apr 12, 2012

Everything you say sounds sensible. If you give us a pull request I´m
sure we would accept, otherwise I can look at it at some point in the
future.

Thanks!

@lukeapage lukeapage closed this in 1ed5999 Apr 15, 2012

@lukeapage

This comment has been minimized.

Show comment Hide comment
@lukeapage

lukeapage Apr 15, 2012

Member

many thanks, I enjoyed reading your blog article. It was simple to do, so I've used your code verbatim, the only change was that I noticed that although you compare case insensitive in order to get the preferred list you get back the preferred encoding name in the original casing and use it in the switch.. I've no idea if the casing ever changes but I put it to lower before switching on it.

Member

lukeapage commented Apr 15, 2012

many thanks, I enjoyed reading your blog article. It was simple to do, so I've used your code verbatim, the only change was that I noticed that although you compare case insensitive in order to get the preferred list you get back the preferred encoding name in the original casing and use it in the switch.. I've no idea if the casing ever changes but I put it to lower before switching on it.

@davetransom

This comment has been minimized.

Show comment Hide comment
@davetransom

davetransom Apr 15, 2012

Glad it was of some help - I was planning on forking, but you beat me to the implementation - nice work :)

And good spotting on the casing - will update my blog too.

Glad it was of some help - I was planning on forking, but you beat me to the implementation - nice work :)

And good spotting on the casing - will update my blog too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment