Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 336358

Summary: Content-length header not set consistently when serving static resources through DefaultServlet
Product: [RT] Jetty Reporter: Matt Rose <mrose>
Component: serverAssignee: Greg Wilkins <gregw>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jetty-inbox
Version: 7.2.0   
Target Milestone: 7.2.x   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Matt Rose CLA 2011-02-04 10:15:58 EST
Just with the default jetty distribution running on my desktop, and the test.war file that's distributed with it, we have this situation.

Get a small file ( I haven't determined the size yet ), the length shows up fine.

mattrose@coltrane:~/Desktop$ wget -S http://localhost:8080/d.txt
--2011-02-03 15:52:34--  http://localhost:8080/d.txt
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:8080... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 200 OK
  Date: Thu, 03 Feb 2011 20:52:34 GMT
  Content-Type: text/plain
  Last-Modified: Wed, 20 Oct 2010 18:50:22 GMT
  Accept-Ranges: bytes
  Content-Length: 610
  Connection: keep-alive
  Server: Jetty(7.2.0.v20101020)
Length: 610 [text/plain]

Get a larger file, the length is not included in the headers on a GET request.

mattrose@coltrane:~/Desktop$ wget -S http://localhost:8080/da.txt
--2011-02-03 15:52:41--  http://localhost:8080/da.txt
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:8080... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 200 OK
  Date: Thu, 03 Feb 2011 20:52:41 GMT
  Content-Type: text/plain
  Last-Modified: Wed, 20 Oct 2010 18:50:22 GMT
  Accept-Ranges: bytes
  Server: Jetty(7.2.0.v20101020)
Length: unspecified [text/plain]

Oddly enough, when you do a HEAD request on the same file, the length is returned with the headers.

mattrose@coltrane:~/Desktop$ HEAD http://localhost:8080/da.txt
200 OK
Connection: close
Date: Thu, 03 Feb 2011 20:53:08 GMT
Accept-Ranges: bytes
Server: Jetty(7.2.0.v20101020)
Content-Length: 61000
Content-Type: text/plain
Last-Modified: Wed, 20 Oct 2010 18:50:22 GMT
Client-Date: Thu, 03 Feb 2011 20:53:08 GMT
Client-Peer: 127.0.0.1:8080
Client-Response-Num: 1

Just a theory at this point, it may not include the content-length in the header response, because when it starts to serve the file, it does not know the size of the file.  

It's hard for me to tell what's going on because there's no real debug information, even with debug logging turned on.
Comment 1 Matt Rose CLA 2011-02-04 10:18:19 EST
Expected behaviour is that jetty will always set content-length on static resources.
Comment 2 Greg Wilkins CLA 2011-02-23 00:35:36 EST
I just tried trunk and it works fine:

gregw@Brick: ~
[501] wget -S http://localhost:8080/da.txt
--2011-02-23 16:33:25--  http://localhost:8080/da.txt
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:8080... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 200 OK
  Date: Wed, 23 Feb 2011 05:33:25 GMT
  Accept-Ranges: bytes
  Content-Type: text/plain
  Content-Length: 61000
  Last-Modified: Sun, 05 Dec 2010 21:22:58 GMT
  Connection: keep-alive
  Server: Jetty(7.3.1-SNAPSHOT)
Length: 61000 (60K) [text/plain]
Saving to: `da.txt'

100%[======================================>] 61,000      --.-K/s   in 0s      

2011-02-23 16:33:25 (447 MB/s) - `da.txt' saved [61000/61000]


We have reworked the static content cache since 7.2.0, so I think we may have fixed it then.

Please reopen if it fails for you in a 7.3.x release
Comment 3 Matt Rose CLA 2011-04-13 09:10:05 EDT
Works in jetty 7.3.1
Comment 4 Matt Rose CLA 2011-04-13 09:10:31 EDT
thanks again for your help, btw.