Skip to content

Commit

Permalink
Forward query string when redirecting from /git-pull/ endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
frankier committed Apr 12, 2023
1 parent af331f8 commit 97174a2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions nbgitpuller/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ def pull():
self.git_lock.release()


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


class UIHandler(IPythonHandler):
@web.authenticated
async def get(self):
Expand All @@ -149,6 +163,8 @@ async def get(self):
targetpath = self.get_argument('targetpath', None) or \
self.get_argument('targetPath', repo.split('/')[-1])

targetpath = self.combine_qs(targetpath)

if urlPath:
path = urlPath
else:
Expand All @@ -168,6 +184,17 @@ async def get(self):
)
await self.flush()

def combine_qs(self, targetpath):
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(IPythonHandler):
"""
Expand Down

0 comments on commit 97174a2

Please sign in to comment.