@@ -9,7 +9,7 @@ use atomic_lib::Storelike;
9
9
use percent_encoding:: percent_decode_str;
10
10
use std:: str:: FromStr ;
11
11
12
- use crate :: content_types:: ContentType ;
12
+ use crate :: content_types:: { get_accept , ContentType } ;
13
13
use crate :: errors:: { AppErrorType , AtomicServerError } ;
14
14
use crate :: { appstate:: AppState , errors:: AtomicServerResult } ;
15
15
@@ -248,7 +248,9 @@ pub fn get_subject(
248
248
req : & actix_web:: HttpRequest ,
249
249
conn : & actix_web:: dev:: ConnectionInfo ,
250
250
appstate : & AppState ,
251
- ) -> AtomicServerResult < String > {
251
+ ) -> AtomicServerResult < ( String , ContentType ) > {
252
+ let content_type = get_accept ( req. headers ( ) ) ;
253
+
252
254
let domain = & appstate. config . opts . domain ;
253
255
let host = conn. host ( ) ;
254
256
let subdomain = if let Some ( index) = host. find ( domain) {
@@ -267,23 +269,48 @@ pub fn get_subject(
267
269
}
268
270
let server_without_last_slash = subject_url. to_string ( ) . trim_end_matches ( '/' ) . to_string ( ) ;
269
271
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) )
271
277
}
272
278
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
+ }
287
314
}
288
- None
315
+ found
289
316
}
0 commit comments