summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorDave Lawrence <dlawrence@mozilla.com>2014-02-05 23:37:07 +0100
committerDave Lawrence <dlawrence@mozilla.com>2014-02-05 23:37:07 +0100
commiteae63571ef63f7ddc9f36219229075a20c012d55 (patch)
treedb2c9ffae90525ee006a779f6f1f4520c6b10246 /Bugzilla
parentc5464b5bb7dfece2bad2b8af9eba4d9b6d07d778 (diff)
downloadbugzilla-eae63571ef63f7ddc9f36219229075a20c012d55.tar.gz
bugzilla-eae63571ef63f7ddc9f36219229075a20c012d55.tar.xz
Bug 966277 - Bugzilla native REST API should default to application/json if no Accept header was set
r=dkl,a=justdave
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/WebService/Constants.pm5
-rw-r--r--Bugzilla/WebService/Server/REST.pm8
2 files changed, 10 insertions, 3 deletions
diff --git a/Bugzilla/WebService/Constants.pm b/Bugzilla/WebService/Constants.pm
index 5d955b96a..4085c2cbd 100644
--- a/Bugzilla/WebService/Constants.pm
+++ b/Bugzilla/WebService/Constants.pm
@@ -251,11 +251,12 @@ use constant XMLRPC_CONTENT_TYPE_WHITELIST => qw(
application/xml
);
+# The first content type specified is used as the default.
use constant REST_CONTENT_TYPE_WHITELIST => qw(
- text/html
- application/javascript
application/json
+ application/javascript
text/javascript
+ text/html
);
sub WS_DISPATCH {
diff --git a/Bugzilla/WebService/Server/REST.pm b/Bugzilla/WebService/Server/REST.pm
index bafa84f88..f1e59873c 100644
--- a/Bugzilla/WebService/Server/REST.pm
+++ b/Bugzilla/WebService/Server/REST.pm
@@ -39,6 +39,8 @@ sub handle {
# Determine how the data should be represented. We do this early so
# errors will also be returned with the proper content type.
+ # If no accept header was sent or the content types specified were not
+ # matched, we default to the first type in the whitelist.
$self->content_type($self->_best_content_type(REST_CONTENT_TYPE_WHITELIST()));
# Using current path information, decide which class/method to
@@ -440,6 +442,10 @@ sub _best_content_type {
sub _simple_content_negotiation {
my ($self, @types) = @_;
my @accept_types = $self->_get_content_prefs();
+ # Return the types as-is if no accept header sent, since sorting will be a no-op.
+ if (!@accept_types) {
+ return @types;
+ }
my $score = sub { $self->_score_type(shift, @accept_types) };
return sort {$score->($b) <=> $score->($a)} @types;
}
@@ -478,7 +484,7 @@ sub _get_content_prefs {
# Sort the types by score, subscore by order, and pull out just the name
@prefs = map {$_->{name}} sort {$b->{score} <=> $a->{score} ||
$a->{order} <=> $b->{order}} @prefs;
- return @prefs, '*/*'; # Allows allow for */*
+ return @prefs;
}
1;