diff options
author | David Lawrence <dkl@mozilla.com> | 2014-10-29 19:45:39 +0100 |
---|---|---|
committer | David Lawrence <dkl@mozilla.com> | 2014-10-30 19:48:35 +0100 |
commit | b532ec33b7bbc3a19afa1344c080c43836d1a22f (patch) | |
tree | 0fb31cf3bb2b142d85706795f8059035f61bbca5 /Bugzilla/WebService/Server | |
parent | ae69ad5447de722c68c7a85bc0d35645b5f1cccd (diff) | |
download | bugzilla-b532ec33b7bbc3a19afa1344c080c43836d1a22f.tar.gz bugzilla-b532ec33b7bbc3a19afa1344c080c43836d1a22f.tar.xz |
Bug 1088253: GET REST calls should allow arbitrary URL parameters to be passed in addition the values in the path
r=glob,a=glob
Diffstat (limited to 'Bugzilla/WebService/Server')
-rw-r--r-- | Bugzilla/WebService/Server/REST.pm | 33 | ||||
-rw-r--r-- | Bugzilla/WebService/Server/REST/Resources/Bug.pm | 5 |
2 files changed, 26 insertions, 12 deletions
diff --git a/Bugzilla/WebService/Server/REST.pm b/Bugzilla/WebService/Server/REST.pm index 69f97ef08..cd4536b97 100644 --- a/Bugzilla/WebService/Server/REST.pm +++ b/Bugzilla/WebService/Server/REST.pm @@ -347,11 +347,28 @@ sub _retrieve_json_params { my $params = {}; %{$params} = %{ Bugzilla->input_params }; - # First add any params we were able to pull out of the path - # based on the resource regexp - %{$params} = (%{$params}, %{$self->bz_rest_params}) if $self->bz_rest_params; + # First add any parameters we were able to pull out of the path + # based on the resource regexp and combine with the normal URL + # 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. if ($self->request->method ne 'GET') { my $extra_params = {}; @@ -362,14 +379,6 @@ sub _retrieve_json_params { 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}; } diff --git a/Bugzilla/WebService/Server/REST/Resources/Bug.pm b/Bugzilla/WebService/Server/REST/Resources/Bug.pm index d0f470fcd..8c73e32e6 100644 --- a/Bugzilla/WebService/Server/REST/Resources/Bug.pm +++ b/Bugzilla/WebService/Server/REST/Resources/Bug.pm @@ -28,6 +28,11 @@ sub _rest_resources { status_code => STATUS_CREATED } }, + qr{^/bug/$}, { + GET => { + method => 'get' + } + }, qr{^/bug/([^/]+)$}, { GET => { method => 'get', |