Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Ticket #599 (defect)

Opened 2 years ago

Last modified 2 years ago

Trouble with GZip and Etag (with enabled autotags)

Status: closed (fixed)

Reported by: Andrew <stromnov@gmail.com> Assigned to: rdelon
Priority: normal Milestone: 3.0
Component: CherryPy code Keywords:
Cc: stromnov@gmail.com

First query:

127.0.0.1 - - [07/Nov/2006:17:54:05] "GET /css/low.css HTTP/1.1" 200 423 "http://localhost:8080/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0"

Second query:

[07/Nov/2006:17:54:55]  Traceback (most recent call last):
  File "C:\Projects\dev\trunk\cherrypy\_cprequest.py", line 80, in run
    hook()
AttributeError: 'NoneType' object has no attribute 'split'

[07/Nov/2006:17:54:55] HTTP
Request Headers:
  COOKIE: session_id=86c16b7568a2272fd7aad76bad20ce1926637ec7
  HOST: localhost:8080
  CONNECTION: keep-alive
  CACHE-CONTROL: max-age=0
  IF-MODIFIED-SINCE: Tue, 31 Oct 2006 08:53:25 GMT
  Remote-Addr: 127.0.0.1
  ACCEPT: text/css,*/*;q=0.1
  ACCEPT-CHARSET: ISO-8859-1,utf-8;q=0.7,*;q=0.7
  USER-AGENT: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0
  REFERER: http://localhost:8080/
  ACCEPT-LANGUAGE: ru,en-us;q=0.7,en;q=0.3
  IF-NONE-MATCH: "b9d4ff1944688924310ff7dcc84b408c"
  Remote-Host: 127.0.0.1
  ACCEPT-ENCODING: gzip,deflate
  KEEP-ALIVE: 300

Code:

class WebServer:
    _cp_config = {"tools.sessions.on": True,
                  "tools.gzip.on": True,
                 }
    
    @cherrypy.tools.etags(autotags=True)
    @cherrypy.expose
    def default(self, *args, **kwargs):
        loader = TemplateLoader(...)

        if len(args) == 0:
            args = ['index']

        path = loader.find(os.path.sep.join(args)+'.html')
        if path:
            tmpl = loader.load(os.path.sep.join(args)+".html")
            stream = tmpl.generate()
            return stream.render('xhtml')

        path = loader.find(os.path.sep.join(args))
        if path:
            return cherrypy.lib.static.serve_file(path)

If one of GZip or Etag turned off, then all works as expected.

PS. Sometimes:

  File "C:\Projects\dev\trunk\cherrypy\_cprequest.py", line 374, in respond
    self.hooks.run('before_finalize')
AttributeError: 'NoneType' object has no attribute 'split'

Change History

11/16/06 18:13:42: Modified by fumanchu

And what problem are you seeing? I can't seem to reproduce this.

11/17/06 04:19:08: Modified by Andrew <stromnov@gmail.com>

Full code:

# Imports
import sys, os
import cherrypy

class WebServer:
    _cp_config = {"tools.gzip.on": True,
                  "tools.gzip.compress_level": 5,
                 }

    @cherrypy.tools.etags(autotags=True)
    @cherrypy.tools.decode()
    @cherrypy.tools.encode(encoding='utf8', errors='strict') # errors='ignore'
    @cherrypy.expose
    def default(self, *args, **kwargs):
        if ''.join(args) == 'shadow.jpg':
            path = os.path.abspath(os.path.sep.join(args))
            return cherrypy.lib.static.serve_file(path)
        return '''<html><head><title>CherryPy Test</title></head>
                  <body>some<img src="/shadow.jpg" />text</body></html>'''

if __name__ == "__main__":
    cherrypy.quickstart(WebServer())

First request output:

[17/Nov/2006:13:11:41] HTTP Serving HTTP on http://localhost:8080/
127.0.0.1 - - [17/Nov/2006:13:11:45] "GET / HTTP/1.1" 200 110 "" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0"
127.0.0.1 - - [17/Nov/2006:13:11:45] "GET /shadow.jpg HTTP/1.1" 200 743 "http://localhost:8080/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0"

Second request ('Reload' in browser):

127.0.0.1 - - [17/Nov/2006:13:11:51] "GET / HTTP/1.1" 304 - "" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0"
[17/Nov/2006:13:11:51]  Traceback (most recent call last):
  File "C:\Projects\dev\trunk\cherrypy\_cprequest.py", line 80, in run
    hook()
  File "C:\Projects\dev\trunk\cherrypy\_cprequest.py", line 45, in __call__
    return self.callback(**self.kwargs)
  File "\Python24\Lib\site-packages\cherrypy\lib\encoding.py", line 215, in gzip

AttributeError: 'NoneType' object has no attribute 'split'

[17/Nov/2006:13:11:51] HTTP
Request Headers:
  COOKIE: session_id=c83c93a77cad4160a6dc2a396cc7297ff1a0a32d
  HOST: localhost:8080
  CONNECTION: keep-alive
  CACHE-CONTROL: max-age=0
  IF-MODIFIED-SINCE: Mon, 13 Nov 2006 17:01:38 GMT
  Remote-Addr: 127.0.0.1
  ACCEPT: image/png,*/*;q=0.5
  ACCEPT-CHARSET: ISO-8859-1,utf-8;q=0.7,*;q=0.7
  USER-AGENT: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0
  REFERER: http://localhost:8080/
  ACCEPT-LANGUAGE: ru,en-us;q=0.7,en;q=0.3
  IF-NONE-MATCH: "21d5369b48f6a120ef3ece07c915c944"
  Remote-Host: 127.0.0.1
  ACCEPT-ENCODING: gzip,deflate
  KEEP-ALIVE: 300
[17/Nov/2006:13:11:51] HTTP Traceback (most recent call last):
  File "C:\Projects\dev\trunk\cherrypy\_cprequest.py", line 374, in respond
    self.hooks.run('before_finalize')
  File "C:\Projects\dev\trunk\cherrypy\_cprequest.py", line 80, in run
    hook()
  File "C:\Projects\dev\trunk\cherrypy\_cprequest.py", line 45, in __call__
    return self.callback(**self.kwargs)
  File "\Python24\Lib\site-packages\cherrypy\lib\encoding.py", line 215, in gzip

AttributeError: 'NoneType' object has no attribute 'split'

127.0.0.1 - - [17/Nov/2006:13:11:51] "GET /shadow.jpg HTTP/1.1" 500 1324 "http://localhost:8080/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0"

Third request - same as first, fourth - as second, etc...

11/18/06 19:56:20: Modified by fumanchu

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in [1441].

Hosted by WebFaction

Log in as guest/cpguest to create tickets