I am porting some Retrofit code to ktor. I need to add additional params (a signature calculation) to an already built URLBuilder. But I get the following:
Copy code
java.lang.IllegalStateException: Cannot modify a builder when final structure has already been built
. Is there a way to do this? Any examples out there I may refer to? Thank you.
s
Shawn
05/29/2019, 2:48 AM
So, I searched for that error and found my way to the
or something, create a new collection with the params you need to add, then create a new, unbuilt ParametersBuilder using the pairs. Then perhaps pass that ParametersBuilder to a new URLBuilder instance with the appropriate values
Shawn
05/29/2019, 2:48 AM
might be best to wrap it in an extension function…
Shawn
05/29/2019, 2:49 AM
the API is not really designed to do this easily, at least, in a type-safe manner anyhow
e
e5l
05/29/2019, 6:20 AM
Hi @tylerwilson, can you add it before the build?
t
tylerwilson
05/29/2019, 2:01 PM
Yeah, thinking about it some more, I think the way to go is the generate sig and create a new URL builder with the updated params. The signature calc needs the host, path and all params to use for calculation (it is based on some Amazon signature procedure). Adding before may be possible, but having an extension on URLBuilder was/is a convenient way to do it. Either way, looks like some copy/calc/apply code is needed. Thank you both.