Fixes token initialization.
Content-Type is implicitly set in response.prepare!, but that is called after setting the body to avoid setting a content length.
We also reference the flash by default when a template is streamed, ensuring the flash is swept before the headers are output. This has the side-effect that the flash is swept when a template is streamed, even if not referenced in the controller or view. Usually, this is not a problem, as flash messages are often rendered in the layout, ensuring a sweep anyway. If this is undesirable, you may disable this behavior by adding this to a file in config/initializers: TemplateStreaming.configure(:autosweep_flash => false) However, you'll have to ensure the flash is referenced during the necessary actions yourself, or it won't be swept.