import type net from 'node:net';
import { type Readable } from 'node:stream';
import type { Cookie, CookieJar, MemoryCookieStore } from 'tough-cookie';
import type { Encoding } from './file.ts';
import { inspect } from './utils.ts';
import { type BasicAuth, type BearerAuth } from './net.common.ts';
export * from './net.common.ts';
export declare enum MyProxy {
    socks5 = "http://127.0.0.1:10080",
    whistle = "http://localhost:8899",
    work = "http://localhost:10090",
    /** 需要先启动 server.start_tunnel_server('ddb.test.proxy') */
    test = "http://localhost:10091"
}
export declare const byproxy: {
    readonly proxy: true;
};
export declare const cookies: {
    store: MemoryCookieStore;
    jar: CookieJar;
    init(): Promise<void>;
};
export type { Cookie };
export interface RawResponse {
    status: number;
    headers: Record<string, string>;
    body: Readable;
}
export interface FullResponse<TBody extends Buffer | string> {
    status: number;
    headers: Record<string, string>;
    body: TBody;
}
export interface RequestOptions {
    method?: 'GET' | 'POST' | 'PUT' | 'HEAD' | 'DELETE' | 'PATCH';
    queries?: Record<string, any>;
    headers?: Record<string, string>;
    body?: string | Record<string, any> | Uint8Array | URLSearchParams | Readable;
    type?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data';
    proxy?: boolean | MyProxy | string;
    encoding?: Encoding | 'binary';
    retries?: true | number;
    timeout?: number;
    auth?: BasicAuth | BearerAuth;
    cookies?: Record<string, string>;
    redirect?: 'follow' | 'manual';
    decode?: boolean;
    print?: {
        retry: boolean;
        timeout: boolean;
    };
}
export interface RequestFullOptions extends RequestOptions {
    full: true;
}
export interface RequestRawOptions extends RequestOptions {
    raw: true;
}
export interface RequestError<TBody extends string | Buffer = string> extends Error {
    url: URL;
    options: RequestOptions | RequestFullOptions | RequestRawOptions;
    response?: FullResponse<TBody>;
    [inspect.custom]: Function;
}
export interface StatusCodeError {
    status: number;
}
export declare class StatusCodeError extends Error {
    name: "StatusCodeError";
    constructor(status: number, url: string);
}
/**
    - url: 必须是完整 url
    - options?:
        - method?: `有 body 时为 POST, 否则为 GET` 'GET' | 'POST' | ···
        - queries?: 添加到 url 上的参数，是 Record<string, any>，true/false 会被转换为 0/1
        - headers?: http 请求头，是 Record<string, string>，其中 key 必须是小写的
        - body?: http 请求体，可以是:
            - string
            - Uint8Array
            - Record<string, any>: 会自动 JSON.stringify
            - URLSearchParams: 仅限 type 为 x-www-form-urlencoded
            - Record<string, string | Blob | File> 自动转为 FormData: 仅限 type 为 form-data, 可以传 File 对象设置文件名
        - type?: `'application/json'` 有 body 时设置 http 请求头中的 content-type 头
        - proxy?: `false`  通过代理发送请求
            - 为 true 时使用 MyProxy.socks5
            - 为非空 string 作为代理地址
            - 为 falsy 值时设为 false
        - encoding?: `根据网页 content-type: charset=gb18030 提取 || 'utf-8'`  传入 'binary' 时返回 Buffer
             (只对非 raw 的请求起作用)
        - retries?: `false` 可以传入 true (默认 2 次) 或 重试次数
        - timeout?: `5 * 1000` 超时后会抛出 error.name 为 'TimeoutError' 的 error (但类型不是 utils.ts 中的 TimeoutError), 可以传入 0 来禁用超时
        - auth?: BasicAuth | BearerAuth
        - cookies?: 需要额外添加到请求的 cookies, 默认情况下携带了 MemoryCookieStore 中保存的之前 http 响应中的 cookies
        - raw?: `false` 传入后返回整个 response (RawResponse)，body 为 Readable
        - full?: `false` 传入后返回整个 response (FullResponse)，body 根据 encoding 对应为 string 或 Buffer
        - decode?: `true` 根据 content-encoding: br 等解码压缩后的 response.body
        - print?:
            - retry: `true` 是否打印 "等待 1 秒后重试 request" 提示信息
            - timeout: `true` 是否打印最后一次超时重试失败时的错误 */
export declare function request(url: string | URL): Promise<string>;
export declare function request(url: string | URL, options: RequestRawOptions): Promise<RawResponse>;
export declare function request(url: string | URL, options: RequestFullOptions & {
    encoding: 'binary';
}): Promise<FullResponse<Buffer>>;
export declare function request(url: string | URL, options: RequestFullOptions): Promise<FullResponse<string>>;
export declare function request(url: string | URL, options: RequestOptions & {
    encoding: 'binary';
}): Promise<Buffer>;
export declare function request(url: string | URL, options: RequestOptions): Promise<string>;
/** 发起 http 请求并将响应体作为 json 解析 */
export declare function request_json<T = any>(url: string | URL, options?: RequestOptions): Promise<T>;
export declare function get_socket_ip(socket: net.Socket): string;
