message: proxy: Handle response headers
diff: @@ -6,7 +6,7 @@ use chrono::prelude::*;
  use hyper2::client::{HttpConnector, ResponseFuture};
  use hyper2::header::{HeaderMap, HeaderName, HeaderValue};
  use hyper2::service::{make_service_fn, service_fn};
  -use hyper2::{Body, Client, Request, Server, Uri};
  +use hyper2::{Body, Client, Request, Response, Server, Uri};
  use hyper_tls2::HttpsConnector;
  @@ -22,6 +22,7 @@ use crate::settings::target::Target;
  use crate::commands::preview::upload;
  const PREVIEW_HOST: &str = "rawhttp.cloudflareworkers.com";
  +const HEADER_PREFIX: &str = "cf-ew-raw-";
  #[derive(Clone)]
  struct ProxyConfig {
  @@ -99,12 +100,32 @@ pub async fn proxy(
  let proxy_config = proxy_config.clone();
  async move {
  Ok::<_, failure::Error>(service_fn(move |req| {
  - preview_request(
  - req,
  - client.to_owned(),
  - preview_id.to_owned(),
  - proxy_config.clone(),
  - )
  + let client = client.to_owned();
  + let preview_id = preview_id.to_owned();
  + let proxy_config = proxy_config.clone();
  + async move {
  + let resp = preview_request(req, client, preview_id, proxy_config).await?;
  +
  + let (mut parts, body) = resp.into_parts();
  +
  + let mut headers = HeaderMap::new();
  +
  + for header in &parts.headers {
  + let (name, value) = header;
  + let name = name.as_str();
  + if name.starts_with(HEADER_PREFIX) {
  + let header_name = &name[HEADER_PREFIX.len()..];
  + // TODO: remove unwrap
  + let header_name =
  + HeaderName::from_bytes(header_name.as_bytes()).unwrap();
  + headers.insert(header_name, value.clone());
  + }
  + }
  + parts.headers = headers;
  +
  + let resp = Response::from_parts(parts, body);
  + Ok::<_, failure::Error>(resp)
  + }
  }))
  }
  });
  @@ -145,7 +166,7 @@ fn preview_request(
  for header in &parts.headers {
  let (name, value) = header;
  - let forward_header = format!("cf-ew-raw-{}", name);
  + let forward_header = format!("{}{}", HEADER_PREFIX, name);
  // TODO: remove unwrap
  let header_name = HeaderName::from_bytes(forward_header.as_bytes()).unwrap();
  headers.insert(header_name, value.clone());
  