diff --git a/lib/NGCP/Panel/Role/API.pm b/lib/NGCP/Panel/Role/API.pm index 5d1a91bd6c..8e24a1c80b 100644 --- a/lib/NGCP/Panel/Role/API.pm +++ b/lib/NGCP/Panel/Role/API.pm @@ -1494,10 +1494,10 @@ sub check_return_type { #while not strict requirement to the config my $result = 1; if ($allowed_types) { - if ( (!ref $allowed_types && $requested_type ne 'binary' && $requested_type ne $allowed_types) + if ( (!ref $allowed_types && $requested_type ne 'binary' && index($requested_type, $allowed_types) < 0) || ( ref $allowed_types eq 'ARRAY' - && !grep {$_ eq $requested_type} @$allowed_types + && !grep {index($requested_type, $_) > -1} @$allowed_types ) ) { $result = 0; diff --git a/lib/NGCP/Panel/Role/EntitiesItem.pm b/lib/NGCP/Panel/Role/EntitiesItem.pm index 90c105db06..4eb70bb201 100644 --- a/lib/NGCP/Panel/Role/EntitiesItem.pm +++ b/lib/NGCP/Panel/Role/EntitiesItem.pm @@ -186,29 +186,40 @@ sub get { my $item = $self->item_by_id_valid($c, $id); last unless $item; - my $header_accept = $c->request->header('Accept'); - my $mime_type_from_query_params = $self->mime_type_from_query_params($c); my $action_config = $self->get_config('action'); my $config_allowed_types = $action_config->{GET}->{ReturnContentType}; my $apllication_json = 'application/json'; - #TODO: to method + + my $header_accept = $c->request->header('Accept'); + + my $mime_type_from_accept_header; if( ( defined $header_accept - && ($header_accept !~ m!\bapplication/json\b!) - && ($header_accept !~ m#(?mime_type_from_query_params($c); + + #TODO: to method + if( defined $mime_type_from_accept_header || defined $mime_type_from_query_params #no header Accept passed, check configured return type || ( $config_allowed_types && ( - ( ( !ref $config_allowed_types) + ( ( !ref $config_allowed_types) && $config_allowed_types ne $apllication_json) - || ( ref $config_allowed_types eq 'ARRAY' + || ( ref $config_allowed_types eq 'ARRAY' && !grep { $_ eq $apllication_json } @{ $config_allowed_types } ) ) ) - + ) { - my $return_type = $header_accept // $mime_type_from_query_params; + my $return_type = $mime_type_from_accept_header // $mime_type_from_query_params; + if ($return_type) { return unless $self->check_return_type($c, $return_type, $config_allowed_types); } elsif (!ref $config_allowed_types) { @@ -275,7 +286,7 @@ sub patch { $self->return_representation($c, 'item' => $item, 'form' => $form, - #hal may be empty if we don't need it for journal. + #hal may be empty if we don't need it for journal. #Then it will be taken from item and form 'hal' => $hal, 'preference' => $preference, @@ -319,7 +330,7 @@ sub put { $self->complete_transaction($c); $self->post_process_commit($c, 'put', $item, $old_resource, $resource, $form, $process_extras); $self->return_representation($c, - #hal may be empty if we don't need it for journal. + #hal may be empty if we don't need it for journal. #Then it will be taken from item and form 'hal' => $hal, 'item' => $item, diff --git a/t/api-rest/api-voicemailgreetings.t b/t/api-rest/api-voicemailgreetings.t index c9773c13a6..32a9d81ef1 100644 --- a/t/api-rest/api-voicemailgreetings.t +++ b/t/api-rest/api-voicemailgreetings.t @@ -138,7 +138,10 @@ foreach my $extension (keys %$audio_types) { diag($soxi_output); - $res = $test_machine->request_get($greeting->{location}.'?format='.$extension); + $res = $test_machine->request_get($greeting->{location}.'?format='.$extension, undef, { + 'Accept' => 'application/json, text/plain, */*', + } + ); $test_machine->http_code_msg(200, "check download voicemail greeting", $res); is($res->filename, $expected_downloaded_name ,"Check downloaded file name: $expected_downloaded_name .");