Skip to content

Incorrect http response for a request using the Range header for pre-compressed resources #25976

Closed
@180254

Description

@180254

What happened:
I use serving pre-compressed resources (spring.resources.chain.compressed), index.html is also compressed.
I found that Facebook Sharing Debugger (https://developers.facebook.com/tools/debug/) doesn't work for my website.

The Facebook Crawler (https://developers.facebook.com/docs/sharing/webmasters/crawler) sends the following request:

"request" : {
  "method" : "GET",
  "uri" : "https://example.com",
  "headers" : {
    "host" : [ "example.com" ],
    "range" : [ "bytes=0-524287" ],
    "x-forwarded-for" : [ "0.0.0.0" ],
    "accept-encoding" : [ "deflate, gzip" ],
    "accept" : [ "*/*" ],
    "user-agent" : [ "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)" ]
  },
  "remoteAddress" : null
},

Spring boot serves pre-compressed file (index.html.gz), response has the following headers:

"response" : {
  "status" : 206,
  "headers" : {
    "Accept-Ranges" : [ "bytes" ],
    "Content-Range" : [ "bytes 0-177/178" ],
    "Connection" : [ "close" ],
    "Vary" : [ "Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers" ],
    "Last-Modified" : [ "Sun, 25 Oct 2020 20:36:37 GMT" ],
    "Content-Length" : [ "178" ],
    "Content-Language" : [ "en-US" ],
    "Date" : [ "Sun, 25 Oct 2020 20:36:46 GMT" ],
    "Content-Type" : [ "text/html;charset=UTF-8" ]
  }
},

In the above scenario server serves a pre-compressed resource, but does not inform about used compression.

What you expected to happen:
The following headers are included in the response:

Vary: Accept-Encoding
Content-Encoding: gzip

How to reproduce it:
Reproduction-steps code: https://github.com/180254/spring-boot-issue-23830

[n] means "terminal number n"
[1] $ mvn clean package
[1] $ java -jar target/demo-0.0.1-SNAPSHOT.jar
[2] $ curl -v -H "Accept-Encoding: gzip" -H "Range: bytes=0-1000" -H "Connection: close" -A "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)" "http://localhost:8080/" -o outputfile

Pay attention to the request&response headers in the curl log and/or visit http://localhost:8080/actuator/httptrace to see http trace.

Check if compression was requested, check if information about compression exist in response. Check if "outputfile" contains compressed or uncompressed data.

Reproducing initial problem: Use example above, run it at any public address and use Facebook Sharing Debugger. Facebook Sharing Debugger uses the compressed bytes as a final response. There is no info from server the data should be uncompressed beforehand.

Anything else we need to know?:
I tried to use the following embedded servers: Tomcat, Jetty, Undertow. There is the same problem for each of them.

Environment:
Spring Boot 2.3.4.RELEASE
Apache Tomcat/9.0.38
Apache Maven 3.6.3
Java version: 11.0.9, vendor: AdoptOpenJDK, runtime: /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions