@@ -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
@@ -224,7 +224,9 @@ pub fn get_subject(
224224 req : & actix_web:: HttpRequest ,
225225 conn : & actix_web:: dev:: ConnectionInfo ,
226226 appstate : & AppState ,
227- ) -> AtomicServerResult < String > {
227+ ) -> AtomicServerResult < ( String , ContentType ) > {
228+ let content_type = get_accept ( req. headers ( ) ) ;
229+
228230 let domain = & appstate. config . opts . domain ;
229231 let host = conn. host ( ) ;
230232 let subdomain = if let Some ( index) = host. find ( domain) {
@@ -243,23 +245,48 @@ pub fn get_subject(
243245 }
244246 let server_without_last_slash = subject_url. to_string ( ) . trim_end_matches ( '/' ) . to_string ( ) ;
245247 let subject = format ! ( "{}{}" , server_without_last_slash, & req. uri( ) . to_string( ) ) ;
246- Ok ( subject)
248+ // if let Some((ct, path)) = try_extension(req.path()) {
249+ // content_type = ct;
250+ // return Ok((path.to_string(), content_type));
251+ // }
252+ Ok ( ( subject, content_type) )
247253}
248254
249- /// Finds the extension
250- pub fn try_extension ( path : & str ) -> Option < ( ContentType , & str ) > {
251- let items: Vec < & str > = path. split ( '.' ) . collect ( ) ;
252- if items. len ( ) == 2 {
253- let path = items[ 0 ] ;
254- let content_type = match items[ 1 ] {
255- "json" => ContentType :: Json ,
256- "jsonld" => ContentType :: JsonLd ,
257- "jsonad" => ContentType :: JsonAd ,
258- "html" => ContentType :: Html ,
259- "ttl" => ContentType :: Turtle ,
260- _ => return None ,
261- } ;
262- return Some ( ( content_type, path) ) ;
255+ /// Finds the extension of a supported serialization format.
256+ /// Not used right now, see: https://github.com/atomicdata-dev/atomic-data-rust/issues/601
257+ #[ allow( dead_code) ]
258+ fn try_extension ( path : & str ) -> Option < ( ContentType , & str ) > {
259+ // Check if path ends with one of the folliwing extensions
260+ let extensions = [
261+ ".json" ,
262+ ".jsonld" ,
263+ ".jsonad" ,
264+ ".html" ,
265+ ".ttl" ,
266+ ".nt" ,
267+ ".nq" ,
268+ ".ntriples" ,
269+ ".nt" ,
270+ ] ;
271+ let mut found = None ;
272+ for ext in extensions. iter ( ) {
273+ if path. ends_with ( ext) {
274+ println ! ( "Found extension: {}" , ext) ;
275+ let path = & path[ 0 ..path. len ( ) - ext. len ( ) ] ;
276+ let content_type = match * ext {
277+ ".json" => Some ( ContentType :: Json ) ,
278+ ".jsonld" => Some ( ContentType :: JsonLd ) ,
279+ ".jsonad" => Some ( ContentType :: JsonAd ) ,
280+ ".html" => Some ( ContentType :: Html ) ,
281+ ".ttl" => Some ( ContentType :: Turtle ) ,
282+ ".nt" => Some ( ContentType :: NTriples ) ,
283+ ".ntriples" => Some ( ContentType :: NTriples ) ,
284+ _ => None ,
285+ } ;
286+ if let Some ( ct) = content_type {
287+ found = Some ( ( ct, path) ) ;
288+ }
289+ }
263290 }
264- None
291+ found
265292}
0 commit comments