Select to view content in your preferred language

There is no way to modify network request

1102
4
Jump to solution
09-04-2023 03:27 AM
dev4567
Emerging Contributor

Context

Starting with Kotlin SDK 200.2 there is ability to add http network (application level) interceptor.

Issue

There is no way to modify a request from the chain – there is no builder for it and `Request.Builder()` will cause exception (as it doesn't have okhttp delegate inside).

Sample code

ArcGISEnvironment.configureArcGISHttpClient {
interceptor {
val originalRequest = it.request()
// val newRequest = originalRequest.newBuilder() <-- no API for this op
// it.proceed(newRequest) // so we can't e.g. add/remove header
it.proceed(originalRequest)
}
}
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
GuntherHeppner
Esri Contributor

We just released ArcGIS Maps SDK for Kotlin 200.4.0, which supports modification of network requests (headers and parameters) during network request interception, more details here.

View solution in original post

0 Kudos
4 Replies
GuntherHeppner
Esri Contributor

Yes, with 200.2.0 we added support for network interceptors, but at this point only for "observational" purposes such as logging network requests. We are currently working on support for modifying network requests as part of network interception. This will be supported in one of the upcoming releases.

Note, if you are interested in adding headers on every outgoing network request, you can currently do this with ArcGISHttpClient.addAdditionalRequestHeader.

0 Kudos
KhiemLq
New Contributor

Hi @GuntherHeppner , It’s good to hear ArcGIS is gonna support modify request so that we could make the request through internal proxy. 

Could you help to give a estimation for the date of next ArcGIS release so that I could plan for my project

0 Kudos
dev4567
Emerging Contributor

The issue with `addAdditionalRequestHeader` is it do adds a header, so there is no way to overwrite the existing one – this is quite critical when e.g. we use own proxy for authorization and every time the auth token expires we have to provide a new header, but the proxy server still expects sole auth header and just uses the first one available (with already expired token).

So we need either interception-with-change-request mechanism or something like `ArcGISHttpClient.removeAdditionalRequestHeader`.

0 Kudos
GuntherHeppner
Esri Contributor

We just released ArcGIS Maps SDK for Kotlin 200.4.0, which supports modification of network requests (headers and parameters) during network request interception, more details here.

0 Kudos