Thanks to visit codestin.com
Credit goes to github.com

Skip to content

HTTP headers getting disappeared by edge functions (under certain edge cases) #48838

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

Closed
1 task done
ataibarkai opened this issue Apr 25, 2023 · 4 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js. stale The issue has not seen recent activity.

Comments

@ataibarkai
Copy link

ataibarkai commented Apr 25, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.1.0: Sun Oct  9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.8.0
      npm: 9.4.0
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.3.0
      eslint-config-next: 13.3.1
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

Middleware / Edge (API routes, runtime)

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/floral-cache-o8jqgq

To Reproduce

# /pages/api/example_head_response.tsx:

import { NextResponse } from "next/server";
import type { NextFetchEvent, NextRequest } from "next/server";

export const config = {
  runtime: "edge",
};

export default async function handler(
  req: NextRequest,
  context: NextFetchEvent
): Promise<NextResponse> {
  console.log("running!");
  return new NextResponse(null, {
    status: 200,
    headers: [
      ["Content-Length", "4242"],
      ["Content-Type", "audio/mpeg"]
    ],
  });
}

Describe the Bug

The 'Content-Length' header is explicitly stripped from the response, by this next/sandbox code snippet:
https://github.com/vercel/next.js/blob/canary/packages/next/src/server/web/sandbox/sandbox.ts#L108-L110

Usually, automatic setting of content-length is desirable (to automatically match the byte-size of the body field). However there are occasions when Content-Length should NOT match the body's content length in bytes.
One prominent example is in responses to HEAD requests, where only the headers should be returned, without a body.

This is commonplace when dealing with remote media files, e.g. MP3 files served over a URL -
where the initial response always includes the full file size in the Content-Length, with an empty body.
(Clients use this information to present the relevant UX, as well as to orchestrate subsequent requests to the remote server).

Expected Behavior

Headers explicitly set programmatically should be kept in place.

At the very least, there should be a mode that enforces this.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Vercel

@ataibarkai ataibarkai added the bug Issue was opened via the bug report template. label Apr 25, 2023
@github-actions github-actions bot added the Runtime Related to Node.js or Edge Runtime with Next.js. label Apr 25, 2023
@ataibarkai ataibarkai changed the title Impossible to implement a HEAD response in an edge function HTTP headers getting disappeared by edge functions (under certain edge cases) Apr 27, 2023
@ataibarkai
Copy link
Author

Bumping this.

Anything I can do to give this higher priority?

@charlyBerthet
Copy link

Same issue here, content-length header disappears from response

@nextjs-bot
Copy link
Collaborator

This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you.

@nextjs-bot nextjs-bot added the stale The issue has not seen recent activity. label Apr 24, 2025
@nextjs-bot
Copy link
Collaborator

This issue has been automatically closed due to two years of inactivity. If you’re still experiencing a similar problem or have additional details to share, please open a new issue following our current issue template. Your updated report helps us investigate and address concerns more efficiently. Thank you for your understanding!

@nextjs-bot nextjs-bot closed this as not planned Won't fix, can't repro, duplicate, stale May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js. stale The issue has not seen recent activity.
Projects
None yet
Development

No branches or pull requests

3 participants