Skip to content

Commit

Permalink
Merge pull request #219 from mmd-osm/patch/json_indent
Browse files Browse the repository at this point in the history
JSON fixes
  • Loading branch information
mmd-osm authored Jan 5, 2020
2 parents 8b817b6 + 9c25212 commit ee2d807
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion include/cgimap/mime_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ enum type {
text_plain,
text_xml,
#ifdef HAVE_YAJL
text_json,
application_json,
#endif
any_type // the "*/*" type used to mean that anything is acceptable.
};
Expand Down
6 changes: 3 additions & 3 deletions src/choose_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ struct http_accept_grammar
= lit("* / *") [_val = mime::any_type]
| lit("text/xml") [_val = mime::text_xml]
#ifdef HAVE_YAJL
| lit("text/json")[_val = mime::text_json]
| lit("application/json")[_val = mime::application_json]
#endif
;
*/
Expand Down Expand Up @@ -267,8 +267,8 @@ shared_ptr<output_formatter> create_formatter(request &req,
o_formatter = shared_ptr<output_formatter>(new xml_formatter(xwriter));

#ifdef HAVE_YAJL
} else if (best_type == mime::text_json) {
auto *jwriter = new json_writer(out, true);
} else if (best_type == mime::application_json) {
auto *jwriter = new json_writer(out, false);
o_formatter = shared_ptr<output_formatter>(new json_formatter(jwriter));
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/json_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ json_formatter::json_formatter(json_writer *w) : writer(w),

json_formatter::~json_formatter() = default;

mime::type json_formatter::mime_type() const { return mime::text_json; }
mime::type json_formatter::mime_type() const { return mime::application_json; }

void json_formatter::write_tags(const tags_t &tags) {

Expand Down
8 changes: 4 additions & 4 deletions src/mime_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ string to_string(type t) {
} else if (text_xml == t) {
return "text/xml";
#ifdef HAVE_YAJL
} else if (text_json == t) {
return "text/json";
} else if (application_json == t) {
return "application/json";
#endif
} else {
throw runtime_error("No string conversion for unspecified MIME type.");
Expand All @@ -36,8 +36,8 @@ type parse_from(const std::string &name) {
} else if (name == "text/xml") {
t = text_xml;
#ifdef HAVE_YAJL
} else if (name == "text/json") {
t = text_json;
} else if (name == "application/json") {
t = application_json;
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/osm_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ list<mime::type> osm_responder::types_available() const {
list<mime::type> types;
types.push_back(mime::text_xml);
#ifdef HAVE_YAJL
types.push_back(mime::text_json);
types.push_back(mime::application_json);
#endif
return types;
}
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 text/json, etc...
* in .xml should be text/xml, .json should be application/json, etc...
*/
pair<string, mime::type> resource_mime_type(const string &path) {

Expand All @@ -284,7 +284,7 @@ namespace {
std::size_t json_found = path.rfind(".json");

if (json_found != string::npos && json_found == path.length() - 5) {
return make_pair(path.substr(0, json_found), mime::text_json);
return make_pair(path.substr(0, json_found), mime::application_json);
}
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions test/json.testcore/map_all.case
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Request-Method: GET
Request-URI: /api/0.6/map?bbox=1.1463021,0.9924642,1.1633345,1.0044411
HTTP-Accept: text/json
HTTP-Accept: application/json
---
Content-Type: text/json; charset=utf-8
Content-Type: application/json; charset=utf-8
Status: 200 OK
---
{ "version": "0.6",
Expand Down
4 changes: 2 additions & 2 deletions test/json.testcore/node_1.case
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Request-Method: GET
Request-URI: /api/0.6/node/1
HTTP-Accept: text/json
HTTP-Accept: application/json
---
Content-Type: text/json; charset=utf-8
Content-Type: application/json; charset=utf-8
!Content-Disposition:
Status: 200 OK
---
Expand Down
2 changes: 1 addition & 1 deletion test/json.testcore/node_2.case
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Request-Method: GET
Request-URI: /api/0.6/node/1.json
HTTP-Accept: */*
---
Content-Type: text/json; charset=utf-8
Content-Type: application/json; charset=utf-8
!Content-Disposition:
Status: 200 OK
---
Expand Down
2 changes: 1 addition & 1 deletion test/test_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ void check_response(std::istream &expected, std::istream &actual) {
content_type.substr(0, 9) == "text/html") {
check_content_body_xml(expected, actual);

} else if (content_type.substr(0, 9) == "text/json") {
} else if (content_type.substr(0, 16) == "application/json") {
check_content_body_json(expected, actual);

} else if (content_type.substr(0, 10) == "text/plain") {
Expand Down

0 comments on commit ee2d807

Please sign in to comment.