Skip to content

Commit

Permalink
Merge pull request #10 from kozakura913/main
Browse files Browse the repository at this point in the history
不正なUTF-8文字を含むHTMLでも可能な限り読み込む
  • Loading branch information
kozakura913 authored Apr 27, 2024
2 parents ea2eab9 + ffd2cb0 commit 13e9d32
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,7 @@ async fn get_file(
(dst,_,_)=encoding.decode(&v);
}
let s=if dst.is_empty(){
//strはutf8表現なのでゼロコピー操作
let s=match std::str::from_utf8(&v){
Ok(s)=>s,
Err(e)=>{
let mut headers=axum::http::HeaderMap::new();
headers.append("X-Proxy-Error",e.to_string().parse().unwrap());
return (axum::http::StatusCode::BAD_GATEWAY,headers).into_response()
},
};
Cow::Borrowed(s)
String::from_utf8_lossy(&v)
}else{
dst
};
Expand Down

0 comments on commit 13e9d32

Please sign in to comment.