{"version":3,"file":"http-exporter-transport.cjs","names":["sendWithHttp"],"sources":["../../../../src/platform/node/transport/http-exporter-transport.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// NOTE: do not change these type imports to actual imports. Doing so WILL break `@opentelemetry/instrumentation-http`,\n// as they'd be imported before the http/https modules can be wrapped.\nimport type * as https from 'https';\nimport type * as http from 'http';\nimport type { ExportResponse } from '../../../export-response';\nimport type { IExporterTransport } from '../../../exporter-transport';\nimport { sendWithHttp } from './http-transport-utils';\nimport type { NodeHttpRequestParameters } from './node-http-transport-types';\n\ninterface Utils {\n  agent: http.Agent | https.Agent;\n  request: typeof http.request | typeof https.request;\n}\n\nclass HttpExporterTransport implements IExporterTransport {\n  private _utils: Utils | null = null;\n  private _parameters: NodeHttpRequestParameters;\n\n  constructor(parameters: NodeHttpRequestParameters) {\n    this._parameters = parameters;\n  }\n\n  async send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {\n    const { agent, request } = await this._loadUtils();\n    const headers = await this._parameters.headers();\n\n    return sendWithHttp(\n      request,\n      this._parameters.url,\n      headers,\n      this._parameters.compression,\n      this._parameters.userAgent,\n      agent,\n      data,\n      timeoutMillis\n    );\n  }\n\n  shutdown() {\n    // intentionally left empty, nothing to do.\n  }\n\n  private async _loadUtils(): Promise<Utils> {\n    let utils = this._utils;\n\n    if (utils === null) {\n      const protocol = new URL(this._parameters.url).protocol;\n      const [agent, request] = await Promise.all([\n        this._parameters.agentFactory(protocol),\n        requestFunctionFactory(protocol),\n      ]);\n      utils = this._utils = { agent, request };\n    }\n\n    return utils;\n  }\n}\n\nasync function requestFunctionFactory(\n  protocol: string\n): Promise<typeof http.request | typeof https.request> {\n  const module = protocol === 'http:' ? import('http') : import('https');\n  const { request } = await module;\n  return request;\n}\n\nexport function createHttpExporterTransport(\n  parameters: NodeHttpRequestParameters\n): IExporterTransport {\n  return new HttpExporterTransport(parameters);\n}\n"],"mappings":";;AAmBA,IAAM,wBAAN,MAA0D;CACxD,SAA+B;CAC/B;CAEA,YAAY,YAAuC;EACjD,KAAK,cAAc;CACrB;CAEA,MAAM,KAAK,MAAkB,eAAgD;EAC3E,MAAM,EAAE,OAAO,YAAY,MAAM,KAAK,WAAW;EACjD,MAAM,UAAU,MAAM,KAAK,YAAY,QAAQ;EAE/C,OAAOA,6BAAAA,aACL,SACA,KAAK,YAAY,KACjB,SACA,KAAK,YAAY,aACjB,KAAK,YAAY,WACjB,OACA,MACA,aACF;CACF;CAEA,WAAW,CAEX;CAEA,MAAc,aAA6B;EACzC,IAAI,QAAQ,KAAK;EAEjB,IAAI,UAAU,MAAM;GAClB,MAAM,WAAW,IAAI,IAAI,KAAK,YAAY,GAAG,CAAC,CAAC;GAC/C,MAAM,CAAC,OAAO,WAAW,MAAM,QAAQ,IAAI,CACzC,KAAK,YAAY,aAAa,QAAQ,GACtC,uBAAuB,QAAQ,CACjC,CAAC;GACD,QAAQ,KAAK,SAAS;IAAE;IAAO;GAAQ;EACzC;EAEA,OAAO;CACT;AACF;AAEA,eAAe,uBACb,UACqD;CAErD,MAAM,EAAE,YAAY,OADL,aAAa,UAAU,OAAO,UAAU,OAAO;CAE9D,OAAO;AACT;AAEA,SAAgB,4BACd,YACoB;CACpB,OAAO,IAAI,sBAAsB,UAAU;AAC7C"}