@@ -9,7 +9,7 @@ use atomic_lib::Storelike;
99use percent_encoding:: percent_decode_str;
1010use std:: str:: FromStr ;
1111
12- use crate :: content_types:: ContentType ;
12+ use crate :: content_types:: { get_accept , ContentType } ;
1313use crate :: errors:: { AppErrorType , AtomicServerError } ;
1414use crate :: { appstate:: AppState , errors:: AtomicServerResult } ;
1515
@@ -248,7 +248,9 @@ pub fn get_subject(
248248 req : & actix_web:: HttpRequest ,
249249 conn : & actix_web:: dev:: ConnectionInfo ,
250250 appstate : & AppState ,
251- ) -> AtomicServerResult < String > {
251+ ) -> AtomicServerResult < ( String , ContentType ) > {
252+ let content_type = get_accept ( req. headers ( ) ) ;
253+
252254 let domain = & appstate. config . opts . domain ;
253255 let host = conn. host ( ) ;
254256 let subdomain = if let Some ( index) = host. find ( domain) {
@@ -267,23 +269,48 @@ pub fn get_subject(
267269 }
268270 let server_without_last_slash = subject_url. to_string ( ) . trim_end_matches ( '/' ) . to_string ( ) ;
269271 let subject = format ! ( "{}{}" , server_without_last_slash, & req. uri( ) . to_string( ) ) ;
270- Ok ( subject)
272+ // if let Some((ct, path)) = try_extension(req.path()) {
273+ // content_type = ct;
274+ // return Ok((path.to_string(), content_type));
275+ // }
276+ Ok ( ( subject, content_type) )
271277}
272278
273- /// Finds the extension
274- pub fn try_extension ( path : & str ) -> Option < ( ContentType , & str ) > {
275- let items: Vec < & str > = path. split ( '.' ) . collect ( ) ;
276- if items. len ( ) == 2 {
277- let path = items[ 0 ] ;
278- let content_type = match items[ 1 ] {
279- "json" => ContentType :: Json ,
280- "jsonld" => ContentType :: JsonLd ,
281- "jsonad" => ContentType :: JsonAd ,
282- "html" => ContentType :: Html ,
283- "ttl" => ContentType :: Turtle ,
284- _ => return None ,
285- } ;
286- return Some ( ( content_type, path) ) ;
279+ /// Finds the extension of a supported serialization format.
280+ /// Not used right now, see: https://github.com/atomicdata-dev/atomic-data-rust/issues/601
281+ #[ allow( dead_code) ]
282+ fn try_extension ( path : & str ) -> Option < ( ContentType , & str ) > {
283+ // Check if path ends with one of the folliwing extensions
284+ let extensions = [
285+ ".json" ,
286+ ".jsonld" ,
287+ ".jsonad" ,
288+ ".html" ,
289+ ".ttl" ,
290+ ".nt" ,
291+ ".nq" ,
292+ ".ntriples" ,
293+ ".nt" ,
294+ ] ;
295+ let mut found = None ;
296+ for ext in extensions. iter ( ) {
297+ if path. ends_with ( ext) {
298+ println ! ( "Found extension: {}" , ext) ;
299+ let path = & path[ 0 ..path. len ( ) - ext. len ( ) ] ;
300+ let content_type = match * ext {
301+ ".json" => Some ( ContentType :: Json ) ,
302+ ".jsonld" => Some ( ContentType :: JsonLd ) ,
303+ ".jsonad" => Some ( ContentType :: JsonAd ) ,
304+ ".html" => Some ( ContentType :: Html ) ,
305+ ".ttl" => Some ( ContentType :: Turtle ) ,
306+ ".nt" => Some ( ContentType :: NTriples ) ,
307+ ".ntriples" => Some ( ContentType :: NTriples ) ,
308+ _ => None ,
309+ } ;
310+ if let Some ( ct) = content_type {
311+ found = Some ( ( ct, path) ) ;
312+ }
313+ }
287314 }
288- None
315+ found
289316}
0 commit comments