Search in sources :

Example 1 with ResponseCompressionAnalyzer

use of org.apache.tapestry5.http.services.ResponseCompressionAnalyzer in project tapestry-5 by apache.

the class PageTesterModule method setupTestableOverrides.

@Contribute(ServiceOverride.class)
public static void setupTestableOverrides(MappedConfiguration<Class, Object> configuration, @Local TestableRequest request, @Local TestableResponse response, final ObjectLocator locator) {
    configuration.add(Request.class, request);
    configuration.add(Response.class, response);
    TestableCookieSinkSource cookies = new TestableCookieSinkSource();
    configuration.add(CookieSink.class, cookies);
    configuration.add(CookieSource.class, cookies);
    // With the significant changes to the handling of assets in 5.4, we introduced a problem:
    // We were checking at page render time whether to generate URLs for normal or compressed
    // assets and that peeked at the HttpServletRequest global, which isn't set up by PageTester.
    // What we're doing here is using a hacked version of that code to force GZip support
    // on.
    configuration.add(ResponseCompressionAnalyzer.class, new ResponseCompressionAnalyzer() {

        public boolean isGZipEnabled(ContentType contentType) {
            return locator.getObject(CompressionAnalyzer.class, null).isCompressable(contentType.getMimeType());
        }

        public boolean isGZipSupported() {
            return true;
        }
    });
}
Also used : ContentType(org.apache.tapestry5.http.ContentType) ResponseCompressionAnalyzer(org.apache.tapestry5.http.services.ResponseCompressionAnalyzer) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Aggregations

ContentType (org.apache.tapestry5.http.ContentType)1 ResponseCompressionAnalyzer (org.apache.tapestry5.http.services.ResponseCompressionAnalyzer)1 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)1