Commit b9e81396 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: alter headers on cached response (#4032)

* fix: alter headers on cached response

* test: deflake
parent c82dcabd
describe('Swap', () => {
beforeEach(() => {
cy.visit('/swap')
cy.visit('/swap').get('#swap-currency-input .token-amount-input')
})
it('starts with ETH selected by default', () => {
......
......@@ -98,12 +98,14 @@ export class CachedDocument extends Response {
static async from(response: Response) {
const text = await response.text()
// Some browsers (Android 12; Chrome 91) duplicate the content-type header, invalidating it.
response.headers.set('Content-Type', 'text/html; charset=utf-8')
// Set the content-type explicitly. Some browsers (Android 12; Chrome 91) use an invalid content-type header.
const headers = new Headers(response.headers)
headers.set('Content-Type', 'text/html; charset=utf-8')
const init = { ...response, headers }
// Injects a marker into the document so that client code knows it was served from cache.
// The marker should be injected immediately in the <body> so it is available to client code.
return new CachedDocument(text.replace('<body>', '<body><script>window.__isDocumentCached=true</script>'), response)
return new CachedDocument(text.replace('<body>', '<body><script>window.__isDocumentCached=true</script>'), init)
}
private constructor(text: string, response: Response) {
......
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