push @accepted_types, @$stashed;
}
# then content types requested by caller
- push @accepted_types, @{ $c->request->accepted_content_types };
+ push @accepted_types,
+ $search_path =~ m{Deserialize}
+ ? @{ $c->request->accepted_content_types }
+ : @{ $c->request->accepted_response_content_types }
+ ;
+
# then the default
push @accepted_types, $config->{'default'} if $config->{'default'};
# pick the best match that we have a serializer mapping for
init_arg => undef,
);
-sub _build_accepted_content_types {
- my $self = shift;
+has accepted_response_content_types => (
+ is => 'ro',
+ isa => 'ArrayRef',
+ lazy => 1,
+ builder => '_build_accepted_response_content_types',
+ init_arg => undef,
+);
- my %types;
+has preferred_response_content_type => (
+ is => 'ro',
+ isa => 'Str',
+ lazy => 1,
+ builder => '_build_preferred_response_content_type',
+ init_arg => undef,
+);
+
+sub _accepted_types_sort {
+ my ($self, %types) = @_;
+ [ sort { $types{$b} <=> $types{$a} } keys %types ];
+}
+sub _build_accepted_content_types {
+ my $self = shift;
+ my %types = $self->_accepted_response_content_types_inner;
# First, we use the content type in the HTTP Request. It wins all.
$types{ $self->content_type } = 3
if $self->content_type;
+ $self->_accepted_types_sort(%types);
+}
+
+sub _build_accepted_response_content_types {
+ my $self = shift;
+ my %types = $self->_accepted_response_content_types_inner;
+ $self->_accepted_types_sort(%types);
+}
+
+sub _accepted_response_content_types_inner {
+ my $self = shift;
+
+ my %types;
if ($self->method eq "GET" && $self->param('content-type')) {
$types{ $self->param('content-type') } = 2;
}
}
- [ sort { $types{$b} <=> $types{$a} } keys %types ];
+ %types;
}
sub _build_preferred_content_type { $_[0]->accepted_content_types->[0] }
+sub _build_preferred_response_content_type { $_[0]->accepted_response_content_types->[0] }
+
sub accepts {
my $self = shift;
my $type = shift;