-
-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [1502] Add the possibility to intercept sync requests
- Loading branch information
Showing
9 changed files
with
235 additions
and
72 deletions.
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
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
16 changes: 0 additions & 16 deletions
16
packages/happy-dom/src/fetch/types/IAsyncRequestInterceptor.ts
This file was deleted.
Oops, something went wrong.
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,60 @@ | ||
import Request from '../Request.js'; | ||
import BrowserWindow from '../../window/BrowserWindow.js'; | ||
import Response from '../Response.js'; | ||
import ISyncResponse from './ISyncResponse.js'; | ||
|
||
export default interface IFetchInterceptor { | ||
/** | ||
* Hook dispatched before making an async request. | ||
* It can be used for modifying the request, providing a response without making a request or for logging. | ||
* | ||
* @param context Contains the request and the window from where the request was made. | ||
* | ||
* @returns Promise that can resolve to a response to be used instead of sending out the response. | ||
*/ | ||
beforeAsyncRequest?: (context: { | ||
request: Request; | ||
window: BrowserWindow; | ||
}) => Promise<Response | void>; | ||
|
||
/** | ||
* Hook dispatched before making an sync request. | ||
* It can be used for modifying the request, providing a response without making a request or for logging. | ||
* | ||
* @param context Contains the request and the window from where the request was made. | ||
* | ||
* @returns Promise that can resolve to a response to be used instead of sending out the response. | ||
*/ | ||
beforeSyncRequest?: (context: { | ||
request: Request; | ||
window: BrowserWindow; | ||
}) => ISyncResponse | void; | ||
|
||
/** | ||
* Hook dispatched after receiving an async response. | ||
* It can be used for modifying or replacing the response and logging. | ||
* | ||
* @param context Contains the request, response and the window from where the request was made. | ||
* | ||
* @returns Promise that can resolve to a response to be used instead of sending out the response. | ||
*/ | ||
afterAsyncResponse?: (context: { | ||
request: Request; | ||
response: Response; | ||
window: BrowserWindow; | ||
}) => Promise<Response | void>; | ||
|
||
/** | ||
* Hook dispatched after receiving a sync response. | ||
* It can be used for modifying or replacing the response and logging | ||
* | ||
* @param context Contains the request, response and the window from where the request was made. | ||
* | ||
* @returns Promise that can resolve to a response to be used instead of sending out the response. | ||
*/ | ||
afterSyncResponse?: (context: { | ||
request: Request; | ||
response: Response; | ||
window: BrowserWindow; | ||
}) => Promise<Response | void>; | ||
} |
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
Oops, something went wrong.