Support short IDs for non-ASCII posts

This commit is contained in:
spikecodes 2022-11-04 19:54:14 -07:00
parent e22404bf03
commit ab91e29821
No known key found for this signature in database
GPG Key ID: 004CECFF9B463BCB
1 changed files with 10 additions and 7 deletions

View File

@ -42,13 +42,16 @@ pub async fn canonical_path(path: String) -> Result<Option<String>, String> {
return Ok(None);
}
match res.headers().get(header::LOCATION) {
None => Ok(None),
Some(hdr) => match hdr.to_str() {
Ok(val) => Ok(Some(val.to_string().trim_start_matches(REDDIT_URL_BASE).to_string())),
Err(e) => Err(e.to_string()),
},
}
Ok(
res
.headers()
.get(header::LOCATION)
.map(|val| percent_encode(val.as_bytes(), CONTROLS)
.to_string()
.trim_start_matches(REDDIT_URL_BASE)
.to_string()
),
)
}
pub async fn proxy(req: Request<Body>, format: &str) -> Result<Response<Body>, String> {