Skip to content

How to modify the body of a post before forwarding the request? #48

Answered by danielSanchezQ
gpfeifer asked this question in Q&A
Discussion options

You must be logged in to vote

@gpfeifer

Leveraging from the docs example, you can wrap the forwarding call in a closure for example and modify whatever you need:

use warp::Filter;
use warp::hyper::Body;
use warp_reverse_proxy::{extract_request_data_filter, proxy_to_and_forward_response, Headers};

#[tokio::main]
async fn main() {
    let hello = warp::path!("hello" / String).map(|name| format!("Hello port, {}!", name));

    // // spawn base server
    tokio::spawn(warp::serve(hello).run(([0, 0, 0, 0], 8080)));

    let request_filter = extract_request_data_filter();
    let app = warp::path!("hello")
        // build the request with data from previous filters
        .and(request_filter)
        .and_then(|path, query,

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
9 replies
@danielSanchezQ
Comment options

@rahulmr
Comment options

@rahulmr
Comment options

@rahulmr
Comment options

@danielSanchezQ
Comment options

Answer selected by gpfeifer
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #46 on October 20, 2021 07:45.