UNPKG

1.32 kBJavaScriptView Raw
1// @flow
2
3
4import Module from './Module'
5import { httpReq as uninstrumentedHttpReq, httpReq2 as uninstrumentedHttpReq2 } from './uninstrumentedHttpUtils'
6
7import type { HttpReqOptions, HttpReqOptions2, HttpReqResponse } from './uninstrumentedHttpUtils'
8
9const { MODULE_NAME, log, warn, error, noteGauge, noteCount, trackOp } = new Module(__filename) // eslint-disable-line no-unused-vars
10
11export async function httpReq(url: string, options: HttpReqOptions = {}): Promise<HttpReqResponse> {
12 return await trackOp(async () => {
13 return await uninstrumentedHttpReq(url, options)
14 }, options && options.trackingName ? `httpReq.${options.trackingName}` : null)
15}
16
17export async function httpReq2(url: string, options: HttpReqOptions2 = {}): Promise<HttpReqResponse> {
18 return await trackOp(async () => {
19 return await uninstrumentedHttpReq2(url, options)
20 }, options && options.trackingName ? `httpReq.${options.trackingName}` : null)
21}
22
23// TODO: move to stringUtils
24export function objToQuery(obj: ?Object, pairSep: ?string, keyValueSep: ?string): string {
25 obj = obj || {}
26 pairSep = typeof pairSep === 'string' ? pairSep : '&'
27 keyValueSep = typeof keyValueSep === 'string' ? keyValueSep : '='
28 // $FlowIgnore
29 return Object.keys(obj).map(k => `${k}${keyValueSep}${encodeURIComponent(obj[k])}`).join(pairSep)
30}
\No newline at end of file