Skip to content
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

Forward query string when redirecting from /git-pull/ endpoint #303

Closed
wants to merge 2 commits into from
Closed
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
32 changes: 32 additions & 0 deletions nbgitpuller/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ def pull():
self.git_lock.release()


USED_UI_ARGUMENTS = frozenset((
'repo',
'branch',
'depth',
'urlpath',
'urlPath',
'subpath',
'subPath',
'app',
'targetpath',
'targetPath',
))


class UIHandler(JupyterHandler):
@web.authenticated
async def get(self):
Expand Down Expand Up @@ -171,6 +185,8 @@ async def get(self):
else:
path = 'tree/' + path

path = self.combine_query_string(path)

self.write(
jinja_env.get_template('status.html').render(
repo=repo, branch=branch, path=path, depth=depth, targetpath=targetpath, version=__version__,
Expand All @@ -179,6 +195,22 @@ async def get(self):
)
await self.flush()

def combine_query_string(self, targetpath):
"""
This function combines the query string in `targetpath` with all unused
query string parameters passed to this handler.
"""

from urllib.parse import urlparse, parse_qs, urlencode, urlunparse
target_parsed = urlparse(targetpath)
target_qs = parse_qs(target_parsed.query)
for key in self.request.arguments:
if key in USED_UI_ARGUMENTS or key in target_qs:
continue
target_qs[key] = self.get_argument(key)
targetpath = urlunparse(target_parsed._replace(query=urlencode(target_qs, doseq=True)))
return targetpath


class LegacyGitSyncRedirectHandler(JupyterHandler):
"""
Expand Down