From b556b054d1ac66ba5f8deebe27c60d14ea968b6d Mon Sep 17 00:00:00 2001 From: mmd-osm Date: Wed, 22 Jan 2020 17:38:28 +0100 Subject: [PATCH] JSON: added clarification for non-supported Accept header formats --- app/controllers/api_controller.rb | 4 ++++ test/controllers/api/map_controller_test.rb | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index c0534a6fa..64514a432 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -45,6 +45,10 @@ class ApiController < ApplicationController request.format = "xml" break end + + # In case the client requests some other format besides XML, JSON and */*, + # we deliberately don't set request.format. The framework will return an + # ActionController::UnknownFormat error to the client later on in this case. end end end diff --git a/test/controllers/api/map_controller_test.rb b/test/controllers/api/map_controller_test.rb index c5392c723..d5cbfb4ef 100644 --- a/test/controllers/api/map_controller_test.rb +++ b/test/controllers/api/map_controller_test.rb @@ -32,7 +32,7 @@ module Api ## # test http accept headers def test_http_accept_header - node = create(:node, :lat => 7, :lon => 7) + node = create(:node) minlon = node.lon - 0.1 minlat = node.lat - 0.1 @@ -99,6 +99,12 @@ module Api http_accept_format("text/json") get :index, :params => { :bbox => bbox } assert_response :internal_server_error, "text/json should fail" + + # image/jpeg is a format which we don't support, ActionController::UnknownFormat error is expected + # HTTP 406 Not acceptable would be the correct response error code. That's outside of our control though. + http_accept_format("image/jpeg") + get :index, :params => { :bbox => bbox } + assert_response :internal_server_error, "text/json should fail" end # ------------------------------------- -- 2.39.5