cloudwego / volo

Rust RPC framework with high-performance and strong-extensibility for building micro-services.
https://crates.io/crates/volo
Apache License 2.0
2.13k stars 166 forks source link

feat(volo-http): impl IntoResponse for Json and Form #441

Closed wfly1998 closed 1 month ago

wfly1998 commented 1 month ago

Motivation

Previously, there were impl TryFrom<Json> for Body and impl IntoResponse for T where T: TryInto<Body>, so Json was deduced as impl IntoResponse. However, Content-Type was not inserted in IntoResponse, which may cause problems.

Solution

This PR implements IntoResponse for Json and Form, and inserts Content-Type in the header. To avoid compilation issues, TryFrom<Json<T>> for Body has been removed. When the client needs to send json, users can call json directly without calling data and manually inserting the header.