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

allow Edge Functions to stream a compressed fetch response #39608

Commits on Aug 15, 2022

  1. allow Edge Functions to stream a compressed fetch response

    When a user tried to have the following Edge Function:
    
    ```ts
    export default () => fetch('https://example.vercel.sh')
    ```
    
    The Edge Function were failing.
    
    Why is that?
    
    When `fetch` was called, an implicit `Accept-Encoding` header was added
    to allow the origin to return a compressed response. Then, the origin
    will set the `Content-Encoding` header in the response, to let the
    client know that the body needs to be decompressed in order to be read.
    
    That creates an issue though: `response.body` will be a
    `ReadableStream<Uint8Array>`, or, a stream that contains binary data
    that decodes into _the uncompressed data_.
    
    What it means, is that `response.body` is uncompressed data, while
    `response.headers.get('content-encoding')` is marking the response body
    as compressed payload.
    
    This commit removes the `content-encoding`, `transfer-encoding` and
    `content-length` headers from the response, as the Next.js server _always_
    streams Edge Function responses.
    Schniz committed Aug 15, 2022
    Copy the full SHA
    5965a5f View commit details
    Browse the repository at this point in the history

Commits on Aug 21, 2022

  1. Copy the full SHA
    e6917af View commit details
    Browse the repository at this point in the history