Skip to content

How to: map hyper::Body to lambda_http::Body #456

Answered by metasim
metasim asked this question in Q&A
Discussion options

You must be logged in to vote

I think I cracked the nut (but welcome feedback if there's a better way!):

use lambda_http as LH;
use axum::http as AH;
use axum::body::BoxBody;
use hyper::body::to_bytes;

async fn lambda_http_response_from_axum(resp: AH::Response<BoxBody>) -> Result<LH::Response<LH::Body>, LH::Error> {
    let (head, body) = resp.into_parts();
    let raw = to_bytes(body).await?;
    let resp = LH::Response::from_parts(head, LH::Body::Binary(raw.to_vec()));
    Ok(resp)
}

Still need to properly handle content type....

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@bnusunny
Comment options

@metasim
Comment options

Answer selected by metasim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants