scoop:scoop.http.asyncio:0.1.0
src/http1_handoff.scoop
Selected production source · src/http1_handoff.scoop
1
package scoop.http.asyncio3
import scoop.http.HttpRole5
internal suspend fun handoffH1(state: H1State): HttpTransport {6
httpJob(state.loop, true)7
val actions = ArrayList<() -> Unit>()8
val transport = state.lock.withLock {9
h1Open(state)10
if (state.readBusy || state.writeBusy || present(state.incoming) || present(state.outgoing))11
throw IllegalStateException(Some("HTTP/1 operation or body is not complete"))12
val switched = if (state.encoder.role == HttpRole.Server) state.encoder.isSwitched else state.decoder.isSwitched13
if (!switched)14
throw IllegalStateException(Some("HTTP/1 has not switched protocols"))15
val result = HttpTransport(state.transport, state.owner, state.loop, state.input.readBytes(state.input.readableBytes))16
state.detached = true17
state.closing = true18
state.transportClosing = true19
state.transportClosed = true20
finishH1Close(state, actions)21
result22
}23
for (action in actions) action()24
val failure = state.lock.withLock { state.closeFailure }25
if (present(failure)) {26
try { transport.close() }27
catch (cleanup: Throwable) { throw ResourceUseException(failure!!, cleanup) }28
throw failure!!29
}30
return transport31
}