Repository: ktorio/ktor
File: ktor-client/ktor-client-core/common/src/io/ktor/client/plugins/observer/DelegatedCall.kt (Kotlin)

Code before:
/*
 * Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
 */

package io.ktor.client.plugins.observer

import io.ktor.client.call.*
import io.ktor.http.*
import io.ktor.utils.io.*

/**
 * Wrap existing [HttpClientCall] with new [content].
 *
 * **Warning:** The content of the returned call response is non-replayable, so it can be consumed only once.
 * Consider using `wrapWithContent` with lambda instead.
 *
 * [Report a problem](https://ktor.io/feedback/?fqname=io.ktor.client.plugins.observer.wrapWithContent)
 */
@Deprecated(
    "Use 'withResponse' instead.",
    ReplaceWith(
        "withResponse { content }",
        "io.ktor.client.call.withResponse"
    )
)
public fun HttpClientCall.wrapWithContent(content: ByteReadChannel): HttpClientCall = withResponse { content }

/**
 * Wrap existing [HttpClientCall] with new content produced by the given [block].
 * The [block] will be called each time the response content is requested.
 *
 * [Report a problem](https://ktor.io/feedback/?fqname=io.ktor.client.plugins.observer.wrapWithContent)
 */
@Deprecated(
    "Use 'withResponse' instead.",
    ReplaceWith(
        "withResponse { block() }",
        "io.ktor.client.call.withResponse"
    )
)
public fun HttpClientCall.wrapWithContent(block: () -> ByteReadChannel): HttpClientCall = withResponse { block() }

/**
 * Wrap existing [HttpClientCall] with new response [content] and [headers].
 *

Review comment (suggestion):
[nitpick] Consider updating the deprecation message to consistently reference 'withResponse' as the migration path instead of mentioning 'wrapWithContent with lambda', to avoid any potential confusion.

Code after:
/*
 * Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
 */

package io.ktor.client.plugins.observer

import io.ktor.client.call.*
import io.ktor.http.*
import io.ktor.utils.io.*

/**
 * Wrap existing [HttpClientCall] with new [content].
 *
 * **Warning:** The content of the returned call response is non-replayable, so it can be consumed only once.
 * Consider using `replaceResponse` instead.
 *
 * [Report a problem](https://ktor.io/feedback/?fqname=io.ktor.client.plugins.observer.wrapWithContent)
 */
@Deprecated(
    "Use 'replaceResponse' instead.",
    ReplaceWith(
        "replaceResponse { content }",
        "io.ktor.client.call.replaceResponse"
    )
)
public fun HttpClientCall.wrapWithContent(content: ByteReadChannel): HttpClientCall = replaceResponse { content }

/**
 * Wrap existing [HttpClientCall] with new content produced by the given [block].
 * The [block] will be called each time the response content is requested.
 *
 * [Report a problem](https://ktor.io/feedback/?fqname=io.ktor.client.plugins.observer.wrapWithContent)
 */
@Deprecated(
    "Use 'replaceResponse' instead.",
    ReplaceWith(
        "replaceResponse { block() }",
        "io.ktor.client.call.replaceResponse"
    )
)
public fun HttpClientCall.wrapWithContent(block: () -> ByteReadChannel): HttpClientCall = replaceResponse { block() }

/**
 * Wrap existing [HttpClientCall] with new response [content] and [headers].
 *