1
1
use crate :: {
2
- appstate:: AppState , content_types:: get_accept, content_types:: ContentType ,
3
- errors:: AtomicServerResult , helpers:: get_client_agent, timer:: Timer ,
2
+ appstate:: AppState ,
3
+ content_types:: get_accept,
4
+ content_types:: ContentType ,
5
+ errors:: AtomicServerResult ,
6
+ helpers:: { get_client_agent, get_subject} ,
7
+ timer:: Timer ,
4
8
} ;
5
9
use actix_web:: { web, HttpResponse } ;
6
10
use atomic_lib:: Storelike ;
@@ -14,42 +18,19 @@ pub async fn handle_get_resource(
14
18
req : actix_web:: HttpRequest ,
15
19
conn : actix_web:: dev:: ConnectionInfo ,
16
20
) -> AtomicServerResult < HttpResponse > {
21
+ let store = & appstate. store ;
17
22
let mut timer = Timer :: new ( ) ;
18
-
19
- let domain = & appstate. config . opts . domain ;
20
- let host = conn. host ( ) ;
21
- let find = host. find ( domain) ;
22
- let subdomain = if let Some ( index) = find {
23
- if index == 0 {
24
- None
25
- } else {
26
- Some ( host[ 0 ..index - 1 ] . to_string ( ) )
27
- }
28
- } else {
29
- panic ! ( "Wrong domain! A requested URL did not contain the host for this domain. This should not be able to happen." ) ;
30
- } ;
31
23
let headers = req. headers ( ) ;
32
24
let content_type = get_accept ( headers) ;
33
-
34
- // You'd think there would be a simpler way of getting the requested URL...
35
- // See https://github.com/actix/actix-web/issues/2895
36
- let mut subject = appstate. store . get_server_url ( ) . clone ( ) ;
37
-
38
- // Doe this include the query params?
39
- subject. set_path ( & req. uri ( ) . to_string ( ) ) ;
40
-
41
- if let Some ( sd) = subdomain {
42
- subject. set_subdomain ( Some ( & sd) ) ?;
43
- }
44
-
45
- let store = & appstate. store ;
46
25
timer. add ( "parse_headers" ) ;
47
26
27
+ let subject = get_subject ( & req, & conn, & appstate) ?;
28
+ timer. add ( "parse_subject" ) ;
29
+
48
30
let for_agent = get_client_agent ( headers, & appstate, subject. to_string ( ) ) ?;
49
31
timer. add ( "get_agent" ) ;
50
32
51
33
let mut builder = HttpResponse :: Ok ( ) ;
52
-
53
34
tracing:: debug!( "get_resource: {} as {}" , subject, content_type. to_mime( ) ) ;
54
35
builder. append_header ( ( "Content-Type" , content_type. to_mime ( ) ) ) ;
55
36
// This prevents the browser from displaying the JSON response upon re-opening a closed tab
@@ -60,8 +41,9 @@ pub async fn handle_get_resource(
60
41
) ) ;
61
42
// When users uses back button, don't show the JSON response
62
43
builder. append_header ( ( "Vary" , "Accept" ) ) ;
44
+ timer. add ( "set_headers" ) ;
63
45
64
- let resource = store. get_resource_extended ( subject. as_str ( ) , false , for_agent. as_deref ( ) ) ?;
46
+ let resource = store. get_resource_extended ( & subject, false , for_agent. as_deref ( ) ) ?;
65
47
timer. add ( "get_resource" ) ;
66
48
67
49
let response_body = match content_type {
0 commit comments