Commit a3e9de58 authored by David Lawrence's avatar David Lawrence

Bug 1088253: GET REST calls should allow arbitrary URL parameters to be passed…

Bug 1088253: GET REST calls should allow arbitrary URL parameters to be passed in addition the values in the path r=glob,a=glob
parent 1dec0431
...@@ -337,11 +337,28 @@ sub _retrieve_json_params { ...@@ -337,11 +337,28 @@ sub _retrieve_json_params {
my $params = {}; my $params = {};
%{$params} = %{ Bugzilla->input_params }; %{$params} = %{ Bugzilla->input_params };
# First add any params we were able to pull out of the path # First add any parameters we were able to pull out of the path
# based on the resource regexp # based on the resource regexp and combine with the normal URL
%{$params} = (%{$params}, %{$self->bz_rest_params}) if $self->bz_rest_params; # parameters.
if (my $rest_params = $self->bz_rest_params) {
foreach my $param (keys %$rest_params) {
if (!exists $params->{$param}) {
$params->{$param} = $rest_params->{$param};
next;
}
my @values = ref $rest_params->{$param}
? @{ $rest_params->{$param} }
: ($rest_params->{$param});
if (ref $params->{$param}) {
push(@{ $params->{$param} }, @values);
}
else {
$params->{$param} = [ $params->{$param}, @values ];
}
}
}
# Merge any additional query key/values with $obj->{params} if not a GET request # Merge any additional query key/values from the request body if non-GET.
# We do this manually cause CGI.pm doesn't understand JSON strings. # We do this manually cause CGI.pm doesn't understand JSON strings.
if ($self->request->method ne 'GET') { if ($self->request->method ne 'GET') {
my $extra_params = {}; my $extra_params = {};
...@@ -352,14 +369,6 @@ sub _retrieve_json_params { ...@@ -352,14 +369,6 @@ sub _retrieve_json_params {
ThrowUserError('json_rpc_invalid_params', { err_msg => $@ }); ThrowUserError('json_rpc_invalid_params', { err_msg => $@ });
} }
} }
# Allow parameters in the query string if request was not GET.
# Note: query string parameters will override any matching params
# also specified in the request body.
foreach my $param ($self->cgi->url_param()) {
$extra_params->{$param} = $self->cgi->url_param($param);
}
%{$params} = (%{$params}, %{$extra_params}) if %{$extra_params}; %{$params} = (%{$params}, %{$extra_params}) if %{$extra_params};
} }
......
...@@ -29,6 +29,11 @@ sub _rest_resources { ...@@ -29,6 +29,11 @@ sub _rest_resources {
status_code => STATUS_CREATED status_code => STATUS_CREATED
} }
}, },
qr{^/bug/$}, {
GET => {
method => 'get'
}
},
qr{^/bug/([^/]+)$}, { qr{^/bug/([^/]+)$}, {
GET => { GET => {
method => 'get', method => 'get',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment