I have the above code in the Edge middleware, but when testing on the client side, I found that there was no Content-Length header. This shows that it was intentionally removed by the Edge middleware. I want to know whether this is the expected behavior or a bug.
What happens when you don’t set it explicitly? Can you try and share the finding?
If you need more help, please share your public repo or a minimal reproducible example. That will let us all work together from the same code to figure out what’s going wrong.
The reason I explicitly set the Content-Length header is that during my initial testing I found there was no Content-Length header, so I tried to set one manually, but I still found it missing.
What do you mean by “API routes”? I don’t quite understand. Does it have to use the Edge runtime? I’m using Edge middleware because only Edge middleware provides a sufficient quota.
Hi @fxzxmicah, I meant using Route Handlers. As far as the quota goes, you also get 1M Function Invocations when using Route Handlers in the Hobby plan. To learn more about the limits, see Vercel Hobby Plan.
So the conclusion is that Middleware removing Content-Length is expected behavior rather than a bug, right?
I tried Route Handlers, but I couldn’t get them deployed successfully—maybe my understanding of Next.js isn’t sufficient yet, so I’ll just keep using Middleware.
Also, I didn’t see anywhere stating that Route Handlers have 1M Function Invocations.
I just previously noticed that there was no Content-Length; it’s not that I absolutely need this header. Since it’s expected behavior, I think we can just leave it at that.
As for Route Handlers, they run fine locally, but once deployed to Vercel, accessing them only results in a 404. I think this is due to my insufficient understanding of Next.js, but I don’t feel like spending time learning it, so I’ll just leave this issue as it is for now.
Regarding invocations, did Vercel increase the quota for the Hobby plan? I remember that previously, when I was using either Edge Functions or Vercel Functions, I found the quota insufficient—it was only 500K—so I had no choice but to use Edge Middleware. Is it not recommended to run an API endpoint on Edge Middleware?
Hi @fxzxmicah, I understand. The quota and features keep updating. You can always refer to the page I shared for latest limits.
You can use Edge Middleware as you please. You can also run API routes on Edge runtime. That being said, here’s the official stance on choosing between the two:
We recommend migrating from edge to Node.js for improved performance and reliability. Both runtimes run on Fluid compute with Active CPU pricing.
This is done as an effort to pass down performance gains and cost cuts to the customers.