Can no longer combine with tower-http's RequestDecompression #2687
-
SummaryWorked in axum 0.6: fn route_influxdb<S>(influxdb_handler: InfluxdbLineProtocolHandlerRef) -> Router<S> {
Router::new()
.route("/write", routing::post(influxdb_write_v1))
.route("/api/v2/write", routing::post(influxdb_write_v2))
.layer(
ServiceBuilder::new()
.layer(HandleErrorLayer::new(handle_error))
.layer(RequestDecompressionLayer::new()),
)
.route("/ping", routing::get(influxdb_ping))
.route("/health", routing::get(influxdb_health))
.with_state(influxdb_handler)
}
async fn handle_error(err: BoxError) -> Json<HttpResponse> {
error!(err; "Unhandled internal error");
Json(HttpResponse::Error(ErrorResponse::from_error_message(
StatusCode::Unexpected,
format!("Unhandled internal error: {err}"),
)))
} But on axum 0.7:
axum version0.7.4 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I just dealt with this problem. In fact with the new version, the code is greatly simplified. First note that you have to depend on tower-http v0.5 and tower v0.4. Next, you no longer need: .layer(
ServiceBuilder::new()
.layer(HandleErrorLayer::new(handle_error))
.layer(RequestDecompressionLayer::new()),
) instead just write something like: .layer(RequestDecompressionLayer::new().gzip(true)) I think it's because With regard to the handlers, |
Beta Was this translation helpful? Give feedback.
I just dealt with this problem. In fact with the new version, the code is greatly simplified.
First note that you have to depend on tower-http v0.5 and tower v0.4.
Next, you no longer need:
instead just write something like:
I think it's because
RequestDecompressionLayer
is infallible now, and so no longer needs an error handling layer. The decompression error, if any, is propagated to reading the data from the request body.With regard to the handlers,
p…