@mojojs/core
Version:
Real-time web framework
106 lines (105 loc) • 3.62 kB
TypeScript
import type { UserAgentOptions, UserAgentRequestOptions, UserAgentWebSocketOptions } from './types.js';
import type { UserAgentResponse } from './user-agent/response.js';
import type { WebSocket } from './websocket.js';
import { URL } from 'node:url';
import { CookieJar } from './user-agent/cookie-jar.js';
import { HTTPTransport } from './user-agent/transport/http.js';
import { HTTPSTransport } from './user-agent/transport/https.js';
import { WSTransport } from './user-agent/transport/ws.js';
import { AsyncHooks } from '@mojojs/util';
import FormData from 'form-data';
interface Upload {
content: string;
filename: string;
type: string;
}
type UserAgentHook = (ua: UserAgent, ...args: any[]) => any;
/**
* HTTP and WebSocket user-agent.
*/
declare class UserAgent {
/**
* Base URL to be used to resolve all relative request URLs with.
*/
baseURL: string | URL | undefined;
/**
* Cookie jar to use.
*/
cookieJar: CookieJar | null;
/**
* User-agent hooks.
*/
hooks: AsyncHooks;
/**
* Transport backend to perform HTTP requests with.
*/
httpTransport: HTTPTransport;
/**
* Transport backend to perform HTTPS requests with.
*/
httpsTransport: HTTPSTransport;
/**
* Maximum number of redirects to follow, default to `0`.
*/
maxRedirects: number;
/**
* Name of user-agent to send with `User-Agent` header.
*/
name: string | undefined;
/**
* Transport backend to use for WebSocket connections.
*/
wsTransport: WSTransport;
constructor(options?: UserAgentOptions);
[Symbol.asyncDispose](): Promise<void>;
/**
* Add a hook to extend the user-agent.
*/
addHook(name: string, fn: UserAgentHook): this;
/**
* Destroy all active keep-alive connections.
*/
destroy(): Promise<void>;
/**
* Perform `DELETE` request.
*/
delete(url: string | URL, options: UserAgentRequestOptions): Promise<UserAgentResponse>;
/**
* Perform `GET` request.
*/
get(url: string | URL, options: UserAgentRequestOptions): Promise<UserAgentResponse>;
/**
* Perform `HEAD` request.
*/
head(url: string | URL, options: UserAgentRequestOptions): Promise<UserAgentResponse>;
/**
* Perform `OPTIONS` request.
*/
options(url: string | URL, options: UserAgentRequestOptions): Promise<UserAgentResponse>;
/**
* Perform `PATCH` request.
*/
patch(url: string | URL, options: UserAgentRequestOptions): Promise<UserAgentResponse>;
/**
* Perform `POST` request.
*/
post(url: string | URL, options: UserAgentRequestOptions): Promise<UserAgentResponse>;
/**
* Perform `PUT` request.
*/
put(url: string | URL, options: UserAgentRequestOptions): Promise<UserAgentResponse>;
/**
* Perform HTTP request.
*/
request(config: UserAgentRequestOptions): Promise<UserAgentResponse>;
/**
* Open WebSocket connection.
*/
websocket(url: string | URL, options?: UserAgentWebSocketOptions): Promise<WebSocket>;
_filterConfig(config: UserAgentRequestOptions): Promise<Record<string, any>>;
_filterSharedConfig(config: UserAgentRequestOptions | UserAgentWebSocketOptions): Promise<Record<string, any>>;
_formData(values?: Record<string, string | Upload>): FormData;
_handleRedirect(config: Record<string, any>, res: UserAgentResponse): Promise<UserAgentResponse>;
_requestConfig(method: string, url?: string | URL, options?: UserAgentRequestOptions): Promise<UserAgentResponse>;
}
export { UserAgent };