UNPKG

sync-request-curl

Version:

Fast way to send synchronous web requests in NodeJS. API is a subset of sync-request. Leverages node-libcurl for high performance. Cannot be used in a browser.

55 lines (54 loc) 2.23 kB
import { IncomingHttpHeaders } from 'http'; import { CurlCode } from 'node-libcurl'; import { HttpVerb, Options } from './types'; interface RequestInputs { method: HttpVerb; url: string; options: Options; } /** * Handles query string parameters in a URL by modifying or appending them * based on the provided object. * * Arrays of primitives, e.g. { quizIds: [1,2,3] }, will be of the form: * https://google.com.au/?quizIds%5B0%5D=0&quizIds%5B1%5D=1&quizIds%5B2%5D=2 * i.e. https://www.google.com.au/?quizIds[0]=0&quizIds[1]=1&quizIds[2]=2 * * @param {string} url - The URL to handle query string parameters for. * @param {Object.<string, any>} qs - query string parameters to modify or append. * @returns {string} The modified URL with the updated query string parameters. */ export declare const handleQs: (url: string, qs: { [key: string]: any; }) => string; /** * Parses incoming HTTP headers to an array of formatted strings. * * @param {IncomingHttpHeaders} headers - The header object to parse. * @returns {string[]} An array of formatted header strings. */ export declare const parseIncomingHeaders: (headers?: IncomingHttpHeaders) => string[]; /** * Parses an array of header lines as IncomingHttpHeaders. * * @param {string[]} headerLines - An array of header lines to parse. * @returns {IncomingHttpHeaders} An object containing parsed headers. */ export declare const parseReturnedHeaders: (headerLines: string[]) => IncomingHttpHeaders; /** * Checks CURL code and throws a `CurlError` if it indicates failure. * * @param {CurlCode} code - The CURL error code to check. * @param {RequestInputs} requestInputs - input parameters for the CURL request. * @throws {CurlError} Throws a `CurlError` if the CURL code indicates failure. */ export declare const checkValidCurlCode: (code: CurlCode, requestInputs: RequestInputs) => void; /** * Checks the status code and body of an HTTP response * * @param {number} statusCode - The status code of the HTTP response. * @param {Buffer} body - The body of the HTTP response. * @throws {Error} if the status code is >= 300. */ export declare const checkValidStatusCode: (statusCode: number, body: Buffer) => void; export {};