Blog‎ > ‎

How to correctly define character set information for static HTML files when using Google App Engine

posted Dec 30, 2012, 5:51 AM by Sami Lehtinen   [ updated Jan 6, 2013, 5:09 AM ]
I just tried several times to define character set (inside the document) for static files served from Google App Engine and failed miserably. It seems that Google doesn't read meta tags like http-equiv from file when serving those. Therefore static files didn't contain correct Content-Type header with charset definition.

HTML file contains hint for web browser, but it's not passed as HTTP response header.

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Naturally if I use script (or Python Google App Engine program) then I can get it delivered correctly as response headers.

    self.response.headers['Content-Type'] = 'text/html; charset=UTF-8'

Which returns correct header line in response header:

    Content-Type: text/html; charset=UTF-8


To fix this for static files, you'll need to define charset in app.yaml file:

    - url: /
      static_files: root/create.html
      upload: root/create.html
      mime_type: text/html; charset=UTF-8

Now Content-Type header for static files also correctly contains character set information.

    Content-Type: text/html; charset=UTF-8

kw: GAE, Python, document, documents, file, files, encoding, mime type, html5, browser, server, headers, header, encodings, utf-8, character set.