diff --git a/package-lock.json b/package-lock.json index ff363e5..b70510f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tarantoolscript", - "version": "0.9.1", + "version": "0.10.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "tarantoolscript", - "version": "0.9.1", + "version": "0.10.0", "license": "MIT", "dependencies": { "@typescript-to-lua/language-extensions": "^1.19.0", diff --git a/package.json b/package.json index a3bb57a..5b5d329 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tarantoolscript", - "version": "0.9.1", + "version": "0.10.0", "author": "Vitaliy Artemov olivera507224@yandex.ru", "description": "TypeScript definitions for Tarantool Lua API.", "repository": { diff --git a/src/builtin/http.client/Client.d.ts b/src/builtin/http.client/Client.d.ts new file mode 100644 index 0000000..3bb3a10 --- /dev/null +++ b/src/builtin/http.client/Client.d.ts @@ -0,0 +1,229 @@ +import { ClientStat } from './ClientStat'; +import { HttpMethod } from './HttpMethod'; +import { IoObject } from './IoObject'; +import { RequestOptions } from './RequestOptions'; +import { ResponseObject } from './ResponseObject'; + +export interface Client { + /** + * Make an HTTP request and receive a response. + * @param method A request HTTP method. Possible values: `GET`, `POST`, `PUT`, `PATCH`, `OPTIONS`, `HEAD`, `DELETE`, `TRACE`, `CONNECT`. + * @param url A request URL, for example, `https://httpbin.org/get`. + * @param body A request body. + * @param opts Request options. + * @returns This method returns one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + request(method: HttpMethod, url: string, body?: string, opts: RequestOptions & { chunked: true }): IoObject; + + /** + * Make an HTTP request and receive a response. + * @param method A request HTTP method. Possible values: `GET`, `POST`, `PUT`, `PATCH`, `OPTIONS`, `HEAD`, `DELETE`, `TRACE`, `CONNECT`. + * @param url A request URL, for example, `https://httpbin.org/get`. + * @param body A request body. + * @param opts Request options. + * @returns This method returns one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + request(method: HttpMethod, url: string, body?: string, opts?: RequestOptions): ResponseObject; + + /** + * Make a `GET` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/get`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + get(url: string, opts: RequestOptions & { chunked: true }): IoObject; + + /** + * Make a `GET` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/get`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + get(url: string, opts?: RequestOptions): ResponseObject; + + /** + * Make a `POST` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/post`. + * @param body A request body. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + post(url: string, body?: AnyTable, opts: RequestOptions & { chunked: true }): IoObject; + + /** + * Make a `POST` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/post`. + * @param body A request body. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + post(url: string, body?: AnyTable, opts?: RequestOptions): ResponseObject; + + /** + * Make a `PUT` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/put`. + * @param body A request body. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + put(url: string, body?: AnyTable, opts: RequestOptions & { chunked: true }): IoObject; + + /** + * Make a `PUT` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/put`. + * @param body A request body. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + put(url: string, body?: AnyTable, opts?: RequestOptions): ResponseObject; + + /** + * Make a `PATCH` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/patch`. + * @param body A request body. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + patch(url: string, body?: AnyTable, opts: RequestOptions & { chunked: true }): IoObject; + + /** + * Make a `PATCH` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/patch`. + * @param body A request body. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + patch(url: string, body?: AnyTable, opts?: RequestOptions): ResponseObject; + + /** + * Make a `DELETE` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/delete`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + delete(url: string, opts: RequestOptions & { chunked: true }): IoObject; + + /** + * Make a `DELETE` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/delete`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + delete(url: string, opts?: RequestOptions): ResponseObject; + + /** + * Make a `HEAD` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/head`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + head(url: string, opts: RequestOptions & { chunked: true }): IoObject; + + /** + * Make a `HEAD` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/head`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + head(url: string, opts?: RequestOptions): ResponseObject; + + /** + * Make a `OPTIONS` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/options`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + options(url: string, opts: RequestOptions & { chunked: true }): IoObject; + + /** + * Make a `OPTIONS` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/options`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + options(url: string, opts?: RequestOptions): ResponseObject; + + /** + * Make a `TRACE` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/trace`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + trace(url: string, opts: RequestOptions & { chunked: true }): IoObject; + + /** + * Make a `TRACE` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/trace`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + trace(url: string, opts?: RequestOptions): ResponseObject; + + /** + * Make a `CONNECT` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/connect`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + connect(url: string, opts: RequestOptions & { chunked: true }): IoObject; + + /** + * Make a `CONNECT` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/connect`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ + connect(url: string, opts?: RequestOptions): ResponseObject; + + /** + * Get a table with statistics for the HTTP client. + */ + stat(): ClientStat; + + /** + * Since: `2.11.0`. + * + * Decoders used to deserialize response data based on the `Content-Type` header value. + */ + decoders: { [ key: string ]: (this: void) => (body: string, _content_type: unknown) => unknown }; +} diff --git a/src/builtin/http.client/ClientOptions.d.ts b/src/builtin/http.client/ClientOptions.d.ts new file mode 100644 index 0000000..a7b96cd --- /dev/null +++ b/src/builtin/http.client/ClientOptions.d.ts @@ -0,0 +1,11 @@ +export interface ClientOptions { + /** + * Specifies the maximum number of entries in the cache. This option affects libcurl `CURLMOPT_MAXCONNECTS`. The default is `-1`. + */ + max_connections?: number; + + /** + * Specifies the maximum number of active connections. This option affects libcurl `CURLMOPT_MAX_TOTAL_CONNECTIONS`. + */ + max_total_connections?: number; +} diff --git a/src/builtin/http.client/ClientStat.d.ts b/src/builtin/http.client/ClientStat.d.ts new file mode 100644 index 0000000..4d351d0 --- /dev/null +++ b/src/builtin/http.client/ClientStat.d.ts @@ -0,0 +1,36 @@ +export interface ClientStat { + /** + * The number of currently executing requests. + */ + active_requests: number; + + /** + * The total number of sockets added into an event loop. + */ + sockets_added: number; + + /** + * The total number of sockets deleted from an event loop. + */ + sockets_deleted: number; + + /** + * The total number of requests. + */ + total_requests: number; + + /** + * The total number of requests that returned HTTP `200 OK` responses. + */ + http_200_responses: number; + + /** + * The total number of requests that returned non-`200 OK` responses. + */ + http_other_responses: number; + + /** + * The total number of failed requests, including system, curl, and HTTP errors. + */ + failed_requests: number; +} diff --git a/src/builtin/http.client/HttpClient.d.ts b/src/builtin/http.client/HttpClient.d.ts new file mode 100644 index 0000000..617c0a0 --- /dev/null +++ b/src/builtin/http.client/HttpClient.d.ts @@ -0,0 +1,240 @@ +/** @noSelfInFile */ + +import { Client } from './Client'; +import { ClientOptions } from './ClientOptions'; +import { ClientStat } from './ClientStat'; +import { HttpMethod } from './HttpMethod'; +import { IoObject } from './IoObject'; +import { ResponseObject } from './ResponseObject'; + +/** + * Create an HTTP client instance. + * @param options Configuration options of the client. + * @return A new HTTP client instance + * @customName new + */ +export declare function new_(options?: ClientOptions): Client + +/** + * Make an HTTP request and receive a response. + * @param method A request HTTP method. Possible values: `GET`, `POST`, `PUT`, `PATCH`, `OPTIONS`, `HEAD`, `DELETE`, `TRACE`, `CONNECT`. + * @param url A request URL, for example, `https://httpbin.org/get`. + * @param body A request body. + * @param opts Request options. + * @returns This method returns one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function request(method: HttpMethod, url: string, body?: string, opts: RequestOptions & { chunked: true }): IoObject; + +/** + * Make an HTTP request and receive a response. + * @param method A request HTTP method. Possible values: `GET`, `POST`, `PUT`, `PATCH`, `OPTIONS`, `HEAD`, `DELETE`, `TRACE`, `CONNECT`. + * @param url A request URL, for example, `https://httpbin.org/get`. + * @param body A request body. + * @param opts Request options. + * @returns This method returns one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function request(method: HttpMethod, url: string, body?: string, opts?: RequestOptions): ResponseObject; + +/** + * Make a `GET` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/get`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function get(url: string, opts: RequestOptions & { chunked: true }): IoObject; + +/** + * Make a `GET` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/get`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function get(url: string, opts?: RequestOptions): ResponseObject; + +/** + * Make a `POST` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/post`. + * @param body A request body. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function post(url: string, body?: AnyTable, opts: RequestOptions & { chunked: true }): IoObject; + +/** + * Make a `POST` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/post`. + * @param body A request body. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function post(url: string, body?: AnyTable, opts?: RequestOptions): ResponseObject; + +/** + * Make a `PUT` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/put`. + * @param body A request body. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function put(url: string, body?: AnyTable, opts: RequestOptions & { chunked: true }): IoObject; + +/** + * Make a `PUT` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/put`. + * @param body A request body. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function put(url: string, body?: AnyTable, opts?: RequestOptions): ResponseObject; + +/** + * Make a `PATCH` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/patch`. + * @param body A request body. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function patch(url: string, body?: AnyTable, opts: RequestOptions & { chunked: true }): IoObject; + +/** + * Make a `PATCH` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/patch`. + * @param body A request body. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function patch(url: string, body?: AnyTable, opts?: RequestOptions): ResponseObject; + +/** + * Make a `DELETE` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/delete`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + * @customName delete + */ +export declare function delete_(url: string, opts: RequestOptions & { chunked: true }): IoObject; + +/** + * Make a `DELETE` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/delete`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + * @customName delete + */ +export declare function delete_(url: string, opts?: RequestOptions): ResponseObject; + +/** + * Make a `HEAD` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/head`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function head(url: string, opts: RequestOptions & { chunked: true }): IoObject; + +/** + * Make a `HEAD` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/head`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function head(url: string, opts?: RequestOptions): ResponseObject; + +/** + * Make a `OPTIONS` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/options`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function options(url: string, opts: RequestOptions & { chunked: true }): IoObject; + +/** + * Make a `OPTIONS` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/options`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function options(url: string, opts?: RequestOptions): ResponseObject; + +/** + * Make a `TRACE` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/trace`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function trace(url: string, opts: RequestOptions & { chunked: true }): IoObject; + +/** + * Make a `TRACE` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/trace`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function trace(url: string, opts?: RequestOptions): ResponseObject; + +/** + * Make a `CONNECT` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/connect`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function connect(url: string, opts: RequestOptions & { chunked: true }): IoObject; + +/** + * Make a `CONNECT` request and receive a response. + * @param url A request URL, for example, `https://httpbin.org/connect`. + * @param opts Request options. + * @returns This method might return one of the following objects: + * - `response_object`; + * - `io_object` if `request_options.chunked` is set to `true`. + */ +export declare function connect(url: string, opts?: RequestOptions): ResponseObject; + +/** + * Get a table with statistics for the HTTP client. + */ +export declare function stat(): ClientStat; + +/** + * Since: `2.11.0`. + * + * Decoders used to deserialize response data based on the `Content-Type` header value. + */ +export declare let decoders: { [ key: string ]: (this: void) => (body: string, _content_type: unknown) => unknown }; diff --git a/src/builtin/http.client/HttpMethod.d.ts b/src/builtin/http.client/HttpMethod.d.ts new file mode 100644 index 0000000..f3ac02a --- /dev/null +++ b/src/builtin/http.client/HttpMethod.d.ts @@ -0,0 +1,10 @@ +export type HttpMethod = + | 'GET' + | 'POST' + | 'PUT' + | 'PATCH' + | 'OPTIONS' + | 'HEAD' + | 'DELETE' + | 'TRACE' + | 'CONNECT' diff --git a/src/builtin/http.client/IoObject.d.ts b/src/builtin/http.client/IoObject.d.ts new file mode 100644 index 0000000..a20305e --- /dev/null +++ b/src/builtin/http.client/IoObject.d.ts @@ -0,0 +1,32 @@ +export interface IoObject { + /** + * Since: `2.11.0`. + * + * Read request data in chunks of a specified length or up to a specific delimiter. + * + * An IO object used to read or write data in chunks. + * To get an IO object instead of the full response (`response_object`), you need to set the `chunked` request option to `true`. + * @param chunk The maximum number of bytes to read. + * @param delimiter The delimiter used to stop reading data. + * @param timeout The number of seconds to wait. The default is `10`. + * @returns A chunk of read data. Returns an empty string if there is nothing more to read. + */ + read: { + (chunk: number, timeout?: number): string; + (delimiter: string, timeout?: number): string; + (chunk: number, delimiter: string, timeout?: number): string; + } + + /** + * Write the specified chunk of data. + * @param data Data to be written. + * @param timeout The number of seconds to wait. The default is `10`. + */ + write(data: AnyTable | unknown, timeout?: number): void; + + /** + * Finish reading or writing data. + * @param timeout The number of seconds to wait. The default is `10`. + */ + finish(timeout?: number): void; +} diff --git a/src/builtin/http.client/RequestOptions.d.ts b/src/builtin/http.client/RequestOptions.d.ts new file mode 100644 index 0000000..256896d --- /dev/null +++ b/src/builtin/http.client/RequestOptions.d.ts @@ -0,0 +1,146 @@ +export interface RequestOptions { + /** + * The path to an SSL certificate file to verify the peer with. + */ + ca_file?: string; + + /** + * The path to a directory holding one or more certificates to verify the peer with. + */ + ca_path?: string; + + /** + * Since: `2.11.0`. + * + * Specifies whether an HTTP client should return the full response (`response_object`) + * or an IO object (`io_object`) used for streaming download/upload. + */ + chunked?: boolean; + + /** + * A table of HTTP headers passed to a request. + */ + headers?: AnyTable; + + /** + * Since: `2.11.0`. + * + * A table of parameters passed to a request. The behavior of this option depends on the request type, for example: + * - For a `GET` request, this option specifies query string parameters. + * - For a `POST` request, this option specifies form parameters to be sent using the `application/x-www-form-urlencoded` type. + */ + params?: AnyTable; + + /** + * A delay (in seconds) the operating system waits while the connection is idle before sending keepalive probes. + */ + keepalive_idle?: number; + + /** + * The interval (in seconds) the operating system waits between sending keepalive probes. + * If both `keepalive_idle` and `keepalive_interval` are set, then Tarantool also sets the HTTP keepalive headers: + * `Connection:Keep-Alive` and `Keep-Alive:timeout=`. Otherwise, Tarantool sends `Connection:close`. + */ + keepalive_interval?: number; + + /** + * The average transfer speed in bytes per second that the transfer should be below during “low speed time” seconds + * for the library to consider it to be too slow and abort. + */ + low_speed_limit?: number; + + /** + * The time that the transfer speed should be below the “low speed limit” for the library to consider it too slow and abort. + */ + low_speed_time?: number; + + /** + * The maximum length of a header name. If a header name length exceeds this value, it is truncated to this length. The default value is `32`. + */ + max_header_name_len?: number; + + /** + * Specify whether the HTTP client follows redirect URLs provided in the `Location` header for `3xx` responses. + * When a non-`3xx` response is received, the client returns it as a result. + * If you set this option to `false`, the client returns the first `3xx` response. + */ + follow_location?: boolean; + + /** + * A comma-separated list of hosts that do not require proxies, or *, or ''. * + * - Set `no_proxy = host [, host ...]` to specify hosts that can be reached without requiring a proxy, + * even if `proxy` is set to a non-blank value and/or if a proxy-related environment variable has been set. + * - Set `no_proxy = '*'` to specify that all hosts can be reached without requiring a proxy, which is equivalent to setting `proxy=''`. + * - Set `no_proxy = ''` to specify that no hosts can be reached without requiring a proxy, + * even if a proxy-related environment variable (`HTTP_PROXY`) is used. + * + * If `no_proxy` is not set, then a proxy-related environment variable (`HTTP_PROXY`) may be used. + */ + no_proxy?: string; + + /** + * A proxy server host or IP address, or `''`. + * - If `proxy` is a host or IP address, then it may begin with a scheme, for example, `https://` for an HTTPS proxy or `http://` for an HTTP proxy. + * - If `proxy` is set to `''` an empty string, then proxy use is disabled, and no proxy-related environment variable is used. + * - If `proxy` is not set, then a proxy-related environment variable may be used, + * such as `HTTP_PROXY` or `HTTPS_PROXY` or `FTP_PROXY`, or `ALL_PROXY` if the protocol can be any protocol. + */ + proxy?: string; + + /** + * A proxy server port. The default is `443` for an HTTPS proxy and `1080` for a non-HTTPS proxy. + */ + proxy_port?: number; + + /** + * A proxy server username and password. This option might have one of the following formats: + * - `proxy_user_pwd = user_name:`; + * - `proxy_user_pwd = :password`; + * - `proxy_user_pwd = user_name:password`. + */ + proxy_user_pwd?: string; + + /** + * A path to an SSL client certificate file. + */ + ssl_cert?: string; + + /** + * A path to a private key file for a TLS and SSL client certificate. + */ + ssl_key?: string; + + /** + * The number of seconds to wait for a curl API read request before timing out. The default timeout is set to infinity (`36586400100` seconds). + */ + timeout?: number; + + /** + * A socket name to use instead of an Internet address for a local connection. + * @example `/tmp/unix_domain_socket.sock` + */ + unix_socket?: string; + + /** + * Turn on/off a verbose mode. + */ + verbose?: boolean; + + /** + * Enable verification of the certificate’s name (CN) against the specified host. + */ + verify_host?: number; + + /** + * Set on/off verification of the peer’s SSL certificate. + */ + verify_peer?: number; + + /** + * Enable decompression of an HTTP response data based on the specified `Accept-Encoding` request header. + * You can pass the following values to this option: + * - `''` – if an empty string is passed, the `Accept-Encoding` contains all the supported encodings (`identity`, `deflate`, `gzip`, and `br`). + * - `br`, `gzip`, `deflate` – a comma-separated list of encodings passed in Accept-Encoding. + */ + accept_encoding?: string; +} diff --git a/src/builtin/http.client/ResponseObject.d.ts b/src/builtin/http.client/ResponseObject.d.ts new file mode 100644 index 0000000..28d20b7 --- /dev/null +++ b/src/builtin/http.client/ResponseObject.d.ts @@ -0,0 +1,40 @@ +export interface ResponseObject { + /** + * A response status code. + */ + status?: number; + + /** + * A response status text. + */ + reason?: string; + + /** + * Response headers. + */ + headers?: AnyTable; + + /** + * Response cookies. + * The value is an array of two elements where the first one is the cookie value and the second one is an array with the cookie’s options. + */ + cookies?: { [key: string]: string[] }; + + /** + * A response body. Use decode to decode the response body. + */ + body?: string; + + /** + * An HTTP protocol version. + */ + proto?: string; + + /** + * Since: `2.11.0`. + * + * Decode the response body to a Lua object based on the content type. + * @returns A decoded body. + */ + decode(): AnyTable?; +} diff --git a/src/builtin/http.client/index.d.ts b/src/builtin/http.client/index.d.ts new file mode 100644 index 0000000..7e4afd3 --- /dev/null +++ b/src/builtin/http.client/index.d.ts @@ -0,0 +1,7 @@ +export * from './Client'; +export * from './ClientOptions'; +export * from './ClientStat'; +export * from './HttpMethod'; +export * from './IoObject'; +export * from './RequestOptions'; +export * from './ResponseObject'; diff --git a/src/builtin/index.d.ts b/src/builtin/index.d.ts index af46064..77f4535 100644 --- a/src/builtin/index.d.ts +++ b/src/builtin/index.d.ts @@ -9,7 +9,6 @@ /** @todo errno https://www.tarantool.io/en/doc/latest/reference/reference_lua/errno/ */ /** @todo fio https://www.tarantool.io/en/doc/latest/reference/reference_lua/fio/ */ /** @todo fun https://www.tarantool.io/en/doc/latest/reference/reference_lua/fun/ */ -/** @todo http https://www.tarantool.io/en/doc/latest/reference/reference_lua/http/ */ /** @todo iconv https://www.tarantool.io/en/doc/latest/reference/reference_lua/iconv/ */ /** @todo jit https://www.tarantool.io/en/doc/latest/reference/reference_lua/jit/ */ /** @todo json https://www.tarantool.io/en/doc/latest/reference/reference_lua/json/ */ @@ -37,6 +36,7 @@ export * from './box'; export * from './buffer'; export * from './csv'; export * from './fiber'; +export * from './http.client'; export * from './log'; export * from './msgpack'; export * from './package'; diff --git a/src/http.client.d.ts b/src/http.client.d.ts new file mode 100644 index 0000000..1fae0f4 --- /dev/null +++ b/src/http.client.d.ts @@ -0,0 +1 @@ +export * from './builtin/http.client/HttpClient';