From: Kohei Yoshino Date: Thu, 1 Nov 2018 17:36:14 +0000 (-0400) Subject: Bug 1503705 - Stop serving HTML-prettyprinted JSON as REST API results X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bdc9cc56b7759e958aec8c67f524b7ec41e49e98;p=thirdparty%2Fbugzilla.git Bug 1503705 - Stop serving HTML-prettyprinted JSON as REST API results --- diff --git a/Bugzilla/WebService/Constants.pm b/Bugzilla/WebService/Constants.pm index 71435c13a..f77ff4372 100644 --- a/Bugzilla/WebService/Constants.pm +++ b/Bugzilla/WebService/Constants.pm @@ -275,7 +275,6 @@ use constant REST_CONTENT_TYPE_WHITELIST => qw( 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 13896b248..001bcbb8a 100644 --- a/Bugzilla/WebService/Server/REST.pm +++ b/Bugzilla/WebService/Server/REST.pm @@ -159,21 +159,7 @@ sub response { my $etag = $self->bz_etag; $self->bz_etag($result) if !$etag; - # If accessing through web browser, then display in readable format - if ($self->content_type eq 'text/html') { - $result = $self->json->pretty->canonical->allow_nonref->encode($result); - - my $template = Bugzilla->template; - $content = ""; - $template->process("rest.html.tmpl", { result => $result }, \$content) - || ThrowTemplateError($template->error()); - - $response->content_type('text/html'); - } - else { - $content = $self->json->encode($result); - } - + $content = $self->json->encode($result); utf8::encode($content) if utf8::is_utf8($content); disable_utf8(); @@ -550,15 +536,6 @@ Bugzilla is at C, then your REST client would access the API via: C which looks cleaner. -=head1 BROWSING - -If the Accept: header of a request is set to text/html (as it is by an -ordinary web browser) then the API will return the JSON data as a HTML -page which the browser can display. In other words, you can play with the -API using just your browser and see results in a human-readable form. -This is a good way to try out the various GET calls, even if you can't use -it for POST or PUT. - =head1 DATA FORMAT The REST API only supports JSON input, and either JSON and JSONP output. @@ -567,12 +544,8 @@ the REST API is a sub class of the JSONRPC API, you can refer to L for more information on data types that are valid for REST. -On every request, you must set both the "Accept" and "Content-Type" HTTP -headers to the MIME type of the data format you are using to communicate with -the API. Content-Type tells the API how to interpret your request, and Accept -tells it how you want your data back. "Content-Type" must be "application/json". -"Accept" can be either that, or "application/javascript" for JSONP - add a "callback" -parameter to name your callback. +If you need JSONP output, you must set the "Accept: application/javascript" HTTP +header and add a "callback" parameter to name your callback. Parameters may also be passed in as part of the query string for non-GET requests and will override any matching parameters in the request body. diff --git a/docs/en/rst/api/core/v1/general.rst b/docs/en/rst/api/core/v1/general.rst index 49d60de7e..3d078ad7a 100644 --- a/docs/en/rst/api/core/v1/general.rst +++ b/docs/en/rst/api/core/v1/general.rst @@ -7,27 +7,13 @@ with Bugzilla. It provides a REST interface to various Bugzilla functions. Basic Information ----------------- -**Browsing** - -If the ``Accept`` header of a request is set to ``text/html`` (as it is by an -ordinary web browser) then the API will return the JSON data as a HTML -page which the browser can display. In other words, you can play with the -API using just your browser to see results in a human-readable form. -This is a good way to try out the various GET calls, even if you can't use -it for POST or PUT. - **Data Format** The REST API only supports JSON input, and either JSON or JSONP output. So objects sent and received must be in JSON format. -On every request, you must set both the ``Accept`` and ``Content-Type`` HTTP -headers to the MIME type of the data format you are using to communicate with -the API. ``Content-Type`` tells the API how to interpret your request, and -``Accept`` tells it how you want your data back. ``Content-Type`` must be -``application/json``. ``Accept`` can be either that, or -``application/javascript`` for JSONP. In the latter`case, add a ``callback`` -parameter to name your callback. +If you need JSONP output, you must set the ``Accept: application/javascript`` +HTTP header and add a ``callback`` parameter to name your callback. Parameters may also be passed in as part of the query string for non-GET requests and will override any matching parameters in the request body. @@ -38,7 +24,6 @@ Example request which returns the current version of Bugzilla: GET /rest/version HTTP/1.1 Host: bugzilla.example.com - Accept: application/json Example response: diff --git a/template/en/default/rest.html.tmpl b/template/en/default/rest.html.tmpl deleted file mode 100644 index 7899449a3..000000000 --- a/template/en/default/rest.html.tmpl +++ /dev/null @@ -1,19 +0,0 @@ -[%# This Source Code Form is subject to the terms of the Mozilla Public - # License, v. 2.0. If a copy of the MPL was not distributed with this - # file, You can obtain one at http://mozilla.org/MPL/2.0/. - # - # This Source Code Form is "Incompatible With Secondary Licenses", as - # defined by the Mozilla Public License, v. 2.0. - #%] - - - - Bugzilla::REST::API - - - -
[% result FILTER html %]
- -