File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed
main/kotlin/com/withorb/api/core
test/kotlin/com/withorb/api/core Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -464,13 +464,14 @@ private constructor(
464464 headers.put(" X-Stainless-Runtime" , " JRE" )
465465 headers.put(" X-Stainless-Runtime-Version" , getJavaVersion())
466466 headers.put(" X-Stainless-Kotlin-Version" , KotlinVersion .CURRENT .toString())
467+ // We replace after all the default headers to allow end-users to overwrite them.
468+ headers.replaceAll(this .headers.build())
469+ queryParams.replaceAll(this .queryParams.build())
467470 apiKey.let {
468471 if (! it.isEmpty()) {
469- headers.put (" Authorization" , " Bearer $it " )
472+ headers.replace (" Authorization" , " Bearer $it " )
470473 }
471474 }
472- headers.replaceAll(this .headers.build())
473- queryParams.replaceAll(this .queryParams.build())
474475
475476 return ClientOptions (
476477 httpClient,
Original file line number Diff line number Diff line change @@ -16,6 +16,29 @@ internal class ClientOptionsTest {
1616
1717 private val httpClient = mock<HttpClient >()
1818
19+ @Test
20+ fun putHeader_canOverwriteDefaultHeader () {
21+ val clientOptions =
22+ ClientOptions .builder()
23+ .httpClient(httpClient)
24+ .putHeader(" User-Agent" , " My User Agent" )
25+ .apiKey(" My API Key" )
26+ .build()
27+
28+ assertThat(clientOptions.headers.values(" User-Agent" )).containsExactly(" My User Agent" )
29+ }
30+
31+ @Test
32+ fun toBuilder_apiKeyAuthCanBeUpdated () {
33+ var clientOptions =
34+ ClientOptions .builder().httpClient(httpClient).apiKey(" My API Key" ).build()
35+
36+ clientOptions = clientOptions.toBuilder().apiKey(" another My API Key" ).build()
37+
38+ assertThat(clientOptions.headers.values(" Authorization" ))
39+ .containsExactly(" Bearer another My API Key" )
40+ }
41+
1942 @Test
2043 fun toBuilder_whenOriginalClientOptionsGarbageCollected_doesNotCloseOriginalClient () {
2144 var clientOptions =
You can’t perform that action at this time.
0 commit comments