Display that redirects were followed properly #7

Closed
opened 2014-04-30 13:12:33 -05:00 by jeromegn · 9 comments
jeromegn commented 2014-04-30 13:12:33 -05:00 (Migrated from github.com)

When clicking a link which triggers a redirect (302 or whatever), PJAX disregards it and pushed the state with the link's URL.

I think it should push, in the state, the URL as sent in the response's header "Location". Also, probably worth looking at that header to check if the URL is external and if it is, then don't try to do PJAX on it.

When clicking a link which triggers a redirect (302 or whatever), PJAX disregards it and pushed the state with the link's URL. I think it should push, in the state, the URL as sent in the response's header "Location". Also, probably worth looking at that header to check if the URL is external and if it is, then don't try to do PJAX on it.
MoOx commented 2014-04-30 13:18:19 -05:00 (Migrated from github.com)

Oh yeah. Will also add this to the incoming tests. Thanks for the report.
I've planned to work on that this week.

Oh yeah. Will also add this to the incoming tests. Thanks for the report. I've planned to work on that this week.
jeromegn commented 2014-06-04 09:13:34 -05:00 (Migrated from github.com)

I've tried tackling this on my own and it's not quite possible.

There's no way to figure out if there was a redirect. The only way I found was to add a header in the response, from my server, stating the "final url".

I've tried tackling this on my own and it's not quite possible. There's no way to figure out if there was a redirect. The only way I found was to add a header in the response, from my server, stating the "final url".
MoOx commented 2014-06-04 11:04:14 -05:00 (Migrated from github.com)

Hum... Do you check others implementations of pjax ? Like jquery-pjax or turbolinks ?

Hum... Do you check others implementations of pjax ? Like jquery-pjax or turbolinks ?
farneman commented 2015-06-22 15:12:04 -05:00 (Migrated from github.com)

This feature would be useful to me as well.

Looks like jquery-pjax looks for a special 'X-PJAX-URL' response header and then falls back to the request url. Turbolinks looks for a 'X-XHR-Redirected-To' response header which is set by the gem on the server side (Rails).

Would it be possible to make use of the response.responseUrl property where/when it's available?

This feature would be useful to me as well. Looks like jquery-pjax looks for a special 'X-PJAX-URL' response header and then falls back to the request url. Turbolinks looks for a 'X-XHR-Redirected-To' response header which is set by the gem on the server side (Rails). Would it be possible to make use of the `response.responseUrl` property where/when it's available?
MoOx commented 2015-06-23 01:55:50 -05:00 (Migrated from github.com)

Not a bad idea. We should make this key customisable.
PR welcome :)

Not a bad idea. We should make this key customisable. PR welcome :)
darylteo commented 2016-01-04 18:58:47 -05:00 (Migrated from github.com)

I believe this feature is extremely crucial, but if it requires changes to the server breaks the "it just works" feature of this library.

While we're doing this, @MoOx would you like pjax to send a X-PJAX header to the server so that the server can detect a pjax request?

I believe this feature is extremely crucial, but if it requires changes to the server breaks the "it just works" feature of this library. While we're doing this, @MoOx would you like pjax to send a X-PJAX header to the server so that the server can detect a pjax request?
MoOx commented 2016-01-05 01:19:33 -05:00 (Migrated from github.com)

Why not.

Why not.
BehindTheMath commented 2017-12-19 15:55:55 -05:00 (Migrated from github.com)

The X-PJAX header has been added by #80.

However, there is currently no implementation for checking a X-PJAX-URL header.

The X-PJAX header has been added by #80. However, there is currently no implementation for checking a X-PJAX-URL header.
BehindTheMath commented 2018-01-08 00:16:49 -05:00 (Migrated from github.com)

It looks like XMLHttpRequest.responseURL reflects the final URL after redirects. I see it's already being used in the tests.

Although it isn't supported by all browsers (most notably, IE), we should definitely check if it's available and use it if it is.

It looks like [XMLHttpRequest.responseURL](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseURL) reflects the final URL after redirects. I see it's already being used in [the tests](https://github.com/MoOx/pjax/blob/6491e3243787556664dc254dcc55b6af226b6786/tests/lib/request.js). Although it isn't supported by all browsers (most notably, IE), we should definitely check if it's available and use it if it is.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: iLoveElysia/pjax#7