Issue #58 resolved

Standard favicon.ico icon

Anonymous created an issue

Add utility functions to include a favicon.ico image on the standard CherryPy distribution, making easy for native CP2 applications to use it. The icon is stored into a plain Python file, encoded with base64. A utility function can be used to send it as a response, with all headers set correctly. The user only needs to capture the cpg.root.default() method, check the path for favicon, and call the function.

Reported by cribeiro

Comments (10)

  1. Anonymous

    A static file can't be as easily distributed and referred to by the user site. This particular static file needs to be at the root of the site. The current mechanism that serves static files remaps the entire dir to one that have static files only; remapping the root dir would make entire site static! To make matters worse, the name used (favicon.ico) is not a valid Python name. If it was simply "favicon" we could do it as follows (just a sample):

    cpg.root.favicon = FavIcon()
    

    But this also does not work, because there's a period in the name.

    So the solution proposed simply adds a few utility functions to make it easier for the user to add a default method to the root, which in turn will serve the favicon.ico object. It's also worth mentioning that the same class of problems also affects the standard robots.txt file, which is also at the root of the site, and have a period in the name.

  2. Anonymous

    Looks like changeset [133] fixed the dotted-name issue by changing dots to underscores. So anyone can now make a favicon_ico() method.

    Perhaps all we need is a utility function that such a method could call to emulate being a static file. The code in _cphttptools which serves static files could be pulled out into its own function, open_static().

    Attaching a patch (+ icon, for testing) which does that. Well, not quite. Instead of giving the app developer direct access to open_static, they can raise cpg.StaticFile(filename) and expect that file to be served for them. See testStaticContent.py in the patch for an example.

  3. Log in to comment