Makes the format from MIME type converter accept more MIME types

pull/41/head
Tpt 4 years ago
parent 955249b3e6
commit 71016ce475
  1. 4
      lib/src/sparql/model.rs
  2. 14
      lib/src/syntax.rs
  3. 2
      server/src/main.rs

@ -106,10 +106,10 @@ impl FileSyntax for QueryResultSyntax {
fn from_mime_type(media_type: &str) -> Option<Self> { fn from_mime_type(media_type: &str) -> Option<Self> {
if let Some(base_type) = media_type.split(';').next() { if let Some(base_type) = media_type.split(';').next() {
match base_type { match base_type {
"application/xml" | "application/sparql-results+xml" => { "application/sparql-results+xml" | "application/xml" | "text/xml" => {
Some(QueryResultSyntax::Xml) Some(QueryResultSyntax::Xml)
} }
"application/json" | "application/sparql-results+json" => { "application/sparql-results+json" | "application/json" | "text/json" => {
Some(QueryResultSyntax::Json) Some(QueryResultSyntax::Json)
} }
_ => None, _ => None,

@ -60,9 +60,11 @@ impl FileSyntax for GraphSyntax {
fn from_mime_type(media_type: &str) -> Option<Self> { fn from_mime_type(media_type: &str) -> Option<Self> {
if let Some(base_type) = media_type.split(';').next() { if let Some(base_type) = media_type.split(';').next() {
match base_type { match base_type {
"application/n-triples" => Some(GraphSyntax::NTriples), "application/n-triples" | "text/plain" => Some(GraphSyntax::NTriples),
"text/turtle" => Some(GraphSyntax::Turtle), "text/turtle" | "application/turtle" | "application/x-turtle" => {
"application/xml" | "application/rdf+xml" => Some(GraphSyntax::RdfXml), Some(GraphSyntax::Turtle)
}
"application/rdf+xml" | "application/xml" | "text/xml" => Some(GraphSyntax::RdfXml),
_ => None, _ => None,
} }
} else { } else {
@ -105,8 +107,10 @@ impl FileSyntax for DatasetSyntax {
fn from_mime_type(media_type: &str) -> Option<Self> { fn from_mime_type(media_type: &str) -> Option<Self> {
if let Some(base_type) = media_type.split(';').next() { if let Some(base_type) = media_type.split(';').next() {
match base_type { match base_type {
"application/n-quads" => Some(DatasetSyntax::NQuads), "application/n-quads" | "text/x-nquads" | "text/nquads" => {
"application/trig" => Some(DatasetSyntax::TriG), Some(DatasetSyntax::NQuads)
}
"application/trig" | "application/x-trig" => Some(DatasetSyntax::TriG),
_ => None, _ => None,
} }
} else { } else {

@ -343,7 +343,7 @@ mod tests {
#[test] #[test]
fn post_unsupported_file() { fn post_unsupported_file() {
let mut request = Request::new(Method::Post, Url::parse("http://localhost/").unwrap()); 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) exec(request, StatusCode::UnsupportedMediaType)
} }

Loading…
Cancel
Save