/**
* Net - abstraction layer around Node's HTTP/S request system.
* Advantages:
* - easier acquiring of data
* - mass disabling of outgoing requests via Config.
*/
///
///
///
import * as https from 'https';
import * as http from 'http';
import * as Streams from './streams';
export interface PostData {
[key: string]: string | number;
}
export interface NetRequestOptions extends https.RequestOptions {
body?: string | PostData;
writable?: boolean;
query?: PostData;
}
export declare class HttpError extends Error {
statusCode?: number;
body: string;
constructor(message: string, statusCode: number | undefined, body: string);
}
export declare class NetStream extends Streams.ReadWriteStream {
opts: NetRequestOptions | null;
uri: string;
request: http.ClientRequest;
/** will be a Promise before the response is received, and the response itself after */
response: Promise | http.IncomingMessage | null;
statusCode: number | null;
/** response headers */
headers: http.IncomingHttpHeaders | null;
state: 'pending' | 'open' | 'timeout' | 'success' | 'error';
constructor(uri: string, opts?: NetRequestOptions | null);
makeRequest(opts: NetRequestOptions | null): http.ClientRequest;
static encodeQuery(data: PostData): string;
_write(data: string | Buffer): Promise | void;
_read(): void;
_pause(): void;
}
export declare class NetRequest {
uri: string;
constructor(uri: string);
/**
* Makes a http/https get request to the given link and returns a stream.
* The request data itself can be read with ReadStream#readAll().
* The NetStream class also holds headers and statusCode as a property.
*
* @param opts request opts - headers, etc.
* @param body POST body
*/
getStream(opts?: NetRequestOptions): NetStream;
/**
* Makes a basic http/https request to the URI.
* Returns the response data.
*
* Will throw if the response code isn't 200 OK.
*
* @param opts request opts - headers, etc.
*/
get(opts?: NetRequestOptions): Promise;
/**
* Makes a http/https POST request to the given link.
* @param opts request opts - headers, etc.
* @param body POST body
*/
post(opts: Omit, body: PostData | string): Promise;
/**
* Makes a http/https POST request to the given link.
* @param opts request opts - headers, etc.
*/
post(opts?: NetRequestOptions): Promise;
}
export declare const Net: ((path: string) => NetRequest) & {
NetRequest: typeof NetRequest;
NetStream: typeof NetStream;
};