Repository: next.js
Issue: Edge functions on Vercel can’t remove query params in redirect
Labels: Runtime

### Verify canary release

- [X] 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 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000
    Binaries:
      Node: 16.14.0
      npm: 8.13.2
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 12.2.4-canary.1
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
```

### What browser are you using? (if relevant)

_No response_

### How are you deploying your application? (if relevant)

Vercel

### Describe the Bug

When returning a `Location` header from an API route using the `experimental-edge` runtime (i.e. when performing a redirect), all of the request’s query parameters are copied into the Location header. This breaks the URL I’m trying to redirect to (the extra query parameters cause the target server to return 400).

This behavior appears only on Vercel; in the `next dev` environment and in the local `vercel dev` environment, the behavior is as expected.

Compare the following two responses (from the attached reproduction):
**Local:**
```
❯ curl -v http://localhost:3000/api/test\?param\=300
*   Trying 127.0.0.1:3000...
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET /api/test?param=300 HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.79.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
< location: https://example.com/
< x-location: https://example.com/
< Date: Tue, 26 Jul 2022 05:27:04 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< Transfer-Encoding: chunked
<
```
**Vercel:**
```
❯ curl -v https://edge-functions-redirect-bug.vercel.app/api/test\?param\=300
*   Trying 76.76.21.98:443...
* Connected to edge-functions-redirect-bug.vercel.app (76.76.21.98) port 443 (#0)
> GET /api/test?param=300 HTTP/2
> Host: edge-functions-redirect-bug.vercel.app
> user-agent: curl/7.79.1
> accept: */*
>
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 301
< date: Tue, 26 Jul 2022 05:27:25 GMT
< location: https://example.com/?param=
< x-matched-path: /api/test
< x-location: https://example.com/
< server: Vercel
< x-vercel-id: iad1::kdvlb-1658813245773-457425c503b4
< strict-transport-security: max-age=63072000; includeSubDomains; preload
< cache-control: public, max-age=0, must-revalidate
< x-vercel-cache: MISS
<
```

Note that in the first case (local), `location` matches `x-location`, whereas in the second case (production on Vercel), the `location` header (incorrectly) reads `https://example.com/?param=` while the `x-location` header (correctly) reads `https://example.com/`. Vercel is modifying the `location` header to add a query parameter. The additional parameter completely breaks the redirect in my case.

### Expected Behavior

I expected the Location header to be returned unmodified, just as the `x-location` header is.

### Link to reproduction

https://github.com/controversial/edge-functions-redirect-bug

### To Reproduce

1. Run locally
2. Deploy to Vercel
3. `curl -v http://localhost:3000/api/test\?param\=300`
4. `curl -v https://my-deployment.vercel.app/api/test\?param\=300`

Observe the incorrect location header returned in response to the request from step 4.