summaryrefslogtreecommitdiffstats
path: root/Bugzilla/WebService/Server
diff options
context:
space:
mode:
authorDave Lawrence <dlawrence@mozilla.com>2014-02-05 23:55:07 +0100
committerDave Lawrence <dlawrence@mozilla.com>2014-02-05 23:55:07 +0100
commite944ebab1ef01993751c75d5fd25ec6b590cb858 (patch)
tree23062bbb8fdd9c52a982883eec2d59091a1eb6d2 /Bugzilla/WebService/Server
parentdcb75dc1dfaf486c7607beedd81fac65737c8e7f (diff)
downloadbugzilla-e944ebab1ef01993751c75d5fd25ec6b590cb858.tar.gz
bugzilla-e944ebab1ef01993751c75d5fd25ec6b590cb858.tar.xz
Bug 968482 - backport bug 966277 to bmo/4.2 to set default content type if no accept header provided
Diffstat (limited to 'Bugzilla/WebService/Server')
-rw-r--r--Bugzilla/WebService/Server/REST.pm8
1 files changed, 7 insertions, 1 deletions
diff --git a/Bugzilla/WebService/Server/REST.pm b/Bugzilla/WebService/Server/REST.pm
index 2216911c9..61af97a50 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;