From eb865b8c425a0d23a30c2510e34797c175f168e0 Mon Sep 17 00:00:00 2001 From: Slaven Rezic Date: Fri, 14 Jun 2019 09:43:22 +0200 Subject: [PATCH] cease warnings (in case of missing Accept header) This should fix RT #129818. Change done along with new test cases. --- lib/REST/Utils.pm | 1 + t/content-negotiation.t | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/REST/Utils.pm b/lib/REST/Utils.pm index 19a7669..e3ef7fb 100644 --- a/lib/REST/Utils.pm +++ b/lib/REST/Utils.pm @@ -66,6 +66,7 @@ Example: sub best_match { my ( $supported, $header ) = @_; + return undef if !defined $header; my @parsed_header = map { [ parse_media_range($_) ] } split /,/msx, $header; my @weighted_matches = sort { $a->[0][0] <=> $b->[0][0] || $a->[0][1] <=> $b->[0][1] } diff --git a/t/content-negotiation.t b/t/content-negotiation.t index 1ae4d31..72b42cf 100644 --- a/t/content-negotiation.t +++ b/t/content-negotiation.t @@ -3,11 +3,14 @@ # Test content negotiation use strict; use warnings; -use Test::More tests => 10; +use Test::More tests => 12; use CGI; use Test::WWW::Mechanize::CGI; use REST::Utils qw( media_type ); +my @warnings; +$SIG{__WARN__} = sub { push @warnings, @_ }; + my $mech = Test::WWW::Mechanize::CGI->new; $mech->cgi( sub { my $q = CGI->new; @@ -25,6 +28,9 @@ $mech->cgi( sub { } }); +$mech->get('http://localhost/'); +is($mech->response->header('content_type'), 'text/plain; charset=ISO-8859-1', 'GET preferred content type without Accept header'); + $mech->add_header(Accept => 'application/xhtml+xml;q=1.0, text/html;q=0.9, text/plain;q=0.8, */*;q=0.1'); $mech->get('http://localhost/'); @@ -62,3 +68,5 @@ is($mech->content_type, 'text/vrml', 'no content negotiation with DELETE'); $mech->post('http://localhost/', Content_Type => undef); is($mech->status, '415', 'no content type'); + +is_deeply \@warnings, [], 'No warnings'; -- 2.1.4