Include full path when determining proxy host url
Session validation includes a method for determining the proxy host url, but previously did not include the path for the initial request. This caused a situation where users with a new session would not be able to complete their first search, since the session validation follow-through url did not include the actual path for their search query. The method now includes a flag for only extracting the root url, which is needed for creating full urls in the content filter. Fixes #708
This commit is contained in:
		
							parent
							
								
									aa198ed562
								
							
						
					
					
						commit
						2eee0b87d5
					
				| 
						 | 
				
			
			@ -35,11 +35,11 @@ def get_request_url(url: str) -> str:
 | 
			
		|||
    return url
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_proxy_host_url(r: Request, default: str) -> str:
 | 
			
		||||
    scheme = r.headers.get('X-Forwarded-Proto', 'http')
 | 
			
		||||
def get_proxy_host_url(r: Request, default: str, root=False) -> str:
 | 
			
		||||
    scheme = r.headers.get('X-Forwarded-Proto', 'https')
 | 
			
		||||
    http_host = r.headers.get('X-Forwarded-Host')
 | 
			
		||||
    if http_host:
 | 
			
		||||
        return f'{scheme}://{http_host}/'
 | 
			
		||||
        return f'{scheme}://{http_host}{r.full_path if not root else "/"}'
 | 
			
		||||
 | 
			
		||||
    return default
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -117,7 +117,10 @@ class Search:
 | 
			
		|||
        """
 | 
			
		||||
        mobile = 'Android' in self.user_agent or 'iPhone' in self.user_agent
 | 
			
		||||
        # reconstruct url if X-Forwarded-Host header present
 | 
			
		||||
        root_url = get_proxy_host_url(self.request, self.request.url_root)
 | 
			
		||||
        root_url = get_proxy_host_url(
 | 
			
		||||
            self.request,
 | 
			
		||||
            self.request.url_root,
 | 
			
		||||
            root=True)
 | 
			
		||||
 | 
			
		||||
        content_filter = Filter(self.session_key,
 | 
			
		||||
                                root_url=root_url,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user