adapters icon indicating copy to clipboard operation
adapters copied to clipboard

Astro middleware breaks Content-Encoding on netlify

Open docapi opened this issue 1 year ago • 0 comments

Astro Info

Astro                    v4.8.5
Node                     v20.11.0
System                   macOS (arm64)
Package Manager          npm
Output                   server
Adapter                  netlify
Integrations             astro-robots-txt
                         @astrojs/alpinejs
                         astro-compress

Describe the Bug

Netlify normally compresses pages with Brotli ("Content-Encoding : br"). If middleware (middleware.ts) is used, e.g. to set security headers, compression no longer works. Example for middleware.ts:

import { defineMiddleware } from "astro/middleware";

export const onRequest = defineMiddleware(async (context, next) => {
  const response = await next();

  response.headers.set("Referrer-Policy", "same-origin");

  return response;
});

What's the expected result?

Netlify continues to compress the pages

Link to Minimal Reproducible Example

This problem happen specifically on netlify so I cannot reproduce on stackblitz or others

Participation

  • [ ] I am willing to submit a pull request for this issue.

docapi avatar May 27 '24 10:05 docapi