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

Post date: Dec 30, 2012 1:51:43 PM

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.