@@ -10,7 +10,7 @@ use atomic_lib::Storelike;
10
10
use percent_encoding:: percent_decode_str;
11
11
use std:: str:: FromStr ;
12
12
13
- use crate :: content_types:: ContentType ;
13
+ use crate :: content_types:: { get_accept , ContentType } ;
14
14
use crate :: errors:: { AppErrorType , AtomicServerError } ;
15
15
use crate :: { appstate:: AppState , errors:: AtomicServerResult } ;
16
16
@@ -160,7 +160,7 @@ pub fn get_client_agent(
160
160
& appstate. store ,
161
161
)
162
162
. map_err ( |e| format ! ( "Authentication failed: {}" , e) ) ?;
163
- Ok ( for_agent. into ( ) )
163
+ Ok ( for_agent)
164
164
}
165
165
166
166
fn session_cookies_from_header ( header : & HeaderValue ) -> AtomicServerResult < Vec < String > > {
@@ -250,7 +250,9 @@ pub fn get_subject(
250
250
req : & actix_web:: HttpRequest ,
251
251
conn : & actix_web:: dev:: ConnectionInfo ,
252
252
appstate : & AppState ,
253
- ) -> AtomicServerResult < String > {
253
+ ) -> AtomicServerResult < ( String , ContentType ) > {
254
+ let content_type = get_accept ( req. headers ( ) ) ;
255
+
254
256
let domain = & appstate. config . opts . domain ;
255
257
let host = conn. host ( ) ;
256
258
let subdomain = if let Some ( index) = host. find ( domain) {
@@ -269,23 +271,48 @@ pub fn get_subject(
269
271
}
270
272
let server_without_last_slash = subject_url. to_string ( ) . trim_end_matches ( '/' ) . to_string ( ) ;
271
273
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) )
273
279
}
274
280
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
+ }
289
316
}
290
- None
317
+ found
291
318
}
0 commit comments