-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: code-split of the long (interceptor.ts) file into smaller pieces
- Loading branch information
1 parent
0075114
commit b5528cc
Showing
9 changed files
with
359 additions
and
324 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import http from 'http'; | ||
import https from 'https'; | ||
|
||
import { InterceptorContext } from './interceptorTypesAndUtils'; | ||
import { overloadHttpRequest } from './overloadHttpRequest'; | ||
import { overloadWebsocketHandshake } from './overloadWebsocketHandshake'; | ||
|
||
export const interceptHttp = (context: InterceptorContext) => { | ||
const originalHttpRequest = http.request; | ||
|
||
http.request = (...args) => { | ||
const overload = overloadHttpRequest(context, 'http', ...args); | ||
if (overload) { | ||
const [identity, ...overloadedArgs] = overload; | ||
|
||
return context.requestPool(originalHttpRequest(...overloadedArgs), identity); | ||
} | ||
|
||
// In cases that are not considered above we pass the args as they came. | ||
return originalHttpRequest(...(args as Parameters<typeof http.request>)); | ||
}; | ||
|
||
const originalHttpGet = http.get; | ||
|
||
http.get = (...args) => { | ||
const overload = overloadWebsocketHandshake(context, 'http', ...args); | ||
if (overload) { | ||
const [identity, ...overloadedArgs] = overload; | ||
|
||
return context.requestPool(originalHttpGet(...overloadedArgs), identity); | ||
} | ||
|
||
return originalHttpGet(...(args as Parameters<typeof https.get>)); | ||
}; | ||
}; |
Oops, something went wrong.