yesodweb/wai — pull request #171 by wuzzeb (2013-09-03 17:10:11+00:00)
Title: Create a StaticSettings from embedded resources

I am splitting up the code in https://groups.google.com/forum/#!topic/yesodweb/5XuzQlVQYG0 and this is the piece that makes sense to add to wai-app-static. It is the code to embed resources; you must supply the contents to embed yourself. I think that is a good design for wai-app-static, the fancy stuff for automatically creating the embedding content can be left to yesod-static. A few comments

* This depends on the previous commit to wai-extra gzip middlewere since we precompress. I don't know if we want to add a dependency with lower version bound to prevent bad combinations or not, perhaps it is enough to just document the required wai-extra version.

* You should verify my use of unsafe functions are actually safe. I added a comment about why I think they are safe.

* It currently depends on template-haskell version 2.8 which limits to GHC 7.4 and above, not sure if this is a problem. I could use some CPP to support template-haskell 2.6

* I don't know why I write tests anymore :) Once the code compiled and type-checked, the tests passed the first time. Hurray for haskell's type system :)

* This code will precompress the content at compile time but only if the compressed content is shorter. If the compressed content is longer it will serve the noncompressed content. The problem is then if we decided not to compress the content the gzip middlewere will attempt to compress the content again. Even if the gzip middlewere was smart enough to serve the shorter text, we wasted time compressing something we already knew did not compress. Probably not a problem in practice since every real-world text/* will be compressible. One option to fix it would be in this module to return a Yesod-Gzip-DontCompress header when we decided not to compress so that the gzip gets out of the way. The problem is then if the gzip middlewere is not used this header leaks into the final response...