Skip to content

Instantly share code, notes, and snippets.

@KES777
KES777 / content_negotiation.t
Created March 23, 2018 08:00
Content negotiation tests
use Mojolicious::Lite;
use Test::Mojo;
use Test::More;
app->defaults( format => 'zzz', template => 'test' );
get '/app';
get '/route' => { format => 'xxx' };
@KES777
KES777 / gist:c7b9a2487b98dee19a329102844a1159
Created March 23, 2018 15:29
content negotiation draft
Mojolicious content negotiation gotchas
Let's begin with parts which participate in content negotiation.
First of all there are client requirements and server capabilities.
This is obvious that we should prefer client requirements over server capabilies by default. And, if server (controller's action) wants, it may force {format}.
So picture is next by precedence:
1. Controller's action format preferences
Initial problem:
use Mojolicious::Lite;
use Test::Mojo;
use Test::More;
get '/test' => { format => 'xxx' };
my $t = Test::Mojo->new;
@KES777
KES777 / gist:0eec79515ef1c2c5c200ca902c9915ec
Last active March 27, 2018 20:59
proper descrition of current behaviour
DESCRIPTION OF THE PROBLEM
use Mojolicious::Lite;
use Test::Mojo;
use Test::More;
get '/test' => { format => 'xxx' };
my $t = Test::Mojo->new;
@KES777
KES777 / t-mojolicoius-exception_lite_app.t
Created March 30, 2018 06:54
Mojolicous expects wrong results
use Mojolicious::Lite;
use Test::Mojo;
use Test::More;
hook before_render => sub {
my ($c, $args) = @_;
@$args{qw(text format)} = ($args->{exception}, 'txt')
if ($args->{template} // '') eq 'exception' && $c->accepts('txt');
};
use Mojo::Base -strict;
use Test::Mojo;
use Test::More;
use Mojolicious::Lite;
app->defaults( handler => 'my_handler' );
get '/example' => sub{ die };
hook before_render => sub {