play.filters.gzip

GzipFilter

class GzipFilter extends EssentialFilter

A gzip filter.

This filter may gzip the responses for any requests that aren't HEAD requests and specify an accept encoding of gzip.

It will only gzip non chunked responses. Chunked responses are often comet responses, gzipping will interfere in that case. If you want to gzip a chunked response, you can apply the gzip enumeratee manually to the enumerator.

For non chunked responses, it won't gzip under the following conditions:

- The response code is 204 or 304 (these codes MUST NOT contain a body, and an empty gzipped response is 20 bytes long) - The response already defines a Content-Encoding header - The response content type is text/event-stream - A custom shouldGzip function is supplied and it returns false

Since gzipping changes the content length of the response, this filter may do some buffering. If a content length is sent by the action, that content length is filtered out and ignored. If the connection flag on the result is Close, the filter will not attempt to buffer, and will simply rely on the closing the response to signify the end of the response. Otherwise, it will buffer up to the configured chunkedThreshold, which defaults to 100kb. If the response fits in that buffer, the filter will send the content length, otherwise it falls back to sending a chunked response, or if the protocol is HTTP/1.0, it closes the connection at the end of the response.

You can use this filter in your project simply by including it in the Global filters, like this:

object Global extends WithFilters(new GzipFilter()) {
...
}
Source
GzipFilter.scala
Linear Supertypes
EssentialFilter, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. GzipFilter
  2. EssentialFilter
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new GzipFilter()

    This allows it to be used from Java

  2. new GzipFilter(chunkedThreshold: Int)

    Allows use with a custom chunked threshold from Java

  3. new GzipFilter(gzip: Enumeratee[Array[Byte], Array[Byte]] = ..., chunkedThreshold: Int = GzipFilter.DefaultChunkedThreshold, shouldGzip: (RequestHeader, ResponseHeader) ⇒ Boolean = ...)

    gzip

    The gzip enumeratee to use.

    chunkedThreshold

    The content length threshold, after which the filter will switch to chunking the result.

    shouldGzip

    Whether the given request/result should be gzipped. This can be used, for example, to implement black/white lists for gzipping by content type.

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. def apply(next: EssentialAction): EssentialAction

    Definition Classes
    GzipFilterEssentialFilter
  7. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  8. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  13. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  14. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  15. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  16. final def notify(): Unit

    Definition Classes
    AnyRef
  17. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  18. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  19. def toString(): String

    Definition Classes
    AnyRef → Any
  20. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from EssentialFilter

Inherited from AnyRef

Inherited from Any

Ungrouped