File tree Expand file tree Collapse file tree
main/kotlin/com/browserbase/api/core
test/kotlin/com/browserbase/api/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -485,23 +485,24 @@ private constructor(
485485 headers.put(" X-Stainless-Runtime" , " JRE" )
486486 headers.put(" X-Stainless-Runtime-Version" , getJavaVersion())
487487 headers.put(" X-Stainless-Kotlin-Version" , KotlinVersion .CURRENT .toString())
488+ // We replace after all the default headers to allow end-users to overwrite them.
489+ headers.replaceAll(this .headers.build())
490+ queryParams.replaceAll(this .queryParams.build())
488491 browserbaseApiKey.let {
489492 if (! it.isEmpty()) {
490- headers.put (" x-bb-api-key" , it)
493+ headers.replace (" x-bb-api-key" , it)
491494 }
492495 }
493496 browserbaseProjectId.let {
494497 if (! it.isEmpty()) {
495- headers.put (" x-bb-project-id" , it)
498+ headers.replace (" x-bb-project-id" , it)
496499 }
497500 }
498501 modelApiKey.let {
499502 if (! it.isEmpty()) {
500- headers.put (" x-model-api-key" , it)
503+ headers.replace (" x-model-api-key" , it)
501504 }
502505 }
503- headers.replaceAll(this .headers.build())
504- queryParams.replaceAll(this .queryParams.build())
505506
506507 return ClientOptions (
507508 httpClient,
Original file line number Diff line number Diff line change @@ -16,6 +16,37 @@ 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+ .browserbaseApiKey(" My Browserbase API Key" )
26+ .browserbaseProjectId(" My Browserbase Project ID" )
27+ .modelApiKey(" My Model API Key" )
28+ .build()
29+
30+ assertThat(clientOptions.headers.values(" User-Agent" )).containsExactly(" My User Agent" )
31+ }
32+
33+ @Test
34+ fun toBuilder_bbApiKeyAuthCanBeUpdated () {
35+ var clientOptions =
36+ ClientOptions .builder()
37+ .httpClient(httpClient)
38+ .browserbaseApiKey(" My Browserbase API Key" )
39+ .browserbaseProjectId(" My Browserbase Project ID" )
40+ .modelApiKey(" My Model API Key" )
41+ .build()
42+
43+ clientOptions =
44+ clientOptions.toBuilder().browserbaseApiKey(" another My Browserbase API Key" ).build()
45+
46+ assertThat(clientOptions.headers.values(" x-bb-api-key" ))
47+ .containsExactly(" another My Browserbase API Key" )
48+ }
49+
1950 @Test
2051 fun toBuilder_whenOriginalClientOptionsGarbageCollected_doesNotCloseOriginalClient () {
2152 var clientOptions =
You can’t perform that action at this time.
0 commit comments