api.d.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { URL, UrlObject } from 'url'
  2. import { Duplex } from 'stream'
  3. import Dispatcher from './dispatcher'
  4. export {
  5. request,
  6. stream,
  7. pipeline,
  8. connect,
  9. upgrade,
  10. }
  11. /** Performs an HTTP request. */
  12. declare function request(
  13. url: string | URL | UrlObject,
  14. options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.RequestOptions, 'origin' | 'path' | 'method'> & Partial<Pick<Dispatcher.RequestOptions, 'method'>>,
  15. ): Promise<Dispatcher.ResponseData>;
  16. /** A faster version of `request`. */
  17. declare function stream(
  18. url: string | URL | UrlObject,
  19. options: { dispatcher?: Dispatcher } & Omit<Dispatcher.RequestOptions, 'origin' | 'path'>,
  20. factory: Dispatcher.StreamFactory
  21. ): Promise<Dispatcher.StreamData>;
  22. /** For easy use with `stream.pipeline`. */
  23. declare function pipeline(
  24. url: string | URL | UrlObject,
  25. options: { dispatcher?: Dispatcher } & Omit<Dispatcher.PipelineOptions, 'origin' | 'path'>,
  26. handler: Dispatcher.PipelineHandler
  27. ): Duplex;
  28. /** Starts two-way communications with the requested resource. */
  29. declare function connect(
  30. url: string | URL | UrlObject,
  31. options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.ConnectOptions, 'origin' | 'path'>
  32. ): Promise<Dispatcher.ConnectData>;
  33. /** Upgrade to a different protocol. */
  34. declare function upgrade(
  35. url: string | URL | UrlObject,
  36. options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.UpgradeOptions, 'origin' | 'path'>
  37. ): Promise<Dispatcher.UpgradeData>;