UNPKG

pluto-http-client

Version:

HTTP client for NodeJS. Inspired in the Java JAX-RS spec so you can expect excellence, versatility and extensibility.

73 lines (72 loc) 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ClientBuilder = void 0; const client_1 = require("./client"); const header_1 = require("./header"); const collections_1 = require("../utils/collections"); const time_unit_1 = require("../utils/time-unit"); class ClientBuilder { constructor() { this._http2 = false; this._filters = new collections_1.TreeMultiValueMap(new collections_1.NumberComparator()); this._headers = new collections_1.MultiValueMap(); this._allowInsecure = false; } setAllowInsecure(allow) { this._allowInsecure = allow; return this; } withAgent(agent) { this._agent = agent; return this; } withTimeout(timeout, timeUnit = time_unit_1.TimeUnit.Milliseconds) { this._timeout = timeout * timeUnit; return this; } withHeader(name, value) { this.headers.add(new header_1.Header(name, value)); return this; } withFilter(filter) { this.filters.put(filter.order(), filter); return this; } withHttp2() { this._http2 = true; const builder = new Http2ClientBuilder(); builder._timeout = this._timeout; builder._allowInsecure = this._allowInsecure; builder._filters = this._filters; builder._headers = this._headers; return builder; } get timeout() { return this._timeout; } get headers() { return this._headers; } get filters() { return this._filters; } header(key, value) { this._headers.add(new header_1.Header(key, value)); return this; } get allowInsecure() { return this._allowInsecure; } get agent() { return this._agent; } build() { return new client_1.Client(this.headers, this.filters, this._allowInsecure, this.timeout, this._agent); } } exports.ClientBuilder = ClientBuilder; class Http2ClientBuilder extends ClientBuilder { build() { return new client_1.Http2Client(this.headers, this.filters, this.allowInsecure, this.timeout); } }