1 |
|
2 |
|
3 |
|
4 | import Module from './Module'
|
5 | import { httpReq as uninstrumentedHttpReq, httpReq2 as uninstrumentedHttpReq2 } from './uninstrumentedHttpUtils'
|
6 |
|
7 | import type { HttpReqOptions, HttpReqOptions2, HttpReqResponse } from './uninstrumentedHttpUtils'
|
8 |
|
9 | const { MODULE_NAME, log, warn, error, noteGauge, noteCount, trackOp } = new Module(__filename)
|
10 |
|
11 | export 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 |
|
17 | export 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 |
|
24 | export 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 |
|
29 | return Object.keys(obj).map(k => `${k}${keyValueSep}${encodeURIComponent(obj[k])}`).join(pairSep)
|
30 | } |
\ | No newline at end of file |