fix: prevent Hono from overriding global Response object (v1.x) (#1411)
This commit is contained in:
parent
12ae856cee
commit
6e8f7e1a43
1 changed files with 122 additions and 19 deletions
|
|
@ -78,14 +78,19 @@ export class StreamableHTTPServerTransport implements Transport {
|
|||
|
||||
// Create a request listener that wraps the web standard transport
|
||||
// getRequestListener converts Node.js HTTP to Web Standard and properly handles SSE streaming
|
||||
this._requestListener = getRequestListener(async (webRequest: Request) => {
|
||||
// Get context if available (set during handleRequest)
|
||||
const context = this._requestContext.get(webRequest);
|
||||
return this._webStandardTransport.handleRequest(webRequest, {
|
||||
authInfo: context?.authInfo,
|
||||
parsedBody: context?.parsedBody
|
||||
});
|
||||
});
|
||||
// overrideGlobalObjects: false prevents Hono from overwriting global Response, which would
|
||||
// break frameworks like Next.js whose response classes extend the native Response
|
||||
this._requestListener = getRequestListener(
|
||||
async (webRequest: Request) => {
|
||||
// Get context if available (set during handleRequest)
|
||||
const context = this._requestContext.get(webRequest);
|
||||
return this._webStandardTransport.handleRequest(webRequest, {
|
||||
authInfo: context?.authInfo,
|
||||
parsedBody: context?.parsedBody
|
||||
});
|
||||
},
|
||||
{ overrideGlobalObjects: false }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -166,12 +171,17 @@ export class StreamableHTTPServerTransport implements Transport {
|
|||
const authInfo = req.auth;
|
||||
|
||||
// Create a custom handler that includes our context
|
||||
const handler = getRequestListener(async (webRequest: Request) => {
|
||||
return this._webStandardTransport.handleRequest(webRequest, {
|
||||
authInfo,
|
||||
parsedBody
|
||||
});
|
||||
});
|
||||
// overrideGlobalObjects: false prevents Hono from overwriting global Response, which would
|
||||
// break frameworks like Next.js whose response classes extend the native Response
|
||||
const handler = getRequestListener(
|
||||
async (webRequest: Request) => {
|
||||
return this._webStandardTransport.handleRequest(webRequest, {
|
||||
authInfo,
|
||||
parsedBody
|
||||
});
|
||||
},
|
||||
{ overrideGlobalObjects: false }
|
||||
);
|
||||
|
||||
// Delegate to the request listener which handles all the Node.js <-> Web Standard conversion
|
||||
// including proper SSE streaming support
|
||||
|
|
|
|||
Loading…
Reference in a new issue