"use strict";
/* Socket Lib - Built with esbuild */
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var headers_exports = {};
__export(headers_exports, {
  parseRetryAfterHeader: () => parseRetryAfterHeader,
  sanitizeHeaders: () => sanitizeHeaders
});
module.exports = __toCommonJS(headers_exports);
var import_array = require("../primordials/array");
var import_date = require("../primordials/date");
var import_map_set = require("../primordials/map-set");
var import_number = require("../primordials/number");
var import_object = require("../primordials/object");
const RETRY_AFTER_INT_RE = /^\d+$/;
function parseRetryAfterHeader(value) {
  if (!value) {
    return void 0;
  }
  const raw = (0, import_array.ArrayIsArray)(value) ? value[0] : value;
  if (!raw) {
    return void 0;
  }
  const trimmed = raw.trim();
  if (RETRY_AFTER_INT_RE.test(trimmed)) {
    const seconds = Number(trimmed);
    return seconds * 1e3;
  }
  const date = new import_date.DateCtor(raw);
  if (!(0, import_number.NumberIsNaN)(date.getTime())) {
    const delayMs = date.getTime() - (0, import_date.DateNow)();
    if (delayMs > 0) {
      return delayMs;
    }
  }
  return void 0;
}
function sanitizeHeaders(headers) {
  if (!headers) {
    return {};
  }
  const sensitiveHeaders = new import_map_set.SetCtor([
    "authorization",
    "cookie",
    "proxy-authorization",
    "proxy-authenticate",
    "set-cookie",
    "www-authenticate"
  ]);
  const result = {
    __proto__: null
  };
  for (const key of (0, import_object.ObjectKeys)(headers)) {
    const value = headers[key];
    if (sensitiveHeaders.has(key.toLowerCase())) {
      result[key] = "[REDACTED]";
    } else if ((0, import_array.ArrayIsArray)(value)) {
      result[key] = value.join(", ");
    } else if (value !== void 0 && value !== null) {
      result[key] = String(value);
    }
  }
  return result;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  parseRetryAfterHeader,
  sanitizeHeaders
});
