HttpExchange

interface HttpExchange<T>(source)

One logical call of a protocol, which may need more than one HTTP request, e.g. to fetch an attestation challenge or to retry with a nonce the server asked for. The method returning the exchange documents which ProtocolRequests it sends.

Call next without a response first, then send every HttpStep.Send.request and pass its response to next, until the exchange returns HttpStep.Done:

var step = exchange.next().getOrThrow()
while (step is HttpStep.Send) step = exchange.next(send(step.request.http)).getOrThrow()
return (step as HttpStep.Done).value

An exchange can be used only once, and is not thread-safe. It fails with HttpErrorResponseException for a non-success response once no retry applies, and cannot be used after any failure.

Functions

Link copied to clipboard
abstract suspend fun next(response: ReceivedHttpResponse? = null): KmmResult<HttpStep<T>>