Fix client.rs - properly return Err on invalid header (fix #28)

This commit is contained in:
Matthew Esposito 2024-01-19 18:57:19 -05:00
parent 0f148c58d3
commit fcde6ff689
No known key found for this signature in database

View File

@ -56,7 +56,9 @@ pub async fn canonical_path(path: String) -> Result<Option<String>, String> {
// If Reddit responds with a 301, then the path is redirected. // If Reddit responds with a 301, then the path is redirected.
301 => match res.headers().get(header::LOCATION) { 301 => match res.headers().get(header::LOCATION) {
Some(val) => { Some(val) => {
let original = val.to_str().unwrap(); let Some(original) = val.to_str().ok() else {
return Err("Unable to decode Location header.".to_string());
};
// We need to strip the .json suffix from the original path. // We need to strip the .json suffix from the original path.
// In addition, we want to remove share parameters. // In addition, we want to remove share parameters.
// Cut it off here instead of letting it propagate all the way // Cut it off here instead of letting it propagate all the way