From 71016ce4752e5d3278af7b8db66a959d3a25519f Mon Sep 17 00:00:00 2001 From: Tpt Date: Tue, 30 Jun 2020 12:14:14 +0200 Subject: [PATCH] Makes the format from MIME type converter accept more MIME types --- lib/src/sparql/model.rs | 4 ++-- lib/src/syntax.rs | 14 +++++++++----- server/src/main.rs | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/src/sparql/model.rs b/lib/src/sparql/model.rs index 7bce5d5f..b2d0709c 100644 --- a/lib/src/sparql/model.rs +++ b/lib/src/sparql/model.rs @@ -106,10 +106,10 @@ impl FileSyntax for QueryResultSyntax { fn from_mime_type(media_type: &str) -> Option { if let Some(base_type) = media_type.split(';').next() { match base_type { - "application/xml" | "application/sparql-results+xml" => { + "application/sparql-results+xml" | "application/xml" | "text/xml" => { Some(QueryResultSyntax::Xml) } - "application/json" | "application/sparql-results+json" => { + "application/sparql-results+json" | "application/json" | "text/json" => { Some(QueryResultSyntax::Json) } _ => None, diff --git a/lib/src/syntax.rs b/lib/src/syntax.rs index 1e68ab73..5d1aa5e7 100644 --- a/lib/src/syntax.rs +++ b/lib/src/syntax.rs @@ -60,9 +60,11 @@ impl FileSyntax for GraphSyntax { fn from_mime_type(media_type: &str) -> Option { if let Some(base_type) = media_type.split(';').next() { match base_type { - "application/n-triples" => Some(GraphSyntax::NTriples), - "text/turtle" => Some(GraphSyntax::Turtle), - "application/xml" | "application/rdf+xml" => Some(GraphSyntax::RdfXml), + "application/n-triples" | "text/plain" => Some(GraphSyntax::NTriples), + "text/turtle" | "application/turtle" | "application/x-turtle" => { + Some(GraphSyntax::Turtle) + } + "application/rdf+xml" | "application/xml" | "text/xml" => Some(GraphSyntax::RdfXml), _ => None, } } else { @@ -105,8 +107,10 @@ impl FileSyntax for DatasetSyntax { fn from_mime_type(media_type: &str) -> Option { if let Some(base_type) = media_type.split(';').next() { match base_type { - "application/n-quads" => Some(DatasetSyntax::NQuads), - "application/trig" => Some(DatasetSyntax::TriG), + "application/n-quads" | "text/x-nquads" | "text/nquads" => { + Some(DatasetSyntax::NQuads) + } + "application/trig" | "application/x-trig" => Some(DatasetSyntax::TriG), _ => None, } } else { diff --git a/server/src/main.rs b/server/src/main.rs index 34dc4cfb..76b60485 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -343,7 +343,7 @@ mod tests { #[test] fn post_unsupported_file() { let mut request = Request::new(Method::Post, Url::parse("http://localhost/").unwrap()); - request.insert_header("Content-Type", "text/plain"); + request.insert_header("Content-Type", "text/foo"); exec(request, StatusCode::UnsupportedMediaType) }