import type { ClientRequest, IncomingMessage, ServerResponse } from 'node:http'; import type { Options } from 'http-proxy-middleware'; import type { ToolsLogger } from '@sap-ux/logger'; import { type Manifest } from '@sap-ux/project-access'; import type { RequestHandler, NextFunction, Request, Response } from 'express'; import type http from 'node:http'; import type { ProxyConfig } from './types.js'; import type { Url } from 'node:url'; import type { ReaderCollection } from '@ui5/fs'; import type { Socket } from 'node:net'; /** * Handler for the proxy response event. * Sets an Etag which will be used for re-validation of the cached UI5 sources. * * @param proxyRes - proxy response object * @param etag - ETag for the cached sources, normally the UI5 version */ export declare const proxyResponseHandler: (proxyRes: IncomingMessage, etag: string) => void; /** * Handler for the proxy request event. * Re-validates the cached UI5 sources based on the ETag. * Logs the requests made by the proxy. * * @param proxyReq - proxy request object * @param res - server response object * @param etag - Etag of the cached UI5 sources, normally the UI5 version */ export declare const proxyRequestHandler: (proxyReq: ClientRequest, res: ServerResponse, etag: string) => void; /** * Get user's proxy configuration. * * @param yamlProxyServer - proxy server config from yaml file * @returns User's proxy configuration or undefined */ export declare const getCorporateProxyServer: (yamlProxyServer: string | undefined) => string | undefined; /** * Hides the proxy credentials for displaying the proxy configuration in the console. * * @param proxy - user's proxy server * @returns proxy with hidden credentials for displaying in the console */ export declare const hideProxyCredentials: (proxy: string | undefined) => string | undefined; /** * Updates the proxy configuration with values from runtime args (highest priority), environment variables or given config value. * * @param proxyFromConfig - optional proxy string from configuration */ export declare function updateProxyEnv(proxyFromConfig?: string): void; /** * Returns the name of html file, which is used to preview the application, from the URL. * * @param url - html request url * @returns Name of the html file */ export declare const getHtmlFile: (url: string) => string; /** * Returns the name of the yaml file, which is used to for the server configuration, from the runtime arguments. * * @param args - runtime arguments * @returns Name of the YAML file */ export declare const getYamlFile: (args: string[]) => string; /** * Sends HTML content as a response. * Ensure compliance with common APIs in express and connect. * * @param res - The http response object * @param html - The HTML content */ export declare const sendResponse: (res: (Response | http.ServerResponse) & { _livereload?: boolean; }, html: string) => void; /** * Determines which UI5 version to use when previewing the application. * * @param version ui5 version as defined in the yaml or via cli argument * @param log logger for outputing information from where ui5 version config is coming * @param manifest optional already loaded manifest.json * @returns The UI5 version with which the application will be started */ export declare function resolveUI5Version(version?: string, log?: ToolsLogger, manifest?: Manifest): Promise; /** * Injects the absolute UI5 urls into the html file, which is used to preview the application. * * @param originalHtml - the content of the html file * @param ui5Configs - the configuration of the ui5-proxy-middleware * @returns The modified html file content */ export declare function injectUI5Url(originalHtml: string, ui5Configs: ProxyConfig[]): string; /** * Injects scripts into the html file, which is used to preview the application. * * @param req - the http request object * @param res - the http response object * @param next - the next function, used to forward the request to the next available handler * @param ui5Configs - the UI5 configuration of the ui5-proxy-middleware * @param rootProject - the root project * @param logger - logger to be used */ export declare const injectScripts: (req: Request, res: Response, next: NextFunction, ui5Configs: ProxyConfig[], rootProject: ReaderCollection, logger?: ToolsLogger) => Promise; /** * Filters comressed html files from UI5 CDN. * Avoid ERR_CONTENT_DECODING_FAILED on http request for gzip'd html files. * e.g. /test-resources/sap/ui/qunit/testrunner.html?testpage=%2Ftest%2Ftestsuite.qunit.html&autostart=true. * * @param _pathname - the request path * @param req - the http request object * @returns True, indicating that the request should be proxied */ export declare const filterCompressedHtmlFiles: (_pathname: string, req: IncomingMessage) => boolean; /** * Specifically handling errors due to undefined and empty errors. * * @param err the error thrown when proxying the request or processing the response * @param req request causing the error * @param logger logger instance * @param _res (not used) * @param _target (not used) */ export declare function proxyErrorHandler(err: Error & { code?: string; }, req: IncomingMessage & { next?: Function; originalUrl?: string; }, logger: ToolsLogger, _res?: ServerResponse | Socket, _target?: string | Partial): void; /** * Adjust UI5 bootstrap URLs to load directly from UI5 CDN. * * @param ui5Configs the UI5 configuration of the ui5-proxy-middleware * @param rootProject the project root * @param logger logger to be used when running the middleware * @returns RequestHandler to adjust bootstraps */ export declare function directLoadProxy(ui5Configs: ProxyConfig[], rootProject: ReaderCollection, logger: ToolsLogger): RequestHandler; /** * Create a rewrite based on the provided configuration. * This will either replace the configured path with the provided pathReplace value or * will prepend the UI5 version to the path. * It also ensures that the path from the http-proxy-middleware starts with the * config path in case of nested router instances. * * @param config proxy configuration * @param ui5Ver UI5 version string * @returns a path rewrite */ export declare function getPathRewrite(config: ProxyConfig, ui5Ver: string): Options['pathRewrite']; //# sourceMappingURL=utils.d.ts.map