ba5e7ce93ed0ca8850809cbf21a3de0c3a2c77d9d2fbc7648cbda611fd741f0301250c13d0d4638b344192370719d6c5365898e4d6fd1149fea2a43b4dd23c 1.7 KB

12345678910111213141516171819202122232425262728293031323334
  1. import CacheHandler from './cache-interceptor'
  2. import Dispatcher from './dispatcher'
  3. import RetryHandler from './retry-handler'
  4. import { LookupOptions } from 'node:dns'
  5. export default Interceptors
  6. declare namespace Interceptors {
  7. export type DumpInterceptorOpts = { maxSize?: number }
  8. export type RetryInterceptorOpts = RetryHandler.RetryOptions
  9. export type RedirectInterceptorOpts = { maxRedirections?: number }
  10. export type ResponseErrorInterceptorOpts = { throwOnError: boolean }
  11. export type CacheInterceptorOpts = CacheHandler.CacheOptions
  12. // DNS interceptor
  13. export type DNSInterceptorRecord = { address: string, ttl: number, family: 4 | 6 }
  14. export type DNSInterceptorOriginRecords = { 4: { ips: DNSInterceptorRecord[] } | null, 6: { ips: DNSInterceptorRecord[] } | null }
  15. export type DNSInterceptorOpts = {
  16. maxTTL?: number
  17. maxItems?: number
  18. lookup?: (hostname: string, options: LookupOptions, callback: (err: NodeJS.ErrnoException | null, addresses: DNSInterceptorRecord[]) => void) => void
  19. pick?: (origin: URL, records: DNSInterceptorOriginRecords, affinity: 4 | 6) => DNSInterceptorRecord
  20. dualStack?: boolean
  21. affinity?: 4 | 6
  22. }
  23. export function dump (opts?: DumpInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
  24. export function retry (opts?: RetryInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
  25. export function redirect (opts?: RedirectInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
  26. export function responseError (opts?: ResponseErrorInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
  27. export function dns (opts?: DNSInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
  28. export function cache (opts?: CacheInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
  29. }