Kotlin
Ktor Pipeline, PipelinePhase
nodeal
2023. 8. 26. 18:21
반응형
Pipeline을 갖는 component는 Engine, Application, Routing, Route가 있다.
각 component의 기본 phase는 다음이 있다:
| Engine | EnginePipeline | before |
| call | ||
| after | ||
| ApplicationReceivePipeline | Before | |
| Transform | ||
| After | ||
| ApplicationSendPipeline | Before | |
| Transform | ||
| Render | ||
| ContentEncoding | ||
| TransferEncoding | ||
| After | ||
| Engine | ||
| Application | ApplicationCallPipeline | Setup |
| Monitoring | ||
| Plugins | ||
| Call | ||
| Fallback | ||
| ApplicationReceivePipeline | Before | |
| Transform | ||
| AfterTransform | ||
| After | ||
| ApplicationSendPipeline | Before | |
| Transform | ||
| Render | ||
| BodyTransformationCheckPostRender | ||
| ContentEncoding | ||
| TransferEncoding | ||
| After | ||
| Engine | ||
| Routing | ApplicationCallPipeline | Setup |
| Monitoring | ||
| Plugins | ||
| Call | ||
| Fallback | ||
| ApplicationReceivePipeline | Before | |
| Transform | ||
| After | ||
| ApplicationSendPipeline | Before | |
| Transform | ||
| Render | ||
| ContentEncoding | ||
| TransferEncoding | ||
| After | ||
| Engine | ||
| Route | ApplicationCallPipeline | Setup |
| Monitoring | ||
| Plugins | ||
| Call | ||
| Fallback | ||
| ApplicationReceivePipeline | Before | |
| Transform | ||
| After | ||
| ApplicationSendPipeline | Before | |
| Transform | ||
| Render | ||
| ContentEncoding | ||
| TransferEncoding | ||
| After | ||
| Engine |
요청이 들어왔을 때 실행 순서는 다음과 같다:
before: Engine
Setup: Application
Monitoring: Application
Plugins: Application
Call: Application
Setup: Routing > Route
Monitoring: Routing > Route
Plugins: Routing > Route
Call: Routing > Route
// Route body 시작
Route body에서 receive를 호출하면 ApplicationReceivePipeline이 실행된다.
Before: Engine > Application > Routing > Route
Transform: Engine > (DefaultTransform) > Application > (ContentNegotiation) > Routing > Route
AfterTransform: Application
After: Engine > Application > Routing > Route
// receive 끝
respond를 호출하면 ApplicationSendPipeline이 실행된다.
Before: Engine > Application > Routing > Route
Transform: Engine > Application > Routing > Route
Render: Engine > Application > Routing > Route
BodyTransformationCheckPostRender: Application
ContentEncoding: Engine > Application > Routing > Route
TransferEncoding: Engine > Application > Routing > Route
After: Engine > Application > Routing > Route
Engine: Engine > Application > Routing > Route
- ApplicationSendPipeline은 finish를 호출하거나 respond없이 route body가 종료될 때에도 호출된다.
Route body가 종료되면 ApplicationCallPipeline.Fallback이 실행된다.
Fallback: Routing > Route > Application
한 요청 처리가 모두 완료될 때 EnginePipeline의 나머지 phase가 실행된다.
Engine: call > After
// 요청 끝
반응형