@@ -10,7 +10,7 @@ use atomic_lib::Storelike;
1010use percent_encoding:: percent_decode_str;
1111use std:: str:: FromStr ;
1212
13- use crate :: content_types:: ContentType ;
13+ use crate :: content_types:: { get_accept , ContentType } ;
1414use crate :: errors:: { AppErrorType , AtomicServerError } ;
1515use crate :: { appstate:: AppState , errors:: AtomicServerResult } ;
1616
@@ -286,7 +286,9 @@ pub fn get_subject(
286286 req : & actix_web:: HttpRequest ,
287287 conn : & actix_web:: dev:: ConnectionInfo ,
288288 appstate : & AppState ,
289- ) -> AtomicServerResult < String > {
289+ ) -> AtomicServerResult < ( String , ContentType ) > {
290+ let content_type = get_accept ( req. headers ( ) ) ;
291+
290292 let domain = & appstate. config . opts . domain ;
291293 let host = conn. host ( ) ;
292294 let subdomain = if let Some ( index) = host. find ( domain) {
@@ -305,23 +307,48 @@ pub fn get_subject(
305307 }
306308 let server_without_last_slash = subject_url. to_string ( ) . trim_end_matches ( '/' ) . to_string ( ) ;
307309 let subject = format ! ( "{}{}" , server_without_last_slash, & req. uri( ) . to_string( ) ) ;
308- Ok ( subject)
310+ // if let Some((ct, path)) = try_extension(req.path()) {
311+ // content_type = ct;
312+ // return Ok((path.to_string(), content_type));
313+ // }
314+ Ok ( ( subject, content_type) )
309315}
310316
311- /// Finds the extension
312- pub fn try_extension ( path : & str ) -> Option < ( ContentType , & str ) > {
313- let items: Vec < & str > = path. split ( '.' ) . collect ( ) ;
314- if items. len ( ) == 2 {
315- let path = items[ 0 ] ;
316- let content_type = match items[ 1 ] {
317- "json" => ContentType :: Json ,
318- "jsonld" => ContentType :: JsonLd ,
319- "jsonad" => ContentType :: JsonAd ,
320- "html" => ContentType :: Html ,
321- "ttl" => ContentType :: Turtle ,
322- _ => return None ,
323- } ;
324- return Some ( ( content_type, path) ) ;
317+ /// Finds the extension of a supported serialization format.
318+ /// Not used right now, see: https://github.com/atomicdata-dev/atomic-data-rust/issues/601
319+ #[ allow( dead_code) ]
320+ fn try_extension ( path : & str ) -> Option < ( ContentType , & str ) > {
321+ // Check if path ends with one of the folliwing extensions
322+ let extensions = [
323+ ".json" ,
324+ ".jsonld" ,
325+ ".jsonad" ,
326+ ".html" ,
327+ ".ttl" ,
328+ ".nt" ,
329+ ".nq" ,
330+ ".ntriples" ,
331+ ".nt" ,
332+ ] ;
333+ let mut found = None ;
334+ for ext in extensions. iter ( ) {
335+ if path. ends_with ( ext) {
336+ println ! ( "Found extension: {}" , ext) ;
337+ let path = & path[ 0 ..path. len ( ) - ext. len ( ) ] ;
338+ let content_type = match * ext {
339+ ".json" => Some ( ContentType :: Json ) ,
340+ ".jsonld" => Some ( ContentType :: JsonLd ) ,
341+ ".jsonad" => Some ( ContentType :: JsonAd ) ,
342+ ".html" => Some ( ContentType :: Html ) ,
343+ ".ttl" => Some ( ContentType :: Turtle ) ,
344+ ".nt" => Some ( ContentType :: NTriples ) ,
345+ ".ntriples" => Some ( ContentType :: NTriples ) ,
346+ _ => None ,
347+ } ;
348+ if let Some ( ct) = content_type {
349+ found = Some ( ( ct, path) ) ;
350+ }
351+ }
325352 }
326- None
353+ found
327354}
0 commit comments