Skip to content

Commit

Permalink
Merge pull request #221 from mmd-osm/patch/mimetype
Browse files Browse the repository at this point in the history
Use MIME type application/xml for better Rails compatibility
  • Loading branch information
mmd-osm authored Mar 1, 2020
2 parents 908afd8 + ac49384 commit 9c7f91e
Show file tree
Hide file tree
Showing 99 changed files with 117 additions and 102 deletions.
2 changes: 1 addition & 1 deletion include/cgimap/mime_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace mime {
enum type {
unspecified_type, // a "null" type, used to indicate no choice.
text_plain,
text_xml,
application_xml,
#ifdef HAVE_YAJL
application_json,
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/api06/changeset_update_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ changeset_update_responder::~changeset_update_responder() = default;
changeset_update_sel_responder::~changeset_update_sel_responder() = default;

changeset_update_handler::changeset_update_handler(request &req, osm_changeset_id_t id_)
: payload_enabled_handler(mime::text_xml,
: payload_enabled_handler(mime::application_xml,
http::method::PUT | http::method::OPTIONS),
id(id_) {}

Expand Down
5 changes: 3 additions & 2 deletions src/choose_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ struct http_accept_grammar
};
/*
= lit("* / *") [_val = mime::any_type]
| lit("text/xml") [_val = mime::text_xml]
| lit("text/xml") [_val = mime::application_xml]
| lit("application/xml") [_val = mime::application_xml]
#ifdef HAVE_YAJL
| lit("application/json")[_val = mime::application_json]
#endif
Expand Down Expand Up @@ -262,7 +263,7 @@ shared_ptr<output_formatter> create_formatter(request &req,
shared_ptr<output_buffer> out) {
shared_ptr<output_formatter> o_formatter;

if (best_type == mime::text_xml) {
if (best_type == mime::application_xml) {
auto *xwriter = new xml_writer(out, true);
o_formatter = shared_ptr<output_formatter>(new xml_formatter(xwriter));

Expand Down
10 changes: 6 additions & 4 deletions src/mime_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ string to_string(type t) {
return "*/*";
} else if (text_plain == t) {
return "text/plain";
} else if (text_xml == t) {
return "text/xml";
} else if (application_xml == t) {
return "application/xml";
#ifdef HAVE_YAJL
} else if (application_json == t) {
return "application/json";
Expand All @@ -33,8 +33,10 @@ type parse_from(const std::string &name) {
t = any_type;
} else if (name == "text/plain") {
t = text_plain;
} else if (name == "text/xml") {
t = text_xml;
} else if (name == "text/xml") { // alias according to RFC 7303, section 9.2
t = application_xml;
} else if (name == "application/xml") {
t = application_xml;
#ifdef HAVE_YAJL
} else if (name == "application/json") {
t = application_json;
Expand Down
2 changes: 1 addition & 1 deletion src/osm_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ osm_responder::~osm_responder() = default;

list<mime::type> osm_responder::types_available() const {
list<mime::type> types;
types.push_back(mime::text_xml);
types.push_back(mime::application_xml);
#ifdef HAVE_YAJL
types.push_back(mime::application_json);
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/osmchange_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ osmchange_responder::~osmchange_responder() = default;

list<mime::type> osmchange_responder::types_available() const {
list<mime::type> types;
types.push_back(mime::text_xml);
types.push_back(mime::application_xml);
return types;
}

Expand Down
2 changes: 1 addition & 1 deletion src/process_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void respond_error(const http::exception &e, request &r) {

if (error_format && al::iequals(error_format, "xml")) {
r.status(200)
.add_header("Content-Type", "text/xml; charset=utf-8");
.add_header("Content-Type", "application/xml; charset=utf-8");

ostringstream ostr;
ostr << "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n"
Expand Down
4 changes: 2 additions & 2 deletions src/routes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ routes::~routes() = default;
namespace {
/**
* figures out the mime type from the path specification, e.g: a resource ending
* in .xml should be text/xml, .json should be application/json, etc...
* in .xml should be application/xml, .json should be application/json, etc...
*/
pair<string, mime::type> resource_mime_type(const string &path) {

Expand All @@ -293,7 +293,7 @@ namespace {
std::size_t xml_found = path.rfind(".xml");

if (xml_found != string::npos && xml_found == path.length() - 4) {
return make_pair(path.substr(0, xml_found), mime::text_xml);
return make_pair(path.substr(0, xml_found), mime::application_xml);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/xml_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ xml_formatter::xml_formatter(xml_writer *w) : writer(w) {}

xml_formatter::~xml_formatter() = default;

mime::type xml_formatter::mime_type() const { return mime::text_xml; }
mime::type xml_formatter::mime_type() const { return mime::application_xml; }

void xml_formatter::start_document(
const std::string &generator, const std::string &root_name) {
Expand Down
2 changes: 1 addition & 1 deletion test/anon.testcore/single_node.case
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Request-Method: GET
Request-URI: /api/0.6/map?bbox=-0.0005,-0.0005,0.0005,0.0005
---
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
Content-Disposition: attachment; filename="map.osm"
Status: 200 OK
---
Expand Down
2 changes: 1 addition & 1 deletion test/changesets.testcore/download.case
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Request-URI: /api/0.6/changeset/1/download
Date: 2017-02-20T15:22:00Z
---
Status: 200 OK
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
!Content-Disposition:
---
<osmChange version="0.6" generator="***" copyright="***" attribution="***" license="***">
Expand Down
2 changes: 1 addition & 1 deletion test/changesets.testcore/download_changeset_2.case
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Request-URI: /api/0.6/changeset/3/download
Date: 2017-03-13T09:54:00Z
---
Status: 200 OK
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
!Content-Disposition:
---
<osmChange version="0.6" generator="***" copyright="***" attribution="***" license="***">
Expand Down
2 changes: 1 addition & 1 deletion test/changesets.testcore/download_changeset_4.case
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Request-URI: /api/0.6/changeset/4/download
Date: 2017-03-13T09:54:00Z
---
Status: 200 OK
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
!Content-Disposition:
---
<osmChange version="0.6" generator="***" copyright="***" attribution="***" license="***">
Expand Down
2 changes: 1 addition & 1 deletion test/changesets.testcore/download_changeset_rel10.case
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Request-URI: /api/0.6/changeset/10/download
Date: 2017-03-13T16:27:00Z
---
Status: 200 OK
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
!Content-Disposition:
---
<osmChange version="0.6" generator="***" copyright="***" attribution="***" license="***">
Expand Down
2 changes: 1 addition & 1 deletion test/changesets.testcore/download_changeset_sort11.case
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Request-URI: /api/0.6/changeset/11/download
Date: 2017-03-13T16:32:00Z
---
Status: 200 OK
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
!Content-Disposition:
---
<osmChange version="0.6" generator="***" copyright="***" attribution="***" license="***">
Expand Down
2 changes: 1 addition & 1 deletion test/changesets.testcore/download_changeset_way6.case
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Request-URI: /api/0.6/changeset/6/download
Date: 2017-03-13T15:43:00Z
---
Status: 200 OK
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
!Content-Disposition:
---
<osmChange version="0.6" generator="***" copyright="***" attribution="***" license="***">
Expand Down
2 changes: 1 addition & 1 deletion test/changesets.testcore/download_changeset_way7.case
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Request-URI: /api/0.6/changeset/7/download
Date: 2017-03-13T15:44:00Z
---
Status: 200 OK
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
!Content-Disposition:
---
<osmChange version="0.6" generator="***" copyright="***" attribution="***" license="***">
Expand Down
2 changes: 1 addition & 1 deletion test/changesets.testcore/download_changeset_way9.case
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Request-URI: /api/0.6/changeset/9/download
Date: 2017-03-13T16:12:00Z
---
Status: 200 OK
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
!Content-Disposition:
---
<osmChange version="0.6" generator="***" copyright="***" attribution="***" license="***">
Expand Down
2 changes: 1 addition & 1 deletion test/changesets.testcore/empty.case
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Request-URI: /api/0.6/changeset/2/download
Date: 2017-03-13T16:58:00Z
---
Status: 200 OK
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
!Content-Disposition:
---
<osmChange version="0.6" generator="***" copyright="***" attribution="***" license="***"/>
2 changes: 1 addition & 1 deletion test/changesets.testcore/read.case
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ HTTP-X-Error-Format: xml
Date: 2015-08-09T11:33:13Z
---
Status: 200 OK
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
!Content-Disposition:
---
<osm version="0.6" generator="***" copyright="***" attribution="***" license="***">
Expand Down
2 changes: 1 addition & 1 deletion test/changesets.testcore/read_discussion.case
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ HTTP-X-Error-Format: xml
Date: 2015-08-09T11:33:13Z
---
Status: 200 OK
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
!Content-Disposition:
---
<osm version="0.6" generator="***" copyright="***" attribution="***" license="***">
Expand Down
2 changes: 1 addition & 1 deletion test/changesets.testcore/read_nonpublic.case
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ HTTP-X-Error-Format: xml
Date: 2015-09-05T20:17:10Z
---
Status: 200 OK
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
!Content-Disposition:
---
<osm version="0.6" generator="***" copyright="***" attribution="***" license="***">
Expand Down
2 changes: 1 addition & 1 deletion test/changesets.testcore/read_open.case
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ HTTP-X-Error-Format: xml
Date: 2015-08-09T10:33:13Z
---
Status: 200 OK
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
!Content-Disposition:
---
<osm version="0.6" generator="***" copyright="***" attribution="***" license="***">
Expand Down
2 changes: 1 addition & 1 deletion test/empty.testcore/accept_any.case
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Request-Method: GET
Request-URI: /api/0.6/map?bbox=0,0,0,0
HTTP-Accept: *
---
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
Content-Disposition: attachment; filename="map.osm"
Status: 200 OK
---
Expand Down
2 changes: 1 addition & 1 deletion test/empty.testcore/accept_any_any.case
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Request-Method: GET
Request-URI: /api/0.6/map?bbox=0,0,0,0
HTTP-Accept: */*
---
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
Content-Disposition: attachment; filename="map.osm"
Status: 200 OK
---
Expand Down
11 changes: 11 additions & 0 deletions test/empty.testcore/accept_application_xml.case
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Request-Method: GET
Request-URI: /api/0.6/map?bbox=0,0,0,0
HTTP-Accept: application/xml
---
Content-Type: application/xml; charset=utf-8
Content-Disposition: attachment; filename="map.osm"
Status: 200 OK
---
<osm version="0.6" generator="***" copyright="***" attribution="***" license="***">
<bounds maxlat="0.0000000" maxlon="0.0000000" minlat="0.0000000" minlon="0.0000000"/>
</osm>
2 changes: 1 addition & 1 deletion test/empty.testcore/accept_josm_nonsense.case
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Request-Method: GET
Request-URI: /api/0.6/map?bbox=0,0,0,0
HTTP-Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
---
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
Content-Disposition: attachment; filename="map.osm"
Status: 200 OK
---
Expand Down
2 changes: 1 addition & 1 deletion test/empty.testcore/accept_nil.case
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Request-Method: GET
Request-URI: /api/0.6/map?bbox=0,0,0,0
---
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
Content-Disposition: attachment; filename="map.osm"
Status: 200 OK
---
Expand Down
2 changes: 1 addition & 1 deletion test/empty.testcore/accept_text_any.case
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Request-Method: GET
Request-URI: /api/0.6/map?bbox=0,0,0,0
HTTP-Accept: text/*
---
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
Content-Disposition: attachment; filename="map.osm"
Status: 200 OK
---
Expand Down
2 changes: 1 addition & 1 deletion test/empty.testcore/accept_text_xml.case
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Request-Method: GET
Request-URI: /api/0.6/map?bbox=0,0,0,0
HTTP-Accept: text/xml
---
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
Content-Disposition: attachment; filename="map.osm"
Status: 200 OK
---
Expand Down
2 changes: 1 addition & 1 deletion test/empty.testcore/http_origin.case
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Request-URI: /api/0.6/map?bbox=0,0,0,0
HTTP-Accept: *
HTTP-Origin: http://localhost
---
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
Content-Disposition: attachment; filename="map.osm"
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, HEAD, OPTIONS
Expand Down
2 changes: 1 addition & 1 deletion test/map.testcore/empty_response.case
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Request-Method: GET
Request-URI: /api/0.6/map?bbox=-0.01,-0.01,-0.0005,-0.0005
---
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
Content-Disposition: attachment; filename="map.osm"
Status: 200 OK
---
Expand Down
2 changes: 1 addition & 1 deletion test/map.testcore/multiple_node.case
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Request-Method: GET
Request-URI: /api/0.6/map?bbox=-0.0005,-0.0005,0.0015,0.0015
---
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
Content-Disposition: attachment; filename="map.osm"
Status: 200 OK
---
Expand Down
2 changes: 1 addition & 1 deletion test/map.testcore/single_node.case
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Request-Method: GET
Request-URI: /api/0.6/map?bbox=-0.0005,-0.0005,0.0005,0.0005
---
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
Content-Disposition: attachment; filename="map.osm"
Status: 200 OK
---
Expand Down
2 changes: 1 addition & 1 deletion test/map.testcore/used_node.case
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Request-Method: GET
Request-URI: /api/0.6/map?bbox=0.2995,-0.0005,0.3005,0.3005
---
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
Content-Disposition: attachment; filename="map.osm"
Status: 200 OK
---
Expand Down
2 changes: 1 addition & 1 deletion test/map.testcore/used_way.case
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Request-Method: GET
Request-URI: /api/0.6/map?bbox=0.1995,-0.0005,0.2005,0.3005
---
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
Content-Disposition: attachment; filename="map.osm"
Status: 200 OK
---
Expand Down
2 changes: 1 addition & 1 deletion test/message.testcore/map_400_xml.case
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Request-URI: /api/0.6/map
HTTP-X-Error-Format: xml
---
Status: 200 OK
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
---
<?xml version="1.0" encoding="utf-8" ?>
<osmError>
Expand Down
2 changes: 1 addition & 1 deletion test/node.testcore/large_id_1.case
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Request-Method: GET
Request-URI: /api/0.6/node/8589934592
---
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
!Content-Disposition:
Status: 200 OK
---
Expand Down
2 changes: 1 addition & 1 deletion test/node.testcore/large_id_2.case
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Request-Method: GET
Request-URI: /api/0.6/node/9223372036854775807
---
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
!Content-Disposition:
Status: 200 OK
---
Expand Down
2 changes: 1 addition & 1 deletion test/node.testcore/node_1.case
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Request-Method: GET
Request-URI: /api/0.6/node/1
---
Content-Type: text/xml; charset=utf-8
Content-Type: application/xml; charset=utf-8
!Content-Disposition:
Status: 200 OK
---
Expand Down
Loading

0 comments on commit 9c7f91e

Please sign in to comment.