]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1503705 - Stop serving HTML-prettyprinted JSON as REST API results
authorKohei Yoshino <kohei.yoshino@gmail.com>
Thu, 1 Nov 2018 17:36:14 +0000 (13:36 -0400)
committerdklawren <dklawren@users.noreply.github.com>
Thu, 1 Nov 2018 17:36:14 +0000 (13:36 -0400)
Bugzilla/WebService/Constants.pm
Bugzilla/WebService/Server/REST.pm
docs/en/rst/api/core/v1/general.rst
template/en/default/rest.html.tmpl [deleted file]

index 71435c13a523d5dca6a3193d7e8cb8db0323a104..f77ff4372fdd190b5f79aacd7b9cec8ee65c7cda 100644 (file)
@@ -275,7 +275,6 @@ use constant REST_CONTENT_TYPE_WHITELIST => qw(
     application/json
     application/javascript
     text/javascript
-    text/html
 );
 
 sub WS_DISPATCH {
index 13896b248098e5ab17ae2934ad1247e91631d781..001bcbb8ab2cb11a39348d0c23af3c3f7284cfff 100644 (file)
@@ -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<bugzilla.yourdomain.com>, then your REST client would
 access the API via: C<http://bugzilla.yourdomain.com/rest/bug/35> 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<JSONRPC|Bugzilla::WebService::Server::JSONRPC> 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.
index 49d60de7ed21cf686cae89577affc3693165a118..3d078ad7a4bc66b3f848a221def99a002ee45044 100644 (file)
@@ -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 (file)
index 7899449..0000000
+++ /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.
-  #%]
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
-                      "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-  <head>
-    <title>Bugzilla::REST::API</title>
-    <link href="[% 'skins/standard/global.css' FILTER version %]"
-          rel="stylesheet" type="text/css">
-  </head>
-  <body>
-    <pre>[% result FILTER html %]</pre>
-  </body>
-</html>