Scoop API

scoop:scoop.http.asyncio:0.1.0

src/http1_handoff.scoop

Selected production source · src/http1_handoff.scoop

1package scoop.http.asyncio
3import scoop.http.HttpRole
5internal 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.isSwitched
13 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 = true
17 state.closing = true
18 state.transportClosing = true
19 state.transportClosed = true
20 finishH1Close(state, actions)
21 result
22 }
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 transport