/** Middleware for oak that allows back-to-back proxies of requests to be * used. * * @module */ import * as dntShim from "../_dnt.shims.js"; import type { State } from "../application.js"; import type { Context } from "../context.js"; import type { Middleware } from "../middleware.js"; import type { RouteParams, RouterContext } from "../router.js"; type Fetch = (input: dntShim.Request, init: { context: Context; }) => Promise; type ProxyMatchFunction = RouteParams, S extends State = Record> = (ctx: Context | RouterContext) => boolean; type ProxyMapFunction> = (path: R, params?: P) => R; type ProxyHeadersFunction = (ctx: Context) => dntShim.HeadersInit | Promise; type ProxyRouterHeadersFunction, S extends State> = (ctx: RouterContext) => dntShim.HeadersInit | Promise; /** Options which can be specified on the {@linkcode proxy} middleware. */ export interface ProxyOptions = RouteParams, S extends State = Record> { /** A callback hook that is called after the response is received which allows * the response content type to be adjusted. This is for situations where the * content type provided by the proxy server might not be suitable for * responding with. */ contentType?(url: string, contentType?: string): Promise | string | undefined; /** The fetch function to use to proxy the request. This defaults to the * global {@linkcode fetch} function. It will always be called with a * second argument which contains an object of `{ context }` which the * `context` property will be an instance of {@linkcode RouterContext}. * * This is designed for mocking purposes or implementing a `fetch()` * callback that needs access the current context when it is called. */ fetch?: Fetch; /** Additional headers that should be set in the response. The value can * be a headers init value or a function that returns or resolves with a * headers init value. */ headers?: dntShim.HeadersInit | ProxyHeadersFunction | ProxyRouterHeadersFunction; /** Either a record or a proxy map function that will allow proxied requests * being handled by the middleware to be remapped to a different remote * path. */ map?: Record | ProxyMapFunction; /** A string, regular expression or proxy match function what determines if * the proxy middleware should proxy the request. * * If the value is a string the match will be true if the requests pathname * starts with the string. In the case of a regular expression, if the * pathname */ match?: string | RegExp | ProxyMatchFunction; /** A flag that indicates if traditional proxy headers should be set in the * response. This defaults to `true`. */ proxyHeaders?: boolean; /** A callback hook which will be called before each proxied fetch request * to allow the native `Request` to be modified or replaced. */ request?(req: dntShim.Request): dntShim.Request | Promise; /** A callback hook which will be called after each proxied fetch response * is received to allow the native `Response` to be modified or replaced. */ response?(res: dntShim.Response): dntShim.Response | Promise; } /** * Middleware that provides a back-to-back proxy for requests. * * @param target * @param options */ export declare function proxy(target: string | URL, options?: ProxyOptions, S>): Middleware; export {};