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

Fix location url resolution. #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/001-xml_http_request.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ class XMLHttpRequest extends XMLHttpRequestEventTarget
# Transparent redirection handling.
switch response.statusCode
when 301, 302, 303, 307, 308
@_url = @_parseUrl response.headers['location']
@_url = @_parseUrl (url.resolve @_url['href'], response.headers['location'])
@_method = 'GET'
if 'content-type' of @_loweredHeaders
delete @_headers[@_loweredHeaders['content-type']]
Expand Down
7 changes: 5 additions & 2 deletions test/src/helpers/xhr_server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ class XhrServer
# Returns a HTTP redirect. Used to test the redirection handling code.
@app.all '/_/redirect/:status/:next_page', (request, response) =>
response.statusCode = parseInt(request.params.status)
response.header 'Location',
"http://#{request.get('host')}/_/#{request.params.next_page}"
if request.query.relative
url = "/#{request.params.next_page}"
else
url = "http://#{request.get('host')}/_/#{request.params.next_page}"
response.header 'Location', url
body = "<p>This is supposed to have a redirect link</p>"
response.header 'Content-Type', 'text/html'
response.header 'Content-Length', body.length.toString()
Expand Down
7 changes: 7 additions & 0 deletions test/src/redirect_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ describe 'XMLHttpRequest', ->
done()
@xhr.send()

it 'resolves effective request uri for the next location', (done) ->
@xhr.open 'GET', 'http://localhost:8912/_/redirect/302/method?relative=true'
@xhr.onload = =>
expect(@xhr._url['href']).to.match(/http:\/\/localhost:8912\/method/)
done()
@xhr.send()

it 'persists custom request headers across redirects', (done) ->
@xhr.open 'GET', 'http://localhost:8912/_/redirect/302/headers'
@xhr.setRequestHeader 'X-Redirect-Test', 'should be preserved'
Expand Down