Skip to content

Commit

Permalink
Merge pull request #40 from p4plus2/master
Browse files Browse the repository at this point in the history
Fixed the infinite redirect bug caused by improper auth cookie handling.
  • Loading branch information
portablejim authored Jan 31, 2017
2 parents 1e61821 + 09721cc commit 33d01f1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,17 @@ def doDownload(manifest):
continue

# File is not cached and needs to be downloaded
projectResponse = sess.get("https://minecraft.curseforge.com/projects/%s" % (dependency['projectID']), stream=True)
projectResponse.url = projectResponse.url.replace('?cookieTest=1', '')
projectResponse = sess.get("https://minecraft.curseforge.com/projects/%s" % (dependency['projectID']), stream=True, allow_redirects=False)

auth_cookie = None
for redirect in sess.resolve_redirects(projectResponse, projectResponse.request):
sess.cookies.update({'Auth.Token': auth_cookie})
if redirect.headers.get('Set-Cookie') is not None:
cookie_list = redirect.headers.get('Set-Cookie').split(";")[0].split("=")
if cookie_list[0] == 'Auth.Token':
auth_cookie = cookie_list[1]
projectResponse.url = redirect.url

fileResponse = sess.get("%s/files/%s/download" % (projectResponse.url, dependency['fileID']), stream=True)
while fileResponse.is_redirect:
source = fileResponse
Expand Down

0 comments on commit 33d01f1

Please sign in to comment.