okhttp icon indicating copy to clipboard operation
okhttp copied to clipboard

Manipulate Interceptors on a Call?

Open oldergod opened this issue 3 years ago • 4 comments

We were looking at some Wire stuff, and Wire operates on a Call.Factory so it cannot introduce new interceptors to an existing Call.

It’d be interesting/powerful to be able to add interceptors directly on a Call instance.

oldergod avatar May 30 '22 14:05 oldergod

application or network interceptors? both?

yschimke avatar May 30 '22 14:05 yschimke

Both

oldergod avatar May 30 '22 17:05 oldergod

This is a weird mixing of layers, but I can see why it's powerful. Particularly if we increasingly support Call.Factory as API and also as implementation.

But in that regard it's why it's mixing the layers. Call.Factory and dependencies are fairly tight. It would pull in Interceptor, and transitively Chain, Connection.

I guess we could ignore this except on jvm.

What is the contract, that you can add final application or network interceptors? Any need to be in other positions?

yschimke avatar May 31 '22 20:05 yschimke

This seems doable, but Call is a pretty central public API that is actively implemented. So wondering what the APIs are like, going to throw in EventListeners here also.

Can't work out how to do this nicely with a clone, since RealCall is heavyweight.

  interface Call {
    fun clone(xxx): Call
  }

So maybe

  interface Call {
    fun addEventListener(eventListener: EventListener)
    fun addInterceptor(interceptor: Interceptor)
    fun addNetworkInterceptor(interceptor: Interceptor)
  }

Or

  interface Call {
    // must be called before execution
    fun reconfigure(fn: CallOptions.() -> Unit)
  }
  
  interface CallOptions {
    fun addEventListener(eventListener: EventListener)
    var interceptors: List<Interceptor>
    var networkInterceptors: List<Interceptor>
  }

Or interface ConfigurableCall: Call

yschimke avatar Sep 10 '22 12:09 yschimke