Mason::Plugin::WithEncoding - Add encoding support to Poet/Mason apps


version 0.2


    In your Poet config file:

        # This is important or the first (and *only* the first) request will
        # not use Plack::Request::WithEncoding
            - Mason::Plugin::WithEncoding

            - WithEncoding

        server.encoding.request: UTF-8
        server.encoding.response: UTF-8
        server.default_content_type: text/html; charset=UTF-8


To decode the request, the plugin loads Plack::Request::WithEncoding and configures it with the encoding specified in server.encoding.request. If no such setting is found, the request is not decoded. This matches the default behaviour of Poet/Mason, but is different from Plack::Request::WithEncoding, (which would normally default to UTF-8).

Output generated by your Mason templates is encoded according to the setting in server.encoding.response. If no such setting is found, the response is not encoded. This is the default behaviour of Poet/Mason.

The content-type default header is set according to server.default_content_type. If no such setting is found, the default header is text/html, as in the default Poet/Mason setup. This tells the client what encoding to use when decoding our content, and also (AFAIK) tells the client what encoding to use when sending us data.

Output sent through send_json is also encoded and the content-type header set accordingly.


This plugin only works inside a Poet environment.

The send_json method added to the Mason request object by Poet always encodes its output as UTF8, which is pretty much always the correct thing to do. But if you are using some other encoding, you'll need to patch this plugin to get send_json to use that instead of UTF8.

Some background


Dave Baird <>


This software is copyright (c) 2016 by David R. Baird.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.