@@ -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
@@ -160,7 +160,7 @@ pub fn get_client_agent(
160160 & appstate. store ,
161161 )
162162 . map_err ( |e| format ! ( "Authentication failed: {}" , e) ) ?;
163- Ok ( for_agent. into ( ) )
163+ Ok ( for_agent)
164164}
165165
166166fn session_cookies_from_header ( header : & HeaderValue ) -> AtomicServerResult < Vec < String > > {
@@ -250,7 +250,9 @@ pub fn get_subject(
250250 req : & actix_web:: HttpRequest ,
251251 conn : & actix_web:: dev:: ConnectionInfo ,
252252 appstate : & AppState ,
253- ) -> AtomicServerResult < String > {
253+ ) -> AtomicServerResult < ( String , ContentType ) > {
254+ let content_type = get_accept ( req. headers ( ) ) ;
255+
254256 let domain = & appstate. config . opts . domain ;
255257 let host = conn. host ( ) ;
256258 let subdomain = if let Some ( index) = host. find ( domain) {
@@ -269,23 +271,48 @@ pub fn get_subject(
269271 }
270272 let server_without_last_slash = subject_url. to_string ( ) . trim_end_matches ( '/' ) . to_string ( ) ;
271273 let subject = format ! ( "{}{}" , server_without_last_slash, & req. uri( ) . to_string( ) ) ;
272- Ok ( subject)
274+ // if let Some((ct, path)) = try_extension(req.path()) {
275+ // content_type = ct;
276+ // return Ok((path.to_string(), content_type));
277+ // }
278+ Ok ( ( subject, content_type) )
273279}
274280
275- /// Finds the extension
276- pub fn try_extension ( path : & str ) -> Option < ( ContentType , & str ) > {
277- let items: Vec < & str > = path. split ( '.' ) . collect ( ) ;
278- if items. len ( ) == 2 {
279- let path = items[ 0 ] ;
280- let content_type = match items[ 1 ] {
281- "json" => ContentType :: Json ,
282- "jsonld" => ContentType :: JsonLd ,
283- "jsonad" => ContentType :: JsonAd ,
284- "html" => ContentType :: Html ,
285- "ttl" => ContentType :: Turtle ,
286- _ => return None ,
287- } ;
288- return Some ( ( content_type, path) ) ;
281+ /// Finds the extension of a supported serialization format.
282+ /// Not used right now, see: https://github.com/atomicdata-dev/atomic-data-rust/issues/601
283+ #[ allow( dead_code) ]
284+ fn try_extension ( path : & str ) -> Option < ( ContentType , & str ) > {
285+ // Check if path ends with one of the folliwing extensions
286+ let extensions = [
287+ ".json" ,
288+ ".jsonld" ,
289+ ".jsonad" ,
290+ ".html" ,
291+ ".ttl" ,
292+ ".nt" ,
293+ ".nq" ,
294+ ".ntriples" ,
295+ ".nt" ,
296+ ] ;
297+ let mut found = None ;
298+ for ext in extensions. iter ( ) {
299+ if path. ends_with ( ext) {
300+ println ! ( "Found extension: {}" , ext) ;
301+ let path = & path[ 0 ..path. len ( ) - ext. len ( ) ] ;
302+ let content_type = match * ext {
303+ ".json" => Some ( ContentType :: Json ) ,
304+ ".jsonld" => Some ( ContentType :: JsonLd ) ,
305+ ".jsonad" => Some ( ContentType :: JsonAd ) ,
306+ ".html" => Some ( ContentType :: Html ) ,
307+ ".ttl" => Some ( ContentType :: Turtle ) ,
308+ ".nt" => Some ( ContentType :: NTriples ) ,
309+ ".ntriples" => Some ( ContentType :: NTriples ) ,
310+ _ => None ,
311+ } ;
312+ if let Some ( ct) = content_type {
313+ found = Some ( ( ct, path) ) ;
314+ }
315+ }
289316 }
290- None
317+ found
291318}
0 commit comments