11use 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 ,
48} ;
59use actix_web:: { web, HttpResponse } ;
610use atomic_lib:: Storelike ;
@@ -14,42 +18,19 @@ pub async fn handle_get_resource(
1418 req : actix_web:: HttpRequest ,
1519 conn : actix_web:: dev:: ConnectionInfo ,
1620) -> AtomicServerResult < HttpResponse > {
21+ let store = & appstate. store ;
1722 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- } ;
3123 let headers = req. headers ( ) ;
3224 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 ;
4625 timer. add ( "parse_headers" ) ;
4726
27+ let subject = get_subject ( & req, & conn, & appstate) ?;
28+ timer. add ( "parse_subject" ) ;
29+
4830 let for_agent = get_client_agent ( headers, & appstate, subject. to_string ( ) ) ?;
4931 timer. add ( "get_agent" ) ;
5032
5133 let mut builder = HttpResponse :: Ok ( ) ;
52-
5334 tracing:: debug!( "get_resource: {} as {}" , subject, content_type. to_mime( ) ) ;
5435 builder. append_header ( ( "Content-Type" , content_type. to_mime ( ) ) ) ;
5536 // 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(
6041 ) ) ;
6142 // When users uses back button, don't show the JSON response
6243 builder. append_header ( ( "Vary" , "Accept" ) ) ;
44+ timer. add ( "set_headers" ) ;
6345
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 ( ) ) ?;
6547 timer. add ( "get_resource" ) ;
6648
6749 let response_body = match content_type {
0 commit comments