(
req: { url?: string; headers: IncomingHttpHeaders },
transforms: Transform[]
)
| 56 | |
| 57 | /** Apply request-side transforms. */ |
| 58 | export function applyRequestTransforms( |
| 59 | req: { url?: string; headers: IncomingHttpHeaders }, |
| 60 | transforms: Transform[] |
| 61 | ): void { |
| 62 | if (transforms.length === 0) { |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | applyRequestHeaderTransforms(req.headers, transforms); |
| 67 | |
| 68 | const parsed = url.parse(req.url || '/'); |
| 69 | const query = parseQueryString(parsed.search); |
| 70 | applyQueryTransforms(query, transforms); |
| 71 | |
| 72 | const newPath = getRequestPath(transforms); |
| 73 | if (newPath !== undefined) { |
| 74 | parsed.pathname = newPath; |
| 75 | } |
| 76 | parsed.search = formatQueryString(query); |
| 77 | req.url = url.format(parsed); |
| 78 | } |
| 79 | |
| 80 | /** Whether any transform rules to be applied for responses. */ |
| 81 | export function hasResponseTransforms(transforms: Transform[]): boolean { |
no test coverage detected