-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(next): bind new stream functions with base incomingMessage object (…
…#37806) Closes: #37805 ## Bug - [x] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` Co-authored-by: JJ Kasper <[email protected]>
- Loading branch information
1 parent
7e3355d
commit d7e8370
Showing
5 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { NextResponse } from 'next/server' | ||
|
||
export async function middleware() { | ||
return NextResponse.next() | ||
} |
28 changes: 28 additions & 0 deletions
28
test/e2e/proxy-request-with-middleware/app/pages/api/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import request from 'request' | ||
|
||
export const config = { | ||
api: { | ||
bodyParser: false, | ||
}, | ||
} | ||
|
||
export default function handler(req, res) { | ||
return req | ||
.pipe( | ||
request( | ||
`http://${ | ||
// node v18 resolves to IPv6 by default so force IPv4 | ||
process.version.startsWith('v18.') | ||
? `127.0.0.1:${req.headers.host.split(':').pop() || ''}` | ||
: req.headers.host | ||
}${req.url}/post`, | ||
{ | ||
followAllRedirects: false, | ||
followRedirect: false, | ||
gzip: true, | ||
json: false, | ||
} | ||
) | ||
) | ||
.pipe(res) | ||
} |
12 changes: 12 additions & 0 deletions
12
test/e2e/proxy-request-with-middleware/app/pages/api/post.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const config = { | ||
api: { | ||
bodyParser: false, | ||
}, | ||
} | ||
|
||
export default function handler(req, res) { | ||
return res.json({ | ||
method: req.method, | ||
headers: req.headers, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* eslint-env jest */ | ||
|
||
import { join } from 'path' | ||
import { fetchViaHTTP } from 'next-test-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { createNext, FileRef } from 'e2e-utils' | ||
|
||
describe('Requests not effected when middleware used', () => { | ||
let next: NextInstance | ||
|
||
afterAll(() => next.destroy()) | ||
beforeAll(async () => { | ||
next = await createNext({ | ||
files: { | ||
pages: new FileRef(join(__dirname, '../app/pages')), | ||
'middleware.js': new FileRef(join(__dirname, '../app/middleware.js')), | ||
}, | ||
dependencies: { | ||
request: '^2.88.2', | ||
}, | ||
}) | ||
}) | ||
|
||
sendRequest('GET') | ||
sendRequest('POST') | ||
|
||
function sendRequest(method) { | ||
const body = !['get', 'head'].includes(method.toLowerCase()) | ||
? JSON.stringify({ | ||
key: 'value', | ||
}) | ||
: undefined | ||
it(`should proxy ${method} request ${ | ||
body ? 'with body' : '' | ||
}`, async () => { | ||
const headers = { | ||
'content-type': 'application/json', | ||
'x-custom-header': 'some value', | ||
} | ||
const res = await fetchViaHTTP(next.url, `api`, '', { | ||
method: method.toUpperCase(), | ||
headers, | ||
body: method.toLowerCase() !== 'get' ? body : undefined, | ||
}) | ||
const data = await res.json() | ||
expect(data.method).toEqual(method) | ||
if (body) { | ||
expect(data.headers['content-length']).toEqual(String(body.length)) | ||
} | ||
expect(data.headers).toEqual(expect.objectContaining(headers)) | ||
}) | ||
} | ||
}) |
d7e8370
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stats from current release
Default Build (Increase detected⚠️ )
General Overall decrease ✓
Page Load Tests Overall decrease⚠️
Client Bundles (main, webpack) Overall increase⚠️
Legacy Client Bundles (polyfills) Overall increase⚠️
Client Pages Overall decrease ✓
Client Build Manifests Overall increase⚠️
Rendered Page Sizes Overall decrease ✓
Middleware size Overall increase⚠️
Diffs
Diff for edge-runtime-webpack.js
Diff for middleware-manifest.json
Diff for middleware.js
Diff too large to display
Diff for _buildManifest.js
Diff for _app-HASH.js
Diff for _error-HASH.js
Diff for amp-HASH.js
Diff for css-HASH.js
Diff for dynamic-HASH.js
Diff for head-HASH.js
Diff for hooks-HASH.js
Diff for image-HASH.js
Diff too large to display
Diff for index-HASH.js
Diff for link-HASH.js
Diff for routerDirect-HASH.js
Diff for script-HASH.js
Diff for withRouter-HASH.js
Diff for 437.HASH.js
Diff for framework-HASH.js
Diff for main-HASH.js
Diff too large to display
Diff for polyfills-HASH.js
Diff too large to display
Diff for webpack-HASH.js
Diff for index.html
Diff for link.html
Diff for withRouter.html
Default Build with SWC (Increase detected⚠️ )
General Overall decrease ✓
Page Load Tests Overall decrease⚠️
Client Bundles (main, webpack) Overall increase⚠️
Legacy Client Bundles (polyfills) Overall increase⚠️
Client Pages Overall decrease ✓
Client Build Manifests Overall increase⚠️
Rendered Page Sizes Overall decrease ✓
Middleware size Overall increase⚠️
Diffs
Diff for edge-runtime-webpack.js
Diff for middleware-manifest.json
Diff for middleware.js
Diff too large to display
Diff for _buildManifest.js
Diff for _app-HASH.js
Diff for _error-HASH.js
Diff for amp-HASH.js
Diff for css-HASH.js
Diff for dynamic-HASH.js
Diff for head-HASH.js
Diff for hooks-HASH.js
Diff for image-HASH.js
Diff too large to display
Diff for index-HASH.js
Diff for link-HASH.js
Diff for routerDirect-HASH.js
Diff for script-HASH.js
Diff for withRouter-HASH.js
Diff for 437.HASH.js
Diff for framework-HASH.js
Diff for main-HASH.js
Diff too large to display
Diff for polyfills-HASH.js
Diff too large to display
Diff for webpack-HASH.js
Diff for index.html
Diff for link.html
Diff for withRouter.html