Rails + gzip: random content-length header

Discussion in 'Bug Reports' started by andreas, Oct 29, 2007.

  1. andreas

    andreas New Member

    Hi,

    I'm running Rails on LSWS with dynamic response gzip compression. I noticed that Safari would try to render even short pages before they were fully loaded, and blamed it on the missing content-length header. In order to get a content-length header I enabled response buffering. Unfortunately it doesn't work reliably; some responses have a content-length header, some just don't (for the same request). Any ideas why that might be?

    Andreas
  2. andreas

    andreas New Member

    nothing?

    Code:
    $ lynx -mime-header http://www.mikrocontroller.net/topic/40008 | head -n 11
    HTTP/1.0 200 OK
    Content-Type: text/html; charset=utf-8
    Set-Cookie: return_to=%2Ftopic%2F40008; path=/
    Set-Cookie: _session_id=bfc34e7857d23aadab1f5492d2772c13; path=/; expires=Thu, 20 Nov 2008 22:44:19 GMT
    Cache-Control: no-cache
    Content-Encoding: gzip
    Vary: Accept-Encoding
    Date: Wed, 21 Nov 2007 17:11:19 GMT
    Server: LiteSpeed
    Connection: close
    
    $ lynx -mime-header http://www.mikrocontroller.net/topic/40008 | head -n 11
    HTTP/1.0 200 OK
    Content-Type: text/html; charset=utf-8
    Set-Cookie: return_to=%2Ftopic%2F40008; path=/
    Set-Cookie: _session_id=18640c2e04e6d0173f024c0ebb0cb189; path=/; expires=Thu, 20 Nov 2008 22:44:19 GMT
    Cache-Control: no-cache
    Content-Encoding: gzip
    Vary: Accept-Encoding
    Content-Length: 5289
    Date: Wed, 21 Nov 2007 17:11:20 GMT
    Server: LiteSpeed
    Connection: close
  3. mistwang

    mistwang LiteSpeed Staff

    It depends on the timing that LSWS receives the full response from backend application.
    When Content-Length is not set, "Chunked" "Transfer-Encoding" should use for HTTP 1.1 client. lynx is a HTTP 1.0 client, so none of above header is set.
    The problem with Safari might not be the header problem, maybe need to sniff the network traffic with tcpdump or something to figure it out.
  4. andreas

    andreas New Member

    Thanks, I understand now. I see the chunked header when I use
    Code:
    curl --compressed -D header http://www.mikrocontroller.net/topic/40003
    .

    Is there a way to enable response buffering for rails contexts (I guess this would disable chunked encoding)? Rails sends the response in one part anyway.
  5. mistwang

    mistwang LiteSpeed Staff

    You can trun on response buffering under "Ruby Rails" tab, It won't work reliably for large pages though.
  6. mistwang

    mistwang LiteSpeed Staff

    A HTTP/1.1 browser should support chunk encoding without any problem.

Share This Page