@@ -44,38 +44,33 @@ internal val CHECKSUM_HEADER_VALIDATION_PRIORITY_LIST: List<String> = listOf(
4444 * @param responseChecksumValidation Configuration option that determines when checksum validation should be done.
4545 */
4646@InternalApi
47- public class FlexibleChecksumsResponseInterceptor < I > (
47+ public open class FlexibleChecksumsResponseInterceptor (
4848 private val responseValidationRequired : Boolean ,
4949 private val responseChecksumValidation : HttpChecksumConfigOption ? ,
5050) : HttpInterceptor {
51-
52- // FIXME: Remove in next minor version bump
53- @Deprecated(" Old constructor is no longer used but it's kept for backwards compatibility" )
54- public constructor (
55- shouldValidateResponseChecksumInitializer: (input: I ) -> Boolean ,
56- ) : this (
57- false ,
58- HttpChecksumConfigOption .WHEN_REQUIRED ,
59- )
60-
6151 @InternalApi
6252 public companion object {
6353 // The name of the checksum header which was validated. If `null`, validation was not performed.
6454 public val ChecksumHeaderValidated : AttributeKey <String > = AttributeKey (" ChecksumHeaderValidated" )
6555 }
6656
6757 override suspend fun modifyBeforeDeserialization (context : ProtocolResponseInterceptorContext <Any , HttpRequest , HttpResponse >): HttpResponse {
68- val logger = coroutineContext.logger<FlexibleChecksumsResponseInterceptor < I > >()
58+ val logger = coroutineContext.logger<FlexibleChecksumsResponseInterceptor >()
6959
70- val forcedToVerifyChecksum = responseValidationRequired || responseChecksumValidation == HttpChecksumConfigOption .WHEN_SUPPORTED
71- if (! forcedToVerifyChecksum ) return context.protocolResponse
60+ val configuredToVerifyChecksum = responseValidationRequired || responseChecksumValidation == HttpChecksumConfigOption .WHEN_SUPPORTED
61+ if (! configuredToVerifyChecksum ) return context.protocolResponse
7262
7363 val checksumHeader = CHECKSUM_HEADER_VALIDATION_PRIORITY_LIST
7464 .firstOrNull { context.protocolResponse.headers.contains(it) } ? : run {
75- logger.warn { " Checksum validation was requested but the response headers didn't contain a valid checksum." }
65+ logger.warn { " Checksum validation was requested but the response headers didn't contain a valid checksum." }
66+ return context.protocolResponse
67+ }
68+
69+ val serviceChecksumValue = context.protocolResponse.headers[checksumHeader]!!
70+ if (ignoreChecksum(serviceChecksumValue)) {
71+ logger.warn { " Checksum detected but validation was skipped." }
7672 return context.protocolResponse
7773 }
78- val serviceChecksumValue = context.protocolResponse.headers[checksumHeader]!!
7974
8075 context.executionContext[ChecksumHeaderValidated ] = checksumHeader
8176
@@ -111,6 +106,11 @@ public class FlexibleChecksumsResponseInterceptor<I>(
111106 else -> throw IllegalStateException (" HTTP body type '$bodyType ' is not supported for flexible checksums." )
112107 }
113108 }
109+
110+ /* *
111+ * Additional check on the checksum itself to see if it should be validated
112+ */
113+ public open fun ignoreChecksum (checksum : String ): Boolean = false
114114}
115115
116116public class ChecksumMismatchException (message : String? ) : ClientException(message)
0 commit comments