-
Notifications
You must be signed in to change notification settings - Fork 973
Description
Content previewing was implemented as a decorator to record the uncompressed content in conjunction with DecodingSevice and EncodingService. However, this approach may fail to capture the actual response sent over the wire. For example, a response generated by ServerErrorHandler cannot be previewed. Also, if a response is changed after ContentPreviewingService, the updated content is not reflected in RequestLog.responseContentPreview().
To address the limitation, we may need to configure ContentPreviewingFactory through server/service options (instead of using ContentPreviwingService) and record the previews internally at the Armeria transport layer. To recode decoded content consistently, compression/ decompression should also be configured via server/service options so that previewing happens after decompression and before compression.
decode request -> decompression -> content preview -> request decorators -> service ->
response decorators -> server error handler -> content preview -> compression -> write response
API proposal:
// Migrate EncodingServiceBuilder into CompressionBuilder
Compression compression =
Compression
.builder()
.encoderFactories(...)
.encodableContentTypes(...)
...
.build();
Server
.builder()
// Enabled by default
.decompress(streamDecoderFactories)
//
.compress(compression);
.contentPreview(contentPreviewerFactory)
.route().get("/get")
// Apply response compression at the service level
.compress(...)