+ ##
+ # test http accept headers
+ def test_http_accept_header
+ node = create(:node)
+
+ minlon = node.lon - 0.1
+ minlat = node.lat - 0.1
+ maxlon = node.lon + 0.1
+ maxlat = node.lat + 0.1
+ bbox = "#{minlon},#{minlat},#{maxlon},#{maxlat}"
+
+ # Accept: XML format -> use XML
+ accept_header = accept_format_header("text/xml")
+ get map_path(:bbox => bbox), :headers => accept_header
+ assert_response :success, "Expected success with the map call"
+ assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
+
+ # Accept: Any format -> use XML
+ accept_header = accept_format_header("*/*")
+ get map_path(:bbox => bbox), :headers => accept_header
+ assert_response :success, "Expected success with the map call"
+ assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
+
+ # Accept: Any format, .json URL suffix -> use json
+ accept_header = accept_format_header("*/*")
+ get map_path(:bbox => bbox, :format => "json"), :headers => accept_header
+ assert_response :success, "Expected success with the map call"
+ assert_equal "application/json; charset=utf-8", @response.header["Content-Type"]
+
+ # Accept: Firefox header -> use XML
+ accept_header = accept_format_header("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
+ get map_path(:bbox => bbox), :headers => accept_header
+ assert_response :success, "Expected success with the map call"
+ assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
+
+ # Accept: JOSM header text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 -> use XML
+ # Note: JOSM's header does not comply with RFC 7231, section 5.3.1
+ accept_header = accept_format_header("text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2")
+ get map_path(:bbox => bbox), :headers => accept_header
+ assert_response :success, "Expected success with the map call"
+ assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
+
+ # Accept: text/plain, */* -> use XML
+ accept_header = accept_format_header("text/plain, */*")
+ get map_path(:bbox => bbox), :headers => accept_header
+ assert_response :success, "Expected success with the map call"
+ assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
+
+ # Accept: text/* -> use XML
+ accept_header = accept_format_header("text/*")
+ get map_path(:bbox => bbox), :headers => accept_header
+ assert_response :success, "Expected success with the map call"
+ assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
+
+ # Accept: json, */* format -> use json
+ accept_header = accept_format_header("application/json, */*")
+ get map_path(:bbox => bbox), :headers => accept_header
+ assert_response :success, "Expected success with the map call"
+ assert_equal "application/json; charset=utf-8", @response.header["Content-Type"]
+
+ # Accept: json format -> use json
+ accept_header = accept_format_header("application/json")
+ get map_path(:bbox => bbox), :headers => accept_header
+ assert_response :success, "Expected success with the map call"
+ assert_equal "application/json; charset=utf-8", @response.header["Content-Type"]
+
+ # text/json is in invalid format, return HTTP 406 Not acceptable
+ accept_header = accept_format_header("text/json")
+ get map_path(:bbox => bbox), :headers => accept_header
+ assert_response :not_acceptable, "text/json should fail"
+
+ # image/jpeg is a format which we don't support, return HTTP 406 Not acceptable
+ accept_header = accept_format_header("image/jpeg")
+ get map_path(:bbox => bbox), :headers => accept_header
+ assert_response :not_acceptable, "text/json should fail"
+ end
+