dropwizard / dropwizard

A damn simple library for building production-ready RESTful web services.
https://www.dropwizard.io
Apache License 2.0
8.48k stars 3.44k forks source link

compressedMimeTypes property does not work as expected #8938

Open jprakashbabu opened 4 weeks ago

jprakashbabu commented 4 weeks ago

Hi,

I am using dropwizard 2.1.11 and enabled compression for certain mime types using the configuration option compressedMimeTypes as shown below. compressedMimeTypes : text/html,text/xml,application/x-javascript,text/javascript,text/css and see that application/x-javascript is not getting compressed even though its there in the list

HTTP/1.1 200 OK
Date: Tue, 11 Jun 2024 20:02:31 GMT
Cache-Control: public, max-age=31536000
Date: Tue, 11 Jun 2024 20:02:31 GMT
Accept-Ranges: bytes
Content-Type: application/x-javascript
Last-Modified: Sat, 01 Jun 2024 20:44:38 GMT
Transfer-Encoding: chunked

However if I don't specify any compressedMimeTypes and leave the default values to get picked up, application/x-javascript gets compressed (Content-Encoding: gzip)

HTTP/1.1 200 OK
Date: Tue, 11 Jun 2024 19:47:54 GMT
Cache-Control: public, max-age=31536000
Date: Tue, 11 Jun 2024 19:47:54 GMT
Accept-Ranges: bytes
Content-Type: application/x-javascript
Last-Modified: Sat, 01 Jun 2024 20:44:38 GMT
Vary: Accept-Encoding
Content-Encoding: gzip
Transfer-Encoding: chunked
Can you please let me know if I am missing something here (or) is the exclude list taking precedence over the include ?

PS: Both the above requests were identical and had Accept-Encoding:gzip, deflate, br, zstd

thanks, Prakash

zUniQueX commented 3 weeks ago

Hi @jprakashbabu. Dropwizard 2.1.11 and the provided Jetty version 9.4.53 are out of support, so please migrate to a more recent Dropwizard version. In general, we won't provide full support for versions announced to be EOL. The correct place would be the discussion board. Please don't raise a discussion and an issue, usually only one option fits :wink:

That being said, I don't see an issue here. When using your include list

server:
  gzip:
    enabled: true
    compressedMimeTypes:
      - text/html
      - text/xml
      - application/x-javascript
      - text/javascript
      - text/css

my JS file gets compressed correctly.

Can you please let me know if I am missing something here (or) is the exclude list taking precedence over the include ?

When checking, if the MIME-type should be compressed, Jetty first evaluates the include list and then additionally validates, that the type is not in the exclude list. The default exclude list however doesn't list application/x-javascript as an excluded MIME-type.