title: Append data to proxied response in Actix-web
body: <p>I would like to append user's request data to peroxided response in <code>actix-web</code>, but <code>type mismatch resolving</code> error will happend.</p>
  
  <p>I think it's about rust futures but I don't have idea about this problem and how can I fix it.</p>
  
  <p>Sample Code :</p>
  
  <pre><code>use actix_web::*;
  use futures::future::ok;
  use futures::Future;
  
  fn show_request(
      request: &amp;actix_web::HttpRequest,
  ) -&gt; Box&lt;Future&lt;Item = HttpResponse, Error = Error&gt;&gt; {
      let mut result: Vec&lt;u8&gt; = Vec::new();
      Box::new(request.body().map_err(|e| e.into()).map(move |f| {
          result.extend(f); 
          client::ClientRequest::get("http://example.com/")
              .finish().unwrap()
              .send()
              .map_err(Error::from)
              .and_then(
                  |resp| resp.body() 
                      .from_err()  
                      .and_then(|body| { 
                          result.extend(body); // append request body to response proxied site
                          Ok(HttpResponse::Ok().body(result))
                      }))
  
  
      }))
  }
  
  pub fn index(scope: actix_web::Scope&lt;()&gt;) -&gt; actix_web::Scope&lt;()&gt; {
      scope.handler("", |req: &amp;actix_web::HttpRequest| {
          show_request(req)
      })
  }
  
  fn main() {
      actix_web::server::new(|| {
          vec![
              actix_web::App::new()
                  .scope("", index)
                  .boxed(),
  
          ]
      }).bind("127.0.0.1:8000")
          .expect("Can not bind to port 8000")
          .run();
  }
  </code></pre>
  
  <p>Cargo.toml</p>
  
  <pre><code>[package]
  name = "temp"
  version = "0.1.0"
  authors = ["John"]
  edition = "2018"
  
  [dependencies]
  actix-web = "0.7"
  futures = "0.1"
  </code></pre>
  
  <p>Shown error :</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0271]: type mismatch resolving `&lt;[closure@src/main.rs:9:55: 24:6 result:_] as std::ops::FnOnce&lt;(bytes::bytes::Bytes,)&gt;&gt;::Output == actix_web::httpresponse::HttpResponse`
    --&gt; src/main.rs:9:5
     |
  9  | /     Box::new(request.body().map_err(|e| e.into()).map(move |f| {
  10 | |         result.extend(f);
  11 | |         client::ClientRequest::get("http://example.com/")
  12 | |             .finish().unwrap()
  ...  |
  23 | |
  24 | |     }))
     | |_______^ expected struct `futures::future::and_then::AndThen`, found struct `actix_web::httpresponse::HttpResponse`
     |
     = note: expected type `futures::future::and_then::AndThen&lt;futures::future::map_err::MapErr&lt;actix_web::client::pipeline::SendRequest, fn(actix_web::client::pipeline::SendRequestError) -&gt; actix_web::error::Error {&lt;actix_web::error::Error as std::convert::From&lt;actix_web::client::pipeline::SendRequestError&gt;&gt;::from}&gt;, futures::future::and_then::AndThen&lt;futures::future::from_err::FromErr&lt;actix_web::httpmessage::MessageBody&lt;actix_web::client::response::ClientResponse&gt;, actix_web::error::Error&gt;, std::result::Result&lt;actix_web::httpresponse::HttpResponse, actix_web::error::Error&gt;, [closure@src/main.rs:18:19: 21:10 result:_]&gt;, [closure@src/main.rs:16:8: 21:11 result:_]&gt;`
                found type `actix_web::httpresponse::HttpResponse`
     = note: required because of the requirements on the impl of `futures::future::Future` for `futures::future::map::Map&lt;futures::future::map_err::MapErr&lt;actix_web::httpmessage::MessageBody&lt;actix_web::httprequest::HttpRequest&gt;, [closure@src/main.rs:9:37: 9:49]&gt;, [closure@src/main.rs:9:55: 24:6 result:_]&gt;`
     = note: required for the cast to the object type `dyn futures::future::Future&lt;Error=actix_web::error::Error, Item=actix_web::httpresponse::HttpResponse&gt;
  </code></pre>