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

Surfaces redirects from URI-Ms. Closes #451 #452

Merged
merged 2 commits into from
Jul 27, 2018
Merged
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
14 changes: 12 additions & 2 deletions ipwb/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=status)

for idx, hLine in enumerate(hLines):
k, v = hLine.split(': ', 1)
Expand All @@ -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
Expand All @@ -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']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably fail in many cases. I think the simplistic assumption made here is that extracted uriBeforeURIR is going to be a directory URI and stored Location header will be a relative path. Both of these are unrealistic assumptions. I think you can simply return the Location header without any modification and let the SW deal with it. I am not sure how will it behave in case of a full URIs (probably it will be caught by the SW too).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The location header prior to this is a URI-R. Without the prepending of the replay system, the redirect forwards the user to the live Web.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uriBeforeURIR ends up being http://localhost:5000/memento/12345678901234/.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misunderstood the uriBeforeURIR earlier. However, Location header is not going to be a full URI all the time, it could very well be a relative or absolute path.

resp.headers['location'] = newURIM

return resp


Expand Down