message: Split out response header munging to separate function
diff: @@ -7,6 +7,7 @@ use hyper::client::{HttpConnector, ResponseFuture};
  use hyper::header::{HeaderMap, HeaderName, HeaderValue};
  use hyper::service::{make_service_fn, service_fn};
  use hyper::{Body, Client, Request, Response, Server, Uri};
  +use hyper::http::response::Parts;
  use hyper::http::uri::InvalidUri;
  use hyper_tls::HttpsConnector;
  @@ -56,18 +57,7 @@ pub async fn dev(
  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()..];
  - let header_name = HeaderName::from_bytes(header_name.as_bytes())?;
  - headers.insert(header_name, value.clone());
  - }
  - }
  - parts.headers = headers;
  + munge_response_headers(&mut parts)?;
  let resp = Response::from_parts(parts, body);
  Ok::<_, failure::Error>(resp)
  @@ -84,6 +74,22 @@ pub async fn dev(
  Ok(())
  }
  +fn munge_response_headers(parts: &mut Parts) -> Result<(), failure::Error> {
  + 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()..];
  + let header_name = HeaderName::from_bytes(header_name.as_bytes())?;
  + headers.insert(header_name, value.clone());
  + }
  + }
  + parts.headers = headers;
  + Ok(())
  +}
  +
  fn get_preview_url(path_string: &str) -> Result<Uri, InvalidUri> {
  format!("https://{}{}", PREVIEW_HOST, path_string).parse()
  }
  