Skip to content

Include query params in 404 redirects #6957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion readthedocs/proxito/tests/handler_404_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def inner_view(request, exception, *args, **kwargs):
return view_func(
request,
*args,
proxito_path=request.get_full_path(),
proxito_path=request.path,
**kwargs,
)
return inner_view
Expand Down
3 changes: 1 addition & 2 deletions readthedocs/proxito/tests/test_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,7 @@ def test_directory_indexes_get_args(self):
self.project.versions.update(active=True, built=True)
# Confirm we've serving from storage for the `index-exists/index.html` file
response = self.client.get(
reverse('proxito_404_handler', kwargs={
'proxito_path': '/en/latest/index-exists?foo=bar'}),
reverse('proxito_404_handler', kwargs={'proxito_path': '/en/latest/index-exists'}) + '?foo=bar',
HTTP_HOST='project.readthedocs.io',
)
self.assertEqual(
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/proxito/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ def get_redirect_response(self, request, redirect_path, proxito_path, http_statu
"""

schema, netloc, path, params, query, fragments = urlparse(proxito_path)
# `proxito_path` doesn't include query params.
query = urlparse(request.get_full_path()).query
new_path = urlunparse((schema, netloc, redirect_path, params, query, fragments))

# Re-use the domain and protocol used in the current request.
Expand Down
8 changes: 7 additions & 1 deletion readthedocs/proxito/views/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,13 @@ def get(self, request, proxito_path, template_name='404.html'):
new_path = parts.path.rstrip('/') + f'/{tryfile}'
else:
new_path = parts.path.rstrip('/') + '/'
new_parts = parts._replace(path=new_path)

# `proxito_path` doesn't include query params.`
query = urlparse(request.get_full_path()).query
new_parts = parts._replace(
path=new_path,
query=query,
)
redirect_url = new_parts.geturl()

# TODO: decide if we need to check for infinite redirect here
Expand Down