From 6cae2b3d01e0b8f22a33799885a753f87cb1f820 Mon Sep 17 00:00:00 2001 From: Mat Kelly Date: Fri, 27 Jul 2018 18:29:15 -0400 Subject: [PATCH 1/2] Surfaces redirects from URI-Ms. Closes #451 --- ipwb/replay.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ipwb/replay.py b/ipwb/replay.py index d91f626f..483b550c 100755 --- a/ipwb/replay.py +++ b/ipwb/replay.py @@ -651,7 +651,11 @@ def handler(signum, frame): hLines = header.split('\n') hLines.pop(0) - resp = Response(payload) + status = 200 + if 'status_code' in jObj: + status = jObj['status_code'] + + resp = Response(payload, status=jObj['status_code']) for idx, hLine in enumerate(hLines): k, v = hLine.split(': ', 1) @@ -663,7 +667,7 @@ def handler(signum, frame): continue # Data may have no actually been chunked resp.set_data(unchunkedPayload) - if k.lower() not in ["content-type", "content-encoding"]: + if k.lower() not in ["content-type", "content-encoding", "location"]: k = "X-Archive-Orig-" + k resp.headers[k] = v @@ -684,6 +688,12 @@ def handler(signum, frame): # respWithLinkHeader = getLinkHeaderAbbreviatedTimeMap(path, datetime) # resp.headers['Link'] = respWithLinkHeader.replace('\n', ' ') + if status[0] == '3': + # Bad assumption that the URI-M will contain \d14 but works for now. + uriBeforeURIR = request.url[:re.search(r'/\d{14}/', request.url).end()] + newURIM = uriBeforeURIR + resp.headers['Location'] + resp.headers['location'] = newURIM + return resp From 7843bd021346ae3fab81b3892389b9f211747eb6 Mon Sep 17 00:00:00 2001 From: Mat Kelly Date: Fri, 27 Jul 2018 18:31:31 -0400 Subject: [PATCH 2/2] Fix status code reference --- ipwb/replay.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipwb/replay.py b/ipwb/replay.py index 483b550c..3b25be1f 100755 --- a/ipwb/replay.py +++ b/ipwb/replay.py @@ -655,7 +655,7 @@ def handler(signum, frame): if 'status_code' in jObj: status = jObj['status_code'] - resp = Response(payload, status=jObj['status_code']) + resp = Response(payload, status=status) for idx, hLine in enumerate(hLines): k, v = hLine.split(': ', 1)