4

I am using pyramid web framework to build a website. I keep getting this warning in chrome console:

Resource interpreted as Font but transferred with MIME type application/octet-stream: "http:static/images/fonts/font.woff".

How do I get rid of this warning message?

I have configured static files to be served using add_static_view

I can think of a way to do this by adding a subscriber function for responses that checks if the path ends in .woff and setting the response header to application/x-font-woff. But it does not look like a clean solution. Is there a way to tell Pyramid to do it through some setting.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Ranjith Ramachandra
  • 10,399
  • 14
  • 59
  • 96

2 Answers2

7

Pyramid uses the standard mimetypes module to guess the mimetype based on the extension. It calls:

mimetypes.guess_type(path, strict=False)

The module looks in the Windows registry if on that platform, and in the following locations for mimetype lists:

knownfiles = [
    "/etc/mime.types",
    "/etc/httpd/mime.types",                    # Mac OS X
    "/etc/httpd/conf/mime.types",               # Apache
    "/etc/apache/mime.types",                   # Apache 1
    "/etc/apache2/mime.types",                  # Apache 2
    "/usr/local/etc/httpd/conf/mime.types",
    "/usr/local/lib/netscape/mime.types",
    "/usr/local/etc/httpd/conf/mime.types",     # Apache 1.2
    "/usr/local/etc/mime.types",                # Apache 1.3
    ]

You can either extend one of those files, or create your own file and add it to the module using the .init() function.

The file format is simple, just list the mimetype, then some whitespace, then a space-separated list of extensions:

application/x-font-woff     woff
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • For windows, open regedit, open the key `Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\` add a key for `.woff` and set the `Content Type` to `application/x-font-woff` – Soylent Graham Aug 08 '20 at 13:09
1

Simply add this following code where your Pyramid web app gets initialized.

import mimetypes mimetypes.add_type('application/x-font-woff', '.woff')

For instance, I have added it in my webapp.py file, which gets called the first time the server gets hit with a request.

kashiB
  • 207
  • 4
  • 14