So I’m implementing an alternative to <https://git...
# ktor
r
So I’m implementing an alternative to https://github.com/ktorio/ktor/issues/1068 because I need it yesterday. Do you think this is a memory-leak safe solution?
Copy code
private val buildersRequiringAuth: MutableSet<HttpRequestBuilder> = HashSet()

/**
 * Setups the Authentication header of this request.
 */
fun HttpRequestBuilder.useAuthentication() {
    buildersRequiringAuth.add(this)
    @Suppress("EXPERIMENTAL_API_USAGE")
    executionContext.invokeOnCompletion {
        buildersRequiringAuth.remove(this)
    }
}

internal val HttpRequestBuilder.usesAuthentication: Boolean
    get() = this in buildersRequiringAuth