Files
NachoSoto ed80980d08 HTTPClient: verbose logs for request IDs (#3320)
See https://github.com/RevenueCat/khepri/pull/6798.
This can help debug issues as it helps us cross-reference requests on
our end.

### Changes:
- Logging `X-Request-ID` and `X-Amzn-Trace-ID` headers if present (only
in verbose mode)
- Logging these even for failed requests
- Also logging `request_handled_by_load_shedder` for failed requests
- To accomplish that. `HTTPURLResponse` now conforms to our
`HTTPResponseType`, this allows us to extract headers in an uniform way

### Example:
```
[network] DEBUG: ℹ️ API request completed: GET '/v1/subscribers/$RCAnonymousID%3Ad9dc4f3b33054cf28c0f2ec9da0f48d5' (304)
Request-ID: 'be534c50-5231-403b-be2f-7c077861751d'; Amzn-Trace-ID: 'Root=1-6532c6ca-7ef80f961ec9c4145484df13'
```
2023-10-25 20:24:23 -07:00

43 lines
1.2 KiB
Swift

//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// OperationQueue+Extensions.swift
//
// Created by Joshua Liebowitz on 1/20/22.
import Foundation
extension OperationQueue {
final func addCacheableOperation<T: CacheableNetworkOperation>(
with factory: CacheableNetworkOperationFactory<T>,
cacheStatus: CallbackCacheStatus
) {
switch cacheStatus {
case .firstCallbackAddedToList:
self.addOperation(factory.create())
Logger.verbose(Strings.network.enqueing_operation(factory.operationType,
cacheKey: factory.cacheKey))
case .addedToExistingInFlightList:
Logger.debug(
Strings.network.reusing_existing_request_for_operation(
T.self,
Logger.verboseLogsEnabled
? factory.cacheKey
: factory.cacheKey.prefix(15) + "…"
)
)
return
}
}
}