cloudflare / templates

A collection of starter templates and examples for Cloudflare Workers and Pages
https://cloudflareworkers.com
MIT License
999 stars 632 forks source link

Pass-through non-utf-8 HTML content #14

Closed pmeenan closed 5 years ago

pmeenan commented 5 years ago

It turns out Workers can only (currently) decode utf-8 (or charsets that transparently decode as utf-8). The examples previously had support for detecting the encoding and using the appropriate decoder. This changes it so that content is passed through unmodified if it is an unsupported charset (or if decoding of any data chunk fails).

It also changes how proxied HTTP requests are handled and creates a new request object instead of re-using the inbound request (needed for Apps but also good for filtering the headers that are passed through so cookies don't leak).

pmeenan commented 5 years ago

@zackbloom - if you could merge again when you get a chance.