@datadog/mobile-react-native 3.11.0 → 3.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/android/build.gradle +14 -5
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
- package/datadog-configuration.gradle +59 -18
- package/datadog-configuration.schema.json +119 -0
- package/ios/Sources/SdkVersion.swift +1 -1
- package/lib/commonjs/DdSdkReactNative.js +6 -1
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/config/FileBasedConfiguration.js +2 -0
- package/lib/commonjs/config/FileBasedConfiguration.js.map +1 -1
- package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js +2 -1
- package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js.map +1 -1
- package/lib/commonjs/config/features/RumConfiguration.js +4 -0
- package/lib/commonjs/config/features/RumConfiguration.js.map +1 -1
- package/lib/commonjs/flags/DdFlags.js +4 -2
- package/lib/commonjs/flags/DdFlags.js.map +1 -1
- package/lib/commonjs/flags/FlagsClient.js +4 -2
- package/lib/commonjs/flags/FlagsClient.js.map +1 -1
- package/lib/commonjs/internal.js +97 -0
- package/lib/commonjs/internal.js.map +1 -0
- package/lib/commonjs/logs/DdLogs.js +4 -2
- package/lib/commonjs/logs/DdLogs.js.map +1 -1
- package/lib/commonjs/rum/DdRum.js +4 -2
- package/lib/commonjs/rum/DdRum.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -15
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
- package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +2 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +308 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +275 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +167 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +36 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +158 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +58 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +39 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +38 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +17 -2
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +25 -3
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +2 -35
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +3 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +88 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
- package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
- package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
- package/lib/commonjs/sdk/DdSdkInternal.js +27 -22
- package/lib/commonjs/sdk/DdSdkInternal.js.map +1 -1
- package/lib/commonjs/specs/NativeDdFlags.js +19 -3
- package/lib/commonjs/specs/NativeDdFlags.js.map +1 -1
- package/lib/commonjs/specs/NativeDdLogs.js +19 -3
- package/lib/commonjs/specs/NativeDdLogs.js.map +1 -1
- package/lib/commonjs/specs/NativeDdRum.js +19 -3
- package/lib/commonjs/specs/NativeDdRum.js.map +1 -1
- package/lib/commonjs/specs/NativeDdSdk.js +19 -3
- package/lib/commonjs/specs/NativeDdSdk.js.map +1 -1
- package/lib/commonjs/specs/NativeDdTrace.js +19 -3
- package/lib/commonjs/specs/NativeDdTrace.js.map +1 -1
- package/lib/commonjs/trace/DdTrace.js +4 -2
- package/lib/commonjs/trace/DdTrace.js.map +1 -1
- package/lib/commonjs/utils/stringUtils.js +48 -0
- package/lib/commonjs/utils/stringUtils.js.map +1 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/module/DdSdkReactNative.js +6 -1
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/config/FileBasedConfiguration.js +2 -0
- package/lib/module/config/FileBasedConfiguration.js.map +1 -1
- package/lib/module/config/async/AutoInstrumentationConfiguration.js +2 -1
- package/lib/module/config/async/AutoInstrumentationConfiguration.js.map +1 -1
- package/lib/module/config/features/RumConfiguration.js +4 -0
- package/lib/module/config/features/RumConfiguration.js.map +1 -1
- package/lib/module/flags/DdFlags.js +4 -2
- package/lib/module/flags/DdFlags.js.map +1 -1
- package/lib/module/flags/FlagsClient.js +5 -2
- package/lib/module/flags/FlagsClient.js.map +1 -1
- package/lib/module/internal.js +27 -0
- package/lib/module/internal.js.map +1 -0
- package/lib/module/logs/DdLogs.js +4 -2
- package/lib/module/logs/DdLogs.js.map +1 -1
- package/lib/module/rum/DdRum.js +4 -2
- package/lib/module/rum/DdRum.js.map +1 -1
- package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -14
- package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
- package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +298 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +268 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +160 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +30 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +150 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +51 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +32 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +32 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +17 -2
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +25 -3
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +1 -34
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +3 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +79 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
- package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
- package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
- package/lib/module/sdk/DdSdkInternal.js +27 -22
- package/lib/module/sdk/DdSdkInternal.js.map +1 -1
- package/lib/module/specs/NativeDdFlags.js +14 -2
- package/lib/module/specs/NativeDdFlags.js.map +1 -1
- package/lib/module/specs/NativeDdLogs.js +14 -2
- package/lib/module/specs/NativeDdLogs.js.map +1 -1
- package/lib/module/specs/NativeDdRum.js +14 -2
- package/lib/module/specs/NativeDdRum.js.map +1 -1
- package/lib/module/specs/NativeDdSdk.js +14 -2
- package/lib/module/specs/NativeDdSdk.js.map +1 -1
- package/lib/module/specs/NativeDdTrace.js +14 -2
- package/lib/module/specs/NativeDdTrace.js.map +1 -1
- package/lib/module/trace/DdTrace.js +4 -2
- package/lib/module/trace/DdTrace.js.map +1 -1
- package/lib/module/utils/stringUtils.js +42 -0
- package/lib/module/utils/stringUtils.js.map +1 -0
- package/lib/module/version.js +1 -1
- package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
- package/lib/typescript/config/FileBasedConfiguration.d.ts.map +1 -1
- package/lib/typescript/config/FileBasedConfiguration.type.d.ts +2 -0
- package/lib/typescript/config/FileBasedConfiguration.type.d.ts.map +1 -1
- package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts +3 -0
- package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts.map +1 -1
- package/lib/typescript/config/features/RumConfiguration.d.ts +3 -1
- package/lib/typescript/config/features/RumConfiguration.d.ts.map +1 -1
- package/lib/typescript/config/features/RumConfiguration.type.d.ts +107 -0
- package/lib/typescript/config/features/RumConfiguration.type.d.ts.map +1 -1
- package/lib/typescript/flags/DdFlags.d.ts.map +1 -1
- package/lib/typescript/flags/FlagsClient.d.ts +1 -1
- package/lib/typescript/flags/FlagsClient.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/internal.d.ts +26 -0
- package/lib/typescript/internal.d.ts.map +1 -0
- package/lib/typescript/logs/DdLogs.d.ts +1 -1
- package/lib/typescript/logs/DdLogs.d.ts.map +1 -1
- package/lib/typescript/rum/DdRum.d.ts +1 -1
- package/lib/typescript/rum/DdRum.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +3 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts +85 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts +18 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts +24 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts +12 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts +28 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts +16 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts +13 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts +13 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts +27 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts +2 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts +43 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts +2 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts +2 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts.map +1 -1
- package/lib/typescript/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.d.ts.map +1 -1
- package/lib/typescript/sdk/DdSdkInternal.d.ts +1 -0
- package/lib/typescript/sdk/DdSdkInternal.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdFlags.d.ts +7 -2
- package/lib/typescript/specs/NativeDdFlags.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdLogs.d.ts +7 -2
- package/lib/typescript/specs/NativeDdLogs.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdRum.d.ts +7 -2
- package/lib/typescript/specs/NativeDdRum.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdSdk.d.ts +7 -2
- package/lib/typescript/specs/NativeDdSdk.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdTrace.d.ts +7 -2
- package/lib/typescript/specs/NativeDdTrace.d.ts.map +1 -1
- package/lib/typescript/trace/DdTrace.d.ts.map +1 -1
- package/lib/typescript/utils/stringUtils.d.ts +12 -0
- package/lib/typescript/utils/stringUtils.d.ts.map +1 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +7 -2
- package/src/DdSdkReactNative.tsx +11 -1
- package/src/__tests__/DdSdkReactNative.test.tsx +145 -20
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +3 -0
- package/src/__tests__/internalEntry.test.ts +26 -0
- package/src/__tests__/mock.test.ts +1 -3
- package/src/__tests__/nativeSpecGetters.test.ts +102 -0
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +3 -3
- package/src/__tests__/wrapperImportSafety.test.ts +129 -0
- package/src/config/FileBasedConfiguration.ts +3 -0
- package/src/config/FileBasedConfiguration.type.ts +2 -0
- package/src/config/__tests__/FileBasedConfiguration.test.ts +66 -0
- package/src/config/__tests__/__fixtures__/configuration-all-fields.json +8 -0
- package/src/config/async/AutoInstrumentationConfiguration.ts +5 -1
- package/src/config/features/RumConfiguration.ts +9 -0
- package/src/config/features/RumConfiguration.type.ts +117 -0
- package/src/flags/DdFlags.ts +4 -3
- package/src/flags/FlagsClient.ts +4 -3
- package/src/index.tsx +7 -0
- package/src/internal.ts +32 -0
- package/src/logs/DdLogs.ts +4 -3
- package/src/rum/DdRum.ts +4 -3
- package/src/rum/__tests__/DdRum.test.ts +4 -4
- package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +33 -26
- package/src/rum/instrumentation/interactionTracking/__tests__/BabelOptionalHandlers.test.ts +120 -0
- package/src/rum/instrumentation/interactionTracking/__tests__/DdBabelInteractionTracking.test.ts +82 -2
- package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +7 -2
- package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +46 -0
- package/src/rum/instrumentation/resourceTracking/__tests__/__utils__/XMLHttpRequestMock.ts +1 -1
- package/src/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.ts +1 -1
- package/src/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/captureHeaders.test.ts +853 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/compileHeaderConfig.test.ts +697 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.integration.test.ts +183 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.test.ts +337 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/isHeaderAllowed.test.ts +35 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/normalizeUrlForMatching.test.ts +176 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/parseResponseHeaders.test.ts +114 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/sensitiveHeaderBlocklist.test.ts +112 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/tracingHeaderExclusion.test.ts +59 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.ts +437 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.ts +339 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.ts +208 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.ts +29 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.ts +181 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.ts +59 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.ts +31 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.ts +61 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/types.ts +33 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.ts +21 -2
- package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/__tests__/FetchProxy.test.ts +274 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/__tests__/ResourceReporter.test.ts +120 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +34 -3
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +624 -2
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.ts +1 -34
- package/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.ts +6 -1
- package/src/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.ts +16 -2
- package/src/rum/instrumentation/resourceTracking/requestProxy/common/__tests__/headerCapture.test.ts +164 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.ts +119 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.ts +2 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.ts +2 -0
- package/src/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.tsx +3 -4
- package/src/sdk/DatadogInternalBridge/__tests__/DdSdkNativeBridge.test.tsx +35 -2
- package/src/sdk/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +5 -5
- package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +2 -1
- package/src/sdk/DdSdkInternal.ts +27 -24
- package/src/sdk/EventMappers/__tests__/EventMapper.test.ts +2 -2
- package/src/specs/NativeDdFlags.ts +14 -2
- package/src/specs/NativeDdLogs.ts +14 -2
- package/src/specs/NativeDdRum.ts +14 -2
- package/src/specs/NativeDdSdk.ts +14 -2
- package/src/specs/NativeDdTrace.ts +14 -2
- package/src/trace/DdTrace.ts +4 -3
- package/src/utils/__tests__/stringUtils.test.ts +90 -0
- package/src/utils/stringUtils.ts +41 -0
- package/src/version.ts +1 -1
package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/captureHeaders.test.ts
ADDED
|
@@ -0,0 +1,853 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
DEFAULT_RESPONSE_HEADERS,
|
|
9
|
+
DEFAULT_REQUEST_HEADERS,
|
|
10
|
+
CANONICAL_RESPONSE_HEADERS,
|
|
11
|
+
CANONICAL_REQUEST_HEADERS,
|
|
12
|
+
accumulateRequestHeader,
|
|
13
|
+
captureResponseHeaders,
|
|
14
|
+
filterRequestHeadersByMode
|
|
15
|
+
} from '../captureHeaders';
|
|
16
|
+
import { compileHeaderCaptureConfig } from '../compileHeaderConfig';
|
|
17
|
+
import type { CompiledHeaderCaptureConfig } from '../types';
|
|
18
|
+
|
|
19
|
+
describe('captureHeaders', () => {
|
|
20
|
+
describe('DEFAULT_RESPONSE_HEADERS', () => {
|
|
21
|
+
it('contains exactly 10 header names', () => {
|
|
22
|
+
expect(DEFAULT_RESPONSE_HEADERS.size).toBe(10);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it.each([
|
|
26
|
+
'cache-control',
|
|
27
|
+
'etag',
|
|
28
|
+
'age',
|
|
29
|
+
'expires',
|
|
30
|
+
'content-type',
|
|
31
|
+
'content-encoding',
|
|
32
|
+
'content-length',
|
|
33
|
+
'vary',
|
|
34
|
+
'server-timing',
|
|
35
|
+
'x-cache'
|
|
36
|
+
])('contains %s', header => {
|
|
37
|
+
expect(DEFAULT_RESPONSE_HEADERS.has(header)).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('DEFAULT_REQUEST_HEADERS', () => {
|
|
42
|
+
it('contains exactly 2 header names', () => {
|
|
43
|
+
expect(DEFAULT_REQUEST_HEADERS.size).toBe(2);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it.each(['cache-control', 'content-type'])('contains %s', header => {
|
|
47
|
+
expect(DEFAULT_REQUEST_HEADERS.has(header)).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('accumulateRequestHeader', () => {
|
|
52
|
+
it('stores an allowed header with original casing', () => {
|
|
53
|
+
const acc: Record<string, string> = {};
|
|
54
|
+
accumulateRequestHeader(acc, 'Content-Type', 'application/json');
|
|
55
|
+
expect(acc).toEqual({ 'Content-Type': 'application/json' });
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('blocks sensitive headers (authorization)', () => {
|
|
59
|
+
const acc: Record<string, string> = {};
|
|
60
|
+
accumulateRequestHeader(acc, 'Authorization', 'Bearer xyz');
|
|
61
|
+
expect(acc).toEqual({});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('blocks tracing headers (x-datadog-trace-id)', () => {
|
|
65
|
+
const acc: Record<string, string> = {};
|
|
66
|
+
accumulateRequestHeader(acc, 'x-datadog-trace-id', '123');
|
|
67
|
+
expect(acc).toEqual({});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('uses last-value-wins for duplicate header names', () => {
|
|
71
|
+
const acc: Record<string, string> = {};
|
|
72
|
+
accumulateRequestHeader(acc, 'Content-Type', 'application/json');
|
|
73
|
+
accumulateRequestHeader(acc, 'Content-Type', 'text/html');
|
|
74
|
+
expect(acc).toEqual({ 'Content-Type': 'text/html' });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('preserves custom header casing', () => {
|
|
78
|
+
const acc: Record<string, string> = {};
|
|
79
|
+
accumulateRequestHeader(acc, 'X-Custom', 'val');
|
|
80
|
+
expect(acc).toEqual({ 'X-Custom': 'val' });
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('accumulates multiple allowed headers', () => {
|
|
84
|
+
const acc: Record<string, string> = {};
|
|
85
|
+
accumulateRequestHeader(acc, 'Content-Type', 'application/json');
|
|
86
|
+
accumulateRequestHeader(acc, 'Accept', 'text/html');
|
|
87
|
+
expect(acc).toEqual({
|
|
88
|
+
'Content-Type': 'application/json',
|
|
89
|
+
Accept: 'text/html'
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('preserves original setRequestHeader casing in accumulator key', () => {
|
|
94
|
+
const acc: Record<string, string> = {};
|
|
95
|
+
accumulateRequestHeader(acc, 'Content-Type', 'application/json');
|
|
96
|
+
expect(acc).toEqual({ 'Content-Type': 'application/json' });
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('preserves mixed-case custom header name', () => {
|
|
100
|
+
const acc: Record<string, string> = {};
|
|
101
|
+
accumulateRequestHeader(acc, 'X-Request-ID', 'abc');
|
|
102
|
+
expect(acc).toEqual({ 'X-Request-ID': 'abc' });
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('last-value-wins preserves latest casing', () => {
|
|
106
|
+
const acc: Record<string, string> = {};
|
|
107
|
+
accumulateRequestHeader(acc, 'content-type', 'first');
|
|
108
|
+
accumulateRequestHeader(acc, 'Content-Type', 'second');
|
|
109
|
+
expect(acc).toEqual({ 'Content-Type': 'second' });
|
|
110
|
+
expect(Object.keys(acc)).toEqual(['Content-Type']);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('still blocks sensitive headers regardless of casing', () => {
|
|
114
|
+
const acc: Record<string, string> = {};
|
|
115
|
+
accumulateRequestHeader(acc, 'AUTHORIZATION', 'Bearer xyz');
|
|
116
|
+
expect(acc).toEqual({});
|
|
117
|
+
|
|
118
|
+
accumulateRequestHeader(acc, 'Authorization', 'Bearer xyz');
|
|
119
|
+
expect(acc).toEqual({});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe('captureResponseHeaders', () => {
|
|
124
|
+
const defaultsConfig: CompiledHeaderCaptureConfig = [
|
|
125
|
+
{
|
|
126
|
+
urlRegex: /.*/,
|
|
127
|
+
requestHeaderNames: new Set(DEFAULT_REQUEST_HEADERS),
|
|
128
|
+
responseHeaderNames: new Set(DEFAULT_RESPONSE_HEADERS),
|
|
129
|
+
isScoped: false,
|
|
130
|
+
requestHeaderCasing: new Map(CANONICAL_REQUEST_HEADERS),
|
|
131
|
+
responseHeaderCasing: new Map(CANONICAL_RESPONSE_HEADERS)
|
|
132
|
+
}
|
|
133
|
+
];
|
|
134
|
+
const disabledConfig: CompiledHeaderCaptureConfig = null;
|
|
135
|
+
const testUrl = 'https://api.example.com/data';
|
|
136
|
+
|
|
137
|
+
it('returns undefined when config is null (disabled)', () => {
|
|
138
|
+
const result = captureResponseHeaders(
|
|
139
|
+
'content-type: text/html\r\n',
|
|
140
|
+
testUrl,
|
|
141
|
+
disabledConfig
|
|
142
|
+
);
|
|
143
|
+
expect(result).toBeUndefined();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('returns undefined when rawHeaders is null', () => {
|
|
147
|
+
const result = captureResponseHeaders(
|
|
148
|
+
null,
|
|
149
|
+
testUrl,
|
|
150
|
+
defaultsConfig
|
|
151
|
+
);
|
|
152
|
+
expect(result).toBeUndefined();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('returns undefined when rawHeaders is undefined', () => {
|
|
156
|
+
const result = captureResponseHeaders(
|
|
157
|
+
undefined,
|
|
158
|
+
testUrl,
|
|
159
|
+
defaultsConfig
|
|
160
|
+
);
|
|
161
|
+
expect(result).toBeUndefined();
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('returns undefined when rawHeaders is empty string', () => {
|
|
165
|
+
const result = captureResponseHeaders('', testUrl, defaultsConfig);
|
|
166
|
+
expect(result).toBeUndefined();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('captures default response headers with defaults rule', () => {
|
|
170
|
+
const raw =
|
|
171
|
+
'content-type: text/html\r\ncache-control: no-cache\r\n';
|
|
172
|
+
const result = captureResponseHeaders(raw, testUrl, defaultsConfig);
|
|
173
|
+
expect(result).toEqual({
|
|
174
|
+
'Content-Type': 'text/html',
|
|
175
|
+
'Cache-Control': 'no-cache'
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('filters out non-default headers with defaults rule', () => {
|
|
180
|
+
const raw = 'x-custom: val\r\n';
|
|
181
|
+
const result = captureResponseHeaders(raw, testUrl, defaultsConfig);
|
|
182
|
+
expect(result).toBeUndefined();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('filters out sensitive headers via security filter', () => {
|
|
186
|
+
const raw = 'authorization: secret\r\ncache-control: no-cache\r\n';
|
|
187
|
+
const result = captureResponseHeaders(raw, testUrl, defaultsConfig);
|
|
188
|
+
expect(result).toEqual({ 'Cache-Control': 'no-cache' });
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('returns undefined when all headers are sensitive', () => {
|
|
192
|
+
const raw = 'authorization: secret\r\ncookie: session=abc\r\n';
|
|
193
|
+
const result = captureResponseHeaders(raw, testUrl, defaultsConfig);
|
|
194
|
+
expect(result).toBeUndefined();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('captures all 10 default response headers when present', () => {
|
|
198
|
+
const raw = `${[
|
|
199
|
+
'cache-control: max-age=3600',
|
|
200
|
+
'etag: "abc123"',
|
|
201
|
+
'age: 100',
|
|
202
|
+
'expires: Thu, 01 Jan 2099 00:00:00 GMT',
|
|
203
|
+
'content-type: application/json',
|
|
204
|
+
'content-encoding: gzip',
|
|
205
|
+
'content-length: 1234',
|
|
206
|
+
'vary: Accept-Encoding',
|
|
207
|
+
'server-timing: db;dur=53',
|
|
208
|
+
'x-cache: HIT'
|
|
209
|
+
].join('\r\n')}\r\n`;
|
|
210
|
+
const result = captureResponseHeaders(raw, testUrl, defaultsConfig);
|
|
211
|
+
expect(result).toEqual({
|
|
212
|
+
'Cache-Control': 'max-age=3600',
|
|
213
|
+
ETag: '"abc123"',
|
|
214
|
+
Age: '100',
|
|
215
|
+
Expires: 'Thu, 01 Jan 2099 00:00:00 GMT',
|
|
216
|
+
'Content-Type': 'application/json',
|
|
217
|
+
'Content-Encoding': 'gzip',
|
|
218
|
+
'Content-Length': '1234',
|
|
219
|
+
Vary: 'Accept-Encoding',
|
|
220
|
+
'Server-Timing': 'db;dur=53',
|
|
221
|
+
'X-Cache': 'HIT'
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
describe('scoped rules', () => {
|
|
226
|
+
it('applies a scoped rule over catch-all rules for percent-encoded hosts', () => {
|
|
227
|
+
const config = compileHeaderCaptureConfig([
|
|
228
|
+
{ type: 'defaults' },
|
|
229
|
+
{
|
|
230
|
+
type: 'matchResponseHeaders',
|
|
231
|
+
headers: ['x-request-id'],
|
|
232
|
+
forURLs: ['api.example.com/v2']
|
|
233
|
+
}
|
|
234
|
+
]);
|
|
235
|
+
const raw = 'cache-control: no-cache\r\nx-request-id: abc\r\n';
|
|
236
|
+
|
|
237
|
+
expect(
|
|
238
|
+
captureResponseHeaders(
|
|
239
|
+
raw,
|
|
240
|
+
'https://%61pi.example.com/v2/users',
|
|
241
|
+
config
|
|
242
|
+
)
|
|
243
|
+
).toEqual({ 'x-request-id': 'abc' });
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it.each([
|
|
247
|
+
'https://api\uFF0Eexample.com/v2/users',
|
|
248
|
+
'https://api%EF%BC%8Eexample.com/v2/users',
|
|
249
|
+
'https:///api.example.com/v2/users'
|
|
250
|
+
])(
|
|
251
|
+
'applies a scoped rule over catch-all rules for the equivalent spelling %s',
|
|
252
|
+
url => {
|
|
253
|
+
const config = compileHeaderCaptureConfig([
|
|
254
|
+
{ type: 'defaults' },
|
|
255
|
+
{
|
|
256
|
+
type: 'matchResponseHeaders',
|
|
257
|
+
headers: ['x-request-id'],
|
|
258
|
+
forURLs: ['api.example.com/v2']
|
|
259
|
+
}
|
|
260
|
+
]);
|
|
261
|
+
const raw =
|
|
262
|
+
'cache-control: no-cache\r\nx-request-id: abc\r\n';
|
|
263
|
+
|
|
264
|
+
expect(captureResponseHeaders(raw, url, config)).toEqual({
|
|
265
|
+
'x-request-id': 'abc'
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
it('matches forURLs hosts case-insensitively and paths case-sensitively', () => {
|
|
271
|
+
const config = compileHeaderCaptureConfig([
|
|
272
|
+
{
|
|
273
|
+
type: 'matchResponseHeaders',
|
|
274
|
+
headers: ['etag'],
|
|
275
|
+
forURLs: ['api.example.com/Public']
|
|
276
|
+
}
|
|
277
|
+
]);
|
|
278
|
+
const raw = 'etag: abc\r\n';
|
|
279
|
+
|
|
280
|
+
expect(
|
|
281
|
+
captureResponseHeaders(
|
|
282
|
+
raw,
|
|
283
|
+
'HTTPS://API.EXAMPLE.COM/Public/users',
|
|
284
|
+
config
|
|
285
|
+
)
|
|
286
|
+
).toEqual({ etag: 'abc' });
|
|
287
|
+
expect(
|
|
288
|
+
captureResponseHeaders(
|
|
289
|
+
raw,
|
|
290
|
+
'https://api.example.com/public/users',
|
|
291
|
+
config
|
|
292
|
+
)
|
|
293
|
+
).toBeUndefined();
|
|
294
|
+
expect(
|
|
295
|
+
filterRequestHeadersByMode(
|
|
296
|
+
{ etag: 'abc' },
|
|
297
|
+
'https://api.example.com/public/users',
|
|
298
|
+
config
|
|
299
|
+
)
|
|
300
|
+
).toBeUndefined();
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('captures only headers from matching rule', () => {
|
|
304
|
+
const config: CompiledHeaderCaptureConfig = [
|
|
305
|
+
{
|
|
306
|
+
urlRegex: /^https?:\/\/api\.example\.com/,
|
|
307
|
+
requestHeaderNames: new Set(['x-request-id']),
|
|
308
|
+
responseHeaderNames: new Set([
|
|
309
|
+
'x-custom',
|
|
310
|
+
'content-type'
|
|
311
|
+
]),
|
|
312
|
+
isScoped: true,
|
|
313
|
+
requestHeaderCasing: new Map([
|
|
314
|
+
['x-request-id', 'x-request-id']
|
|
315
|
+
]),
|
|
316
|
+
responseHeaderCasing: new Map([
|
|
317
|
+
['x-custom', 'x-custom'],
|
|
318
|
+
['content-type', 'content-type']
|
|
319
|
+
])
|
|
320
|
+
}
|
|
321
|
+
];
|
|
322
|
+
const raw =
|
|
323
|
+
'x-custom: val\r\ncontent-type: text/html\r\ncache-control: no-cache\r\n';
|
|
324
|
+
const result = captureResponseHeaders(raw, testUrl, config);
|
|
325
|
+
expect(result).toEqual({
|
|
326
|
+
'x-custom': 'val',
|
|
327
|
+
'content-type': 'text/html'
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it('returns undefined when no rule matches the URL', () => {
|
|
332
|
+
const config: CompiledHeaderCaptureConfig = [
|
|
333
|
+
{
|
|
334
|
+
urlRegex: /^https?:\/\/other\.example\.com/,
|
|
335
|
+
requestHeaderNames: new Set(),
|
|
336
|
+
responseHeaderNames: new Set(['content-type']),
|
|
337
|
+
isScoped: true,
|
|
338
|
+
requestHeaderCasing: new Map(),
|
|
339
|
+
responseHeaderCasing: new Map([
|
|
340
|
+
['content-type', 'content-type']
|
|
341
|
+
])
|
|
342
|
+
}
|
|
343
|
+
];
|
|
344
|
+
const raw = 'content-type: text/html\r\n';
|
|
345
|
+
const result = captureResponseHeaders(raw, testUrl, config);
|
|
346
|
+
expect(result).toBeUndefined();
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('still applies security filter with scoped rules', () => {
|
|
350
|
+
const config: CompiledHeaderCaptureConfig = [
|
|
351
|
+
{
|
|
352
|
+
urlRegex: /^https?:\/\/api\.example\.com/,
|
|
353
|
+
requestHeaderNames: new Set(),
|
|
354
|
+
responseHeaderNames: new Set([
|
|
355
|
+
'authorization',
|
|
356
|
+
'content-type'
|
|
357
|
+
]),
|
|
358
|
+
isScoped: true,
|
|
359
|
+
requestHeaderCasing: new Map(),
|
|
360
|
+
responseHeaderCasing: new Map([
|
|
361
|
+
['authorization', 'authorization'],
|
|
362
|
+
['content-type', 'content-type']
|
|
363
|
+
])
|
|
364
|
+
}
|
|
365
|
+
];
|
|
366
|
+
const raw =
|
|
367
|
+
'authorization: secret\r\ncontent-type: text/html\r\n';
|
|
368
|
+
const result = captureResponseHeaders(raw, testUrl, config);
|
|
369
|
+
expect(result).toEqual({ 'content-type': 'text/html' });
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
describe('union merging', () => {
|
|
374
|
+
it('merges headers from multiple matching rules additively', () => {
|
|
375
|
+
const config: CompiledHeaderCaptureConfig = [
|
|
376
|
+
{
|
|
377
|
+
urlRegex: /api\.example\.com/,
|
|
378
|
+
requestHeaderNames: new Set(),
|
|
379
|
+
responseHeaderNames: new Set(['x-cache']),
|
|
380
|
+
isScoped: true,
|
|
381
|
+
requestHeaderCasing: new Map(),
|
|
382
|
+
responseHeaderCasing: new Map([['x-cache', 'x-cache']])
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
urlRegex: /api\.example\.com/,
|
|
386
|
+
requestHeaderNames: new Set(),
|
|
387
|
+
responseHeaderNames: new Set(['content-type']),
|
|
388
|
+
isScoped: true,
|
|
389
|
+
requestHeaderCasing: new Map(),
|
|
390
|
+
responseHeaderCasing: new Map([
|
|
391
|
+
['content-type', 'content-type']
|
|
392
|
+
])
|
|
393
|
+
}
|
|
394
|
+
];
|
|
395
|
+
const raw = 'x-cache: HIT\r\ncontent-type: text/html\r\n';
|
|
396
|
+
const result = captureResponseHeaders(raw, testUrl, config);
|
|
397
|
+
expect(result).toEqual({
|
|
398
|
+
'x-cache': 'HIT',
|
|
399
|
+
'content-type': 'text/html'
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it('scoped rules replace catch-all rules when both match', () => {
|
|
404
|
+
const config: CompiledHeaderCaptureConfig = [
|
|
405
|
+
{
|
|
406
|
+
urlRegex: /.*/,
|
|
407
|
+
requestHeaderNames: new Set(),
|
|
408
|
+
responseHeaderNames: new Set(['etag']),
|
|
409
|
+
isScoped: false,
|
|
410
|
+
requestHeaderCasing: new Map(),
|
|
411
|
+
responseHeaderCasing: new Map([['etag', 'etag']])
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
urlRegex: /api\.example\.com/,
|
|
415
|
+
requestHeaderNames: new Set(),
|
|
416
|
+
responseHeaderNames: new Set(['x-cache']),
|
|
417
|
+
isScoped: true,
|
|
418
|
+
requestHeaderCasing: new Map(),
|
|
419
|
+
responseHeaderCasing: new Map([['x-cache', 'x-cache']])
|
|
420
|
+
}
|
|
421
|
+
];
|
|
422
|
+
const raw = 'etag: "abc"\r\nx-cache: HIT\r\n';
|
|
423
|
+
const result = captureResponseHeaders(raw, testUrl, config);
|
|
424
|
+
expect(result).toEqual({ 'x-cache': 'HIT' });
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
it('catch-all rules apply when no scoped rule matches', () => {
|
|
428
|
+
const config: CompiledHeaderCaptureConfig = [
|
|
429
|
+
{
|
|
430
|
+
urlRegex: /.*/,
|
|
431
|
+
requestHeaderNames: new Set(),
|
|
432
|
+
responseHeaderNames: new Set(['etag']),
|
|
433
|
+
isScoped: false,
|
|
434
|
+
requestHeaderCasing: new Map(),
|
|
435
|
+
responseHeaderCasing: new Map([['etag', 'etag']])
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
urlRegex: /other\.com/,
|
|
439
|
+
requestHeaderNames: new Set(),
|
|
440
|
+
responseHeaderNames: new Set(['x-cache']),
|
|
441
|
+
isScoped: true,
|
|
442
|
+
requestHeaderCasing: new Map(),
|
|
443
|
+
responseHeaderCasing: new Map([['x-cache', 'x-cache']])
|
|
444
|
+
}
|
|
445
|
+
];
|
|
446
|
+
const raw = 'etag: "abc"\r\nx-cache: HIT\r\n';
|
|
447
|
+
const result = captureResponseHeaders(
|
|
448
|
+
raw,
|
|
449
|
+
'https://api.example.com/data',
|
|
450
|
+
config
|
|
451
|
+
);
|
|
452
|
+
expect(result).toEqual({ etag: '"abc"' });
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it('multiple scoped rules merge additively', () => {
|
|
456
|
+
const config: CompiledHeaderCaptureConfig = [
|
|
457
|
+
{
|
|
458
|
+
urlRegex: /api\.example\.com/,
|
|
459
|
+
requestHeaderNames: new Set(),
|
|
460
|
+
responseHeaderNames: new Set(['x-cache', 'vary']),
|
|
461
|
+
isScoped: true,
|
|
462
|
+
requestHeaderCasing: new Map(),
|
|
463
|
+
responseHeaderCasing: new Map([
|
|
464
|
+
['x-cache', 'x-cache'],
|
|
465
|
+
['vary', 'vary']
|
|
466
|
+
])
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
urlRegex: /api\.example\.com/,
|
|
470
|
+
requestHeaderNames: new Set(),
|
|
471
|
+
responseHeaderNames: new Set(['content-type', 'etag']),
|
|
472
|
+
isScoped: true,
|
|
473
|
+
requestHeaderCasing: new Map(),
|
|
474
|
+
responseHeaderCasing: new Map([
|
|
475
|
+
['content-type', 'content-type'],
|
|
476
|
+
['etag', 'etag']
|
|
477
|
+
])
|
|
478
|
+
}
|
|
479
|
+
];
|
|
480
|
+
const raw =
|
|
481
|
+
'x-cache: HIT\r\nvary: Accept\r\ncontent-type: text/html\r\netag: "abc"\r\n';
|
|
482
|
+
const result = captureResponseHeaders(raw, testUrl, config);
|
|
483
|
+
expect(result).toEqual({
|
|
484
|
+
'x-cache': 'HIT',
|
|
485
|
+
vary: 'Accept',
|
|
486
|
+
'content-type': 'text/html',
|
|
487
|
+
etag: '"abc"'
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
describe('casing preservation', () => {
|
|
493
|
+
it('outputs default headers with canonical Title-Case casing', () => {
|
|
494
|
+
const raw =
|
|
495
|
+
'content-type: text/html\r\ncache-control: no-cache\r\n';
|
|
496
|
+
const result = captureResponseHeaders(
|
|
497
|
+
raw,
|
|
498
|
+
testUrl,
|
|
499
|
+
defaultsConfig
|
|
500
|
+
);
|
|
501
|
+
expect(result).toEqual({
|
|
502
|
+
'Content-Type': 'text/html',
|
|
503
|
+
'Cache-Control': 'no-cache'
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
it('outputs custom rule headers with user-provided casing', () => {
|
|
508
|
+
const config: CompiledHeaderCaptureConfig = [
|
|
509
|
+
{
|
|
510
|
+
urlRegex: /.*/,
|
|
511
|
+
requestHeaderNames: new Set(),
|
|
512
|
+
responseHeaderNames: new Set(['x-ratelimit']),
|
|
513
|
+
isScoped: false,
|
|
514
|
+
requestHeaderCasing: new Map(),
|
|
515
|
+
responseHeaderCasing: new Map([
|
|
516
|
+
['x-ratelimit', 'x-ratelimit']
|
|
517
|
+
])
|
|
518
|
+
}
|
|
519
|
+
];
|
|
520
|
+
const raw = 'x-ratelimit: 100\r\n';
|
|
521
|
+
const result = captureResponseHeaders(raw, testUrl, config);
|
|
522
|
+
expect(result).toEqual({ 'x-ratelimit': '100' });
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
it('custom rule casing overrides defaults for same header', () => {
|
|
526
|
+
const config: CompiledHeaderCaptureConfig = [
|
|
527
|
+
{
|
|
528
|
+
urlRegex: /.*/,
|
|
529
|
+
requestHeaderNames: new Set(DEFAULT_REQUEST_HEADERS),
|
|
530
|
+
responseHeaderNames: new Set(DEFAULT_RESPONSE_HEADERS),
|
|
531
|
+
isScoped: false,
|
|
532
|
+
requestHeaderCasing: new Map(CANONICAL_REQUEST_HEADERS),
|
|
533
|
+
responseHeaderCasing: new Map(
|
|
534
|
+
CANONICAL_RESPONSE_HEADERS
|
|
535
|
+
)
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
urlRegex: /.*/,
|
|
539
|
+
requestHeaderNames: new Set(),
|
|
540
|
+
responseHeaderNames: new Set(['content-type']),
|
|
541
|
+
isScoped: false,
|
|
542
|
+
requestHeaderCasing: new Map(),
|
|
543
|
+
responseHeaderCasing: new Map([
|
|
544
|
+
['content-type', 'content-type']
|
|
545
|
+
])
|
|
546
|
+
}
|
|
547
|
+
];
|
|
548
|
+
const raw = 'content-type: text/html\r\n';
|
|
549
|
+
const result = captureResponseHeaders(raw, testUrl, config);
|
|
550
|
+
// Second rule's casing should override first for same header
|
|
551
|
+
expect(result).toEqual({ 'content-type': 'text/html' });
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
it('first custom rule casing wins among custom rules', () => {
|
|
555
|
+
const config: CompiledHeaderCaptureConfig = [
|
|
556
|
+
{
|
|
557
|
+
urlRegex: /.*/,
|
|
558
|
+
requestHeaderNames: new Set(),
|
|
559
|
+
responseHeaderNames: new Set(['content-type']),
|
|
560
|
+
isScoped: true,
|
|
561
|
+
requestHeaderCasing: new Map(),
|
|
562
|
+
responseHeaderCasing: new Map([
|
|
563
|
+
['content-type', 'Content-Type']
|
|
564
|
+
])
|
|
565
|
+
},
|
|
566
|
+
{
|
|
567
|
+
urlRegex: /.*/,
|
|
568
|
+
requestHeaderNames: new Set(),
|
|
569
|
+
responseHeaderNames: new Set(['content-type']),
|
|
570
|
+
isScoped: true,
|
|
571
|
+
requestHeaderCasing: new Map(),
|
|
572
|
+
responseHeaderCasing: new Map([
|
|
573
|
+
['content-type', 'content-type']
|
|
574
|
+
])
|
|
575
|
+
}
|
|
576
|
+
];
|
|
577
|
+
const raw = 'content-type: text/html\r\n';
|
|
578
|
+
const result = captureResponseHeaders(raw, testUrl, config);
|
|
579
|
+
// First rule's casing wins
|
|
580
|
+
expect(result).toEqual({ 'Content-Type': 'text/html' });
|
|
581
|
+
});
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
describe('filterRequestHeadersByMode', () => {
|
|
586
|
+
const testUrl = 'https://api.example.com/data';
|
|
587
|
+
const disabledConfig: CompiledHeaderCaptureConfig = null;
|
|
588
|
+
const defaultsConfig: CompiledHeaderCaptureConfig = [
|
|
589
|
+
{
|
|
590
|
+
urlRegex: /.*/,
|
|
591
|
+
requestHeaderNames: new Set(DEFAULT_REQUEST_HEADERS),
|
|
592
|
+
responseHeaderNames: new Set(DEFAULT_RESPONSE_HEADERS),
|
|
593
|
+
isScoped: false,
|
|
594
|
+
requestHeaderCasing: new Map(CANONICAL_REQUEST_HEADERS),
|
|
595
|
+
responseHeaderCasing: new Map(CANONICAL_RESPONSE_HEADERS)
|
|
596
|
+
}
|
|
597
|
+
];
|
|
598
|
+
|
|
599
|
+
it('returns undefined when config is null (disabled)', () => {
|
|
600
|
+
const result = filterRequestHeadersByMode(
|
|
601
|
+
{ 'content-type': 'json' },
|
|
602
|
+
testUrl,
|
|
603
|
+
disabledConfig
|
|
604
|
+
);
|
|
605
|
+
expect(result).toBeUndefined();
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
it('keeps only default request headers with defaults rule', () => {
|
|
609
|
+
const result = filterRequestHeadersByMode(
|
|
610
|
+
{ 'content-type': 'json', 'x-custom': 'val' },
|
|
611
|
+
testUrl,
|
|
612
|
+
defaultsConfig
|
|
613
|
+
);
|
|
614
|
+
expect(result).toEqual({ 'Content-Type': 'json' });
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
it('returns undefined when no default request headers present', () => {
|
|
618
|
+
const result = filterRequestHeadersByMode(
|
|
619
|
+
{ 'x-custom': 'val' },
|
|
620
|
+
testUrl,
|
|
621
|
+
defaultsConfig
|
|
622
|
+
);
|
|
623
|
+
expect(result).toBeUndefined();
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
it('keeps both default request headers when present', () => {
|
|
627
|
+
const result = filterRequestHeadersByMode(
|
|
628
|
+
{
|
|
629
|
+
'content-type': 'json',
|
|
630
|
+
'cache-control': 'no-cache',
|
|
631
|
+
'x-custom': 'val'
|
|
632
|
+
},
|
|
633
|
+
testUrl,
|
|
634
|
+
defaultsConfig
|
|
635
|
+
);
|
|
636
|
+
expect(result).toEqual({
|
|
637
|
+
'Content-Type': 'json',
|
|
638
|
+
'Cache-Control': 'no-cache'
|
|
639
|
+
});
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
describe('scoped rules', () => {
|
|
643
|
+
it('keeps only request headers from matching rule', () => {
|
|
644
|
+
const config: CompiledHeaderCaptureConfig = [
|
|
645
|
+
{
|
|
646
|
+
urlRegex: /^https?:\/\/api\.example\.com/,
|
|
647
|
+
requestHeaderNames: new Set(['x-request-id']),
|
|
648
|
+
responseHeaderNames: new Set(),
|
|
649
|
+
isScoped: true,
|
|
650
|
+
requestHeaderCasing: new Map([
|
|
651
|
+
['x-request-id', 'x-request-id']
|
|
652
|
+
]),
|
|
653
|
+
responseHeaderCasing: new Map()
|
|
654
|
+
}
|
|
655
|
+
];
|
|
656
|
+
const result = filterRequestHeadersByMode(
|
|
657
|
+
{ 'x-request-id': 'abc', 'x-other': 'def' },
|
|
658
|
+
testUrl,
|
|
659
|
+
config
|
|
660
|
+
);
|
|
661
|
+
expect(result).toEqual({ 'x-request-id': 'abc' });
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
it('returns undefined when no rule matches URL', () => {
|
|
665
|
+
const config: CompiledHeaderCaptureConfig = [
|
|
666
|
+
{
|
|
667
|
+
urlRegex: /^https?:\/\/other\.example\.com/,
|
|
668
|
+
requestHeaderNames: new Set(['x-request-id']),
|
|
669
|
+
responseHeaderNames: new Set(),
|
|
670
|
+
isScoped: true,
|
|
671
|
+
requestHeaderCasing: new Map([
|
|
672
|
+
['x-request-id', 'x-request-id']
|
|
673
|
+
]),
|
|
674
|
+
responseHeaderCasing: new Map()
|
|
675
|
+
}
|
|
676
|
+
];
|
|
677
|
+
const result = filterRequestHeadersByMode(
|
|
678
|
+
{ 'x-request-id': 'abc' },
|
|
679
|
+
testUrl,
|
|
680
|
+
config
|
|
681
|
+
);
|
|
682
|
+
expect(result).toBeUndefined();
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
it('returns undefined when matching rule has no request header matches', () => {
|
|
686
|
+
const config: CompiledHeaderCaptureConfig = [
|
|
687
|
+
{
|
|
688
|
+
urlRegex: /^https?:\/\/api\.example\.com/,
|
|
689
|
+
requestHeaderNames: new Set(['x-request-id']),
|
|
690
|
+
responseHeaderNames: new Set(),
|
|
691
|
+
isScoped: true,
|
|
692
|
+
requestHeaderCasing: new Map([
|
|
693
|
+
['x-request-id', 'x-request-id']
|
|
694
|
+
]),
|
|
695
|
+
responseHeaderCasing: new Map()
|
|
696
|
+
}
|
|
697
|
+
];
|
|
698
|
+
const result = filterRequestHeadersByMode(
|
|
699
|
+
{ 'x-other': 'val' },
|
|
700
|
+
testUrl,
|
|
701
|
+
config
|
|
702
|
+
);
|
|
703
|
+
expect(result).toBeUndefined();
|
|
704
|
+
});
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
describe('union merging', () => {
|
|
708
|
+
it('merges request headers from multiple matching rules', () => {
|
|
709
|
+
const config: CompiledHeaderCaptureConfig = [
|
|
710
|
+
{
|
|
711
|
+
urlRegex: /api\.example\.com/,
|
|
712
|
+
requestHeaderNames: new Set(['x-request-id']),
|
|
713
|
+
responseHeaderNames: new Set(),
|
|
714
|
+
isScoped: true,
|
|
715
|
+
requestHeaderCasing: new Map([
|
|
716
|
+
['x-request-id', 'x-request-id']
|
|
717
|
+
]),
|
|
718
|
+
responseHeaderCasing: new Map()
|
|
719
|
+
},
|
|
720
|
+
{
|
|
721
|
+
urlRegex: /api\.example\.com/,
|
|
722
|
+
requestHeaderNames: new Set(['content-type']),
|
|
723
|
+
responseHeaderNames: new Set(),
|
|
724
|
+
isScoped: true,
|
|
725
|
+
requestHeaderCasing: new Map([
|
|
726
|
+
['content-type', 'content-type']
|
|
727
|
+
]),
|
|
728
|
+
responseHeaderCasing: new Map()
|
|
729
|
+
}
|
|
730
|
+
];
|
|
731
|
+
const result = filterRequestHeadersByMode(
|
|
732
|
+
{
|
|
733
|
+
'x-request-id': 'abc',
|
|
734
|
+
'content-type': 'json',
|
|
735
|
+
'x-other': 'val'
|
|
736
|
+
},
|
|
737
|
+
testUrl,
|
|
738
|
+
config
|
|
739
|
+
);
|
|
740
|
+
expect(result).toEqual({
|
|
741
|
+
'x-request-id': 'abc',
|
|
742
|
+
'content-type': 'json'
|
|
743
|
+
});
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
it('scoped rules replace catch-all for request headers', () => {
|
|
747
|
+
const config: CompiledHeaderCaptureConfig = [
|
|
748
|
+
{
|
|
749
|
+
urlRegex: /.*/,
|
|
750
|
+
requestHeaderNames: new Set(['x-catch-all']),
|
|
751
|
+
responseHeaderNames: new Set(),
|
|
752
|
+
isScoped: false,
|
|
753
|
+
requestHeaderCasing: new Map([
|
|
754
|
+
['x-catch-all', 'x-catch-all']
|
|
755
|
+
]),
|
|
756
|
+
responseHeaderCasing: new Map()
|
|
757
|
+
},
|
|
758
|
+
{
|
|
759
|
+
urlRegex: /api\.example\.com/,
|
|
760
|
+
requestHeaderNames: new Set(['x-scoped']),
|
|
761
|
+
responseHeaderNames: new Set(),
|
|
762
|
+
isScoped: true,
|
|
763
|
+
requestHeaderCasing: new Map([
|
|
764
|
+
['x-scoped', 'x-scoped']
|
|
765
|
+
]),
|
|
766
|
+
responseHeaderCasing: new Map()
|
|
767
|
+
}
|
|
768
|
+
];
|
|
769
|
+
const result = filterRequestHeadersByMode(
|
|
770
|
+
{ 'x-catch-all': 'a', 'x-scoped': 'b' },
|
|
771
|
+
testUrl,
|
|
772
|
+
config
|
|
773
|
+
);
|
|
774
|
+
expect(result).toEqual({ 'x-scoped': 'b' });
|
|
775
|
+
});
|
|
776
|
+
});
|
|
777
|
+
|
|
778
|
+
it('returns undefined for empty accumulated headers', () => {
|
|
779
|
+
const result = filterRequestHeadersByMode(
|
|
780
|
+
{},
|
|
781
|
+
testUrl,
|
|
782
|
+
defaultsConfig
|
|
783
|
+
);
|
|
784
|
+
expect(result).toBeUndefined();
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
describe('casing preservation', () => {
|
|
788
|
+
it('outputs request headers with original accumulated casing', () => {
|
|
789
|
+
const config: CompiledHeaderCaptureConfig = [
|
|
790
|
+
{
|
|
791
|
+
urlRegex: /.*/,
|
|
792
|
+
requestHeaderNames: new Set([
|
|
793
|
+
'content-type',
|
|
794
|
+
'x-request-id'
|
|
795
|
+
]),
|
|
796
|
+
responseHeaderNames: new Set(),
|
|
797
|
+
isScoped: false,
|
|
798
|
+
requestHeaderCasing: new Map([
|
|
799
|
+
['content-type', 'Content-Type'],
|
|
800
|
+
['x-request-id', 'X-Request-ID']
|
|
801
|
+
]),
|
|
802
|
+
responseHeaderCasing: new Map()
|
|
803
|
+
}
|
|
804
|
+
];
|
|
805
|
+
// Accumulated headers have original setRequestHeader casing
|
|
806
|
+
const result = filterRequestHeadersByMode(
|
|
807
|
+
{
|
|
808
|
+
'Content-Type': 'application/json',
|
|
809
|
+
'X-Request-ID': 'abc'
|
|
810
|
+
},
|
|
811
|
+
testUrl,
|
|
812
|
+
config
|
|
813
|
+
);
|
|
814
|
+
expect(result).toEqual({
|
|
815
|
+
'Content-Type': 'application/json',
|
|
816
|
+
'X-Request-ID': 'abc'
|
|
817
|
+
});
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
it('falls back to config casing when accumulated key is lowered', () => {
|
|
821
|
+
const config: CompiledHeaderCaptureConfig = [
|
|
822
|
+
{
|
|
823
|
+
urlRegex: /.*/,
|
|
824
|
+
requestHeaderNames: new Set([
|
|
825
|
+
'content-type',
|
|
826
|
+
'cache-control'
|
|
827
|
+
]),
|
|
828
|
+
responseHeaderNames: new Set(),
|
|
829
|
+
isScoped: false,
|
|
830
|
+
requestHeaderCasing: new Map([
|
|
831
|
+
['content-type', 'Content-Type'],
|
|
832
|
+
['cache-control', 'Cache-Control']
|
|
833
|
+
]),
|
|
834
|
+
responseHeaderCasing: new Map()
|
|
835
|
+
}
|
|
836
|
+
];
|
|
837
|
+
// Accumulated headers are lowered (legacy/fallback scenario)
|
|
838
|
+
const result = filterRequestHeadersByMode(
|
|
839
|
+
{
|
|
840
|
+
'content-type': 'application/json',
|
|
841
|
+
'cache-control': 'no-cache'
|
|
842
|
+
},
|
|
843
|
+
testUrl,
|
|
844
|
+
config
|
|
845
|
+
);
|
|
846
|
+
expect(result).toEqual({
|
|
847
|
+
'Content-Type': 'application/json',
|
|
848
|
+
'Cache-Control': 'no-cache'
|
|
849
|
+
});
|
|
850
|
+
});
|
|
851
|
+
});
|
|
852
|
+
});
|
|
853
|
+
});
|