Commit 5c6a20db authored by JJ Kasper's avatar JJ Kasper Committed by Joe Haddad

Add refresh header for 308 redirect for IE11 compatibility (#10042)

parent 243c0382
...@@ -485,17 +485,23 @@ export default class Server { ...@@ -485,17 +485,23 @@ export default class Server {
if (route.type === 'redirect') { if (route.type === 'redirect') {
const parsedNewUrl = parseUrl(newUrl) const parsedNewUrl = parseUrl(newUrl)
res.setHeader( const updatedDestination = formatUrl({
'Location', ...parsedDestination,
formatUrl({ pathname: parsedNewUrl.pathname,
...parsedDestination, hash: parsedNewUrl.hash,
pathname: parsedNewUrl.pathname, search: undefined,
hash: parsedNewUrl.hash, })
search: undefined,
}) res.setHeader('Location', updatedDestination)
)
res.statusCode = res.statusCode =
(route as Redirect).statusCode || DEFAULT_REDIRECT_STATUS (route as Redirect).statusCode || DEFAULT_REDIRECT_STATUS
// Since IE11 doesn't support the 308 header add backwards
// compatibility using refresh header
if (res.statusCode === 308) {
res.setHeader('Refresh', `0;url=${updatedDestination}`)
}
res.end() res.end()
return { return {
finished: true, finished: true,
......
...@@ -229,6 +229,14 @@ const runTests = (isDev = false) => { ...@@ -229,6 +229,14 @@ const runTests = (isDev = false) => {
expect(res.headers.get('x-second-header')).toBe('second') expect(res.headers.get('x-second-header')).toBe('second')
}) })
it('should add refresh header for 308 redirect', async () => {
const res = await fetchViaHTTP(appPort, '/redirect4', undefined, {
redirect: 'manual',
})
expect(res.status).toBe(308)
expect(res.headers.get('refresh')).toBe(`0;url=/`)
})
if (!isDev) { if (!isDev) {
it('should output routes-manifest successfully', async () => { it('should output routes-manifest successfully', async () => {
const manifest = await fs.readJSON( const manifest = await fs.readJSON(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment