@@ -558,3 +558,38 @@ def test_server_proxy_redirect_location_header_rewrite(
558558 # Should be rewritten to include the proxy prefix
559559 # The token query parameter should be preserved in the redirect
560560 assert location == f"/python-redirect/target/path?token={ TOKEN } "
561+
562+
563+ @pytest .mark .parametrize ("a_server" , ["notebook" , "lab" ], indirect = True )
564+ def test_server_proxy_redirect_location_header_absolute_url (
565+ a_server_port_and_token : Tuple [int , str ],
566+ ) -> None :
567+ """
568+ Test that Location headers in redirect responses are not rewritten when
569+ absolute_url=True is configured.
570+
571+ When absolute_url=True, the backend server receives the full proxy path
572+ (e.g., /python-redirect-abs/mydir instead of just /mydir). The proxy does
573+ not rewrite Location headers, passing them through as-is from the backend.
574+
575+ This means the backend must be aware of the proxy prefix to generate
576+ correct redirects, which is the intended behavior of absolute_url=True.
577+ """
578+ PORT , TOKEN = a_server_port_and_token
579+
580+ # Test 1: Named server proxy with absolute_url=True, redirect without trailing slash
581+ r = request_get (PORT , "/python-redirect-abs/mydir" , TOKEN )
582+ assert r .code == 301
583+ location = r .headers .get ("Location" )
584+ # Location header is not rewritten by proxy, passed through as-is from backend
585+ # Backend sees /python-redirect-abs/mydir and adds trailing slash: /python-redirect-abs/mydir/
586+ assert location == f"/python-redirect-abs/mydir/?token={ TOKEN } "
587+
588+ # Test 2: Named server proxy with absolute_url=True, verify no rewriting occurs
589+ # Request to /python-redirect-abs/abc (without trailing slash)
590+ r = request_get (PORT , "/python-redirect-abs/abc" , TOKEN )
591+ assert r .code == 301
592+ location = r .headers .get ("Location" )
593+ # Backend returns whatever it wants, proxy doesn't rewrite it
594+ # In this case, backend adds trailing slash to the full path it received
595+ assert location == f"/python-redirect-abs/abc/?token={ TOKEN } "
0 commit comments