Is your feature request related to a problem? Please describe.
RequestFactory is the only extension point for HTTP customization, and its API (openConnection(url): HttpURLConnection) gives us no way to observe upload lifecycle events without resorting to a full HttpURLConnection wrapper.
HttpURLConnection is abstract, so Kotlin's by delegation does not apply. Intercepting even a single method (e.g. getResponseCode() for upload latency measurement) requires a class that manually forwards every method to a delegate, roughly 25+ overrides for the methods the SDK actually calls. The result is fragile boilerplate that silently breaks whenever the SDK starts calling a method that wasn't forwarded.
Describe the solution you'd like
A callback interface on RequestFactory that the SDK invokes after each upload attempt, for example:
open class RequestFactory {
// existing API …
/**
* Called when an upload receives an HTTP response.
*
* @param url the upload endpoint
* @param statusCode HTTP response code
* @param elapsedMs wall-clock time from opening the connection to receiving the response
*/
open fun onUploadCompleted(url: String, statusCode: Int, elapsedMs: Long) {}
/**
* Called when an upload fails with a network exception before an HTTP response is received.
*
* @param url the upload endpoint
* @param error the IOException that caused the failure
* @param elapsedMs wall-clock time from opening the connection to the failure
*/
open fun onUploadError(url: String, error: IOException, elapsedMs: Long) {}
}
Separating the two callbacks keeps each signature clean:
onUploadCompleted always has a valid status code.
onUploadError always has a real exception and avoids sentinel values like statusCode = -1 that callers would otherwise need to guard against.
This would let us emit structured metrics and fire alerts, all without touching HttpURLConnection 's internals.
Describe alternatives you've considered
Wrapping HttpURLConnection via a subclass delegating to a real instance (the current workaround). It works, but:
- Requires overriding ~25 methods manually
- Silently breaks if the SDK starts calling an un-overridden method after an SDK upgrade (values are written to the wrapper's inherited fields, never forwarded to the underlying connection)
Additional context
We are using RequestFactory to route uploads through a proxy, attach custom request headers, and configure timeouts via a remote config system. The onUploadCompleted hook would let us also emit structured log events for slow or failed uploads without the wrapper approach described above.
Is your feature request related to a problem? Please describe.
RequestFactoryis the only extension point for HTTP customization, and its API (openConnection(url): HttpURLConnection) gives us no way to observe upload lifecycle events without resorting to a fullHttpURLConnectionwrapper.HttpURLConnectionis abstract, so Kotlin'sbydelegation does not apply. Intercepting even a single method (e.g.getResponseCode()for upload latency measurement) requires a class that manually forwards every method to a delegate, roughly 25+ overrides for the methods the SDK actually calls. The result is fragile boilerplate that silently breaks whenever the SDK starts calling a method that wasn't forwarded.Describe the solution you'd like
A callback interface on
RequestFactorythat the SDK invokes after each upload attempt, for example:Separating the two callbacks keeps each signature clean:
onUploadCompletedalways has a valid status code.onUploadErroralways has a real exception and avoids sentinel values likestatusCode = -1that callers would otherwise need to guard against.This would let us emit structured metrics and fire alerts, all without touching
HttpURLConnection's internals.Describe alternatives you've considered
Wrapping
HttpURLConnectionvia a subclass delegating to a real instance (the current workaround). It works, but:Additional context
We are using
RequestFactoryto route uploads through a proxy, attach custom request headers, and configure timeouts via a remote config system. TheonUploadCompletedhook would let us also emit structured log events for slow or failed uploads without the wrapper approach described above.