diff --git a/src/001-xml_http_request.coffee b/src/001-xml_http_request.coffee index 3e448b4..fd8d579 100644 --- a/src/001-xml_http_request.coffee +++ b/src/001-xml_http_request.coffee @@ -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']] diff --git a/test/src/helpers/xhr_server.coffee b/test/src/helpers/xhr_server.coffee index 5dcb0ea..4d273c9 100644 --- a/test/src/helpers/xhr_server.coffee +++ b/test/src/helpers/xhr_server.coffee @@ -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 = "
This is supposed to have a redirect link
" response.header 'Content-Type', 'text/html' response.header 'Content-Length', body.length.toString() diff --git a/test/src/redirect_test.coffee b/test/src/redirect_test.coffee index 854e642..390a67b 100644 --- a/test/src/redirect_test.coffee +++ b/test/src/redirect_test.coffee @@ -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'