Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Allow custom request timeouts to be passed to OkHttp client (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
finn-block committed Jan 16, 2024
1 parent fe212cb commit ce9307c
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import tbdex.sdk.protocol.models.Offering
import tbdex.sdk.protocol.serialization.Json
import tbdex.sdk.protocol.serialization.Json.jsonMapper
import web5.sdk.dids.Did
import java.time.Duration

/**
* A client of the tbDEX HTTP interface for communicating with a PFI.
*/
object TbdexHttpClient {
private val client = OkHttpClient()
private var client = OkHttpClient()
private val jsonMediaType = "application/json; charset=utf-8".toMediaType()
private const val JSON_HEADER = "application/json"

Expand Down Expand Up @@ -180,6 +181,15 @@ object TbdexHttpClient {
}
}

/**
* Sets the timeout for all future HTTP requests
*
* @param timeout the total time to allow HTTP requests to take before they are considered timed out
*/
fun setTimeout(timeout: Duration) {
client = OkHttpClient.Builder().callTimeout(timeout).build();

Check warning on line 190 in httpclient/src/main/kotlin/tbdex/sdk/httpclient/TbdexHttpClient.kt

View check run for this annotation

Codecov / codecov/patch

httpclient/src/main/kotlin/tbdex/sdk/httpclient/TbdexHttpClient.kt#L190

Added line #L190 was not covered by tests
}

/**
* Builds an error response based on the provided HTTP response.
*
Expand Down

0 comments on commit ce9307c

Please sign in to comment.