Skip to content

Commit

Permalink
check for branch in session cookie, then request header
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-wm-arthur committed Jun 7, 2021
1 parent b010b49 commit 63fbd12
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion dolt/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ def __init__(self, get_response):
def __call__(self, request):
return self.get_response(request)

@staticmethod
def _requested_branch(request):
if DOLT_BRANCH_KEYWORD in request.session:
return request.session.get(DOLT_BRANCH_KEYWORD)
if DOLT_BRANCH_KEYWORD in request.headers:
return request.headers.get(DOLT_BRANCH_KEYWORD)
return DOLT_DEFAULT_BRANCH

def process_view(self, request, view_func, view_args, view_kwargs):
# lookup the active branch in the session cookie
branch = request.session.get(DOLT_BRANCH_KEYWORD, DOLT_DEFAULT_BRANCH)
branch = self._requested_branch(request)
try:
# switch the database to use the active branch
Branch.objects.get(pk=branch).checkout_branch()
Expand Down

0 comments on commit 63fbd12

Please sign in to comment.