Skip to content

Commit

Permalink
Refactor scheme_host_port function to simplify HTTP/2 handling
Browse files Browse the repository at this point in the history
  • Loading branch information
arloor committed Sep 19, 2024
1 parent 21242de commit 5c90a86
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions rust_http_proxy/src/web_func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,11 @@ fn incr_counter_if_need(
}
}

fn extract_search_engine_from_referer(referer: &str) -> io::Result<String> {
if let Some(caps) = Regex::new("^https?://(.+?)(/|$)")
.map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?
.captures(referer)
{
fn extract_search_engine_from_referer(referer: &str) -> Result<String, regex::Error> {
if let Some(caps) = Regex::new("^https?://(.+?)(/|$)")?.captures(referer) {
let address = caps.get(1).map_or(referer, |g| g.as_str());
if let Some(caps) =
Regex::new("(google|baidu|bing|yandex|v2ex|github|stackoverflow|duckduckgo)")
.map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?
Regex::new("(google|baidu|bing|yandex|v2ex|github|stackoverflow|duckduckgo)")?
.captures(address)
{
Ok(caps.get(1).map_or(address, |g| g.as_str()).to_string())
Expand Down

0 comments on commit 5c90a86

Please sign in to comment.