Handle HeaderValue and Uri parsing errors

This commit is contained in:
spikecodes
2021-03-17 16:32:28 -07:00
parent b14b4ff551
commit fb7faf6477
3 changed files with 34 additions and 7 deletions

View File

@ -21,7 +21,7 @@ mod utils;
use clap::{App as cli, Arg};
use futures_lite::FutureExt;
use hyper::{Body, Request, Response};
use hyper::{header::HeaderValue, Body, Request, Response};
mod client;
use client::proxy;
@ -73,7 +73,12 @@ async fn resource(body: &str, content_type: &str, cache: bool) -> Result<Respons
.unwrap_or_default();
if cache {
res.headers_mut().insert("Cache-Control", "public, max-age=1209600, s-maxage=86400".parse().unwrap());
match HeaderValue::from_str("public, max-age=1209600, s-maxage=86400") {
Ok(val) => {
res.headers_mut().insert("Cache-Control", val);
}
Err(_) => (),
}
}
Ok(res)