apply proxy mask to the host only

This commit is contained in:
yggverse 2025-10-09 23:06:23 +03:00
parent b9e809fac9
commit a47abac138
2 changed files with 25 additions and 24 deletions

View file

@ -1,7 +1,7 @@
use gtk::{ use gtk::{
Align, Box, Button, Entry, Switch,
glib::{DateTime, GString}, glib::{DateTime, GString},
prelude::{BoxExt, ButtonExt, EditableExt, WidgetExt}, prelude::{BoxExt, ButtonExt, EditableExt, WidgetExt},
Align, Box, Button, Entry, Switch,
}; };
pub struct Row { pub struct Row {
@ -35,7 +35,7 @@ impl Row {
let request = Entry::builder() let request = Entry::builder()
.hexpand(true) .hexpand(true)
.placeholder_text("Request") .placeholder_text("Host")
.text(request.unwrap_or(".*")) .text(request.unwrap_or(".*"))
.tooltip_text("Supports regex expressions") .tooltip_text("Supports regex expressions")
.build(); .build();
@ -79,8 +79,8 @@ impl Row {
let c = std::rc::Rc::new(on_delete); let c = std::rc::Rc::new(on_delete);
move |this| { move |this| {
use adw::{ use adw::{
AlertDialog, ResponseAppearance,
prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual}, prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual},
AlertDialog, ResponseAppearance,
}; };
const RESPONSE_CONFIRM: (&str, &str) = ("confirm", "Confirm"); const RESPONSE_CONFIRM: (&str, &str) = ("confirm", "Confirm");

View file

@ -484,12 +484,15 @@ fn refresh_proxy_resolver(
) { ) {
const NONE: &[&str] = &[]; const NONE: &[&str] = &[];
let t = entry.text(); // allocate once // apply condition only to valid host found in the request entry
// * in other case, the raw request string may include just user input
match profile.proxy.matches(&t) { // which may contain another 'host' in the request substring after '?'
Some(m) => { if let Some(u) = uri(entry)
let (css_classes, tooltip_text) = match m.lookup(&t, Cancellable::NONE) { && let Some(h) = u.host()
Ok(h) => (&["accent"], format!("Proxy over {}", h.join(","))), && let Some(m) = profile.proxy.matches(&h)
{
let (css_classes, tooltip_text) = match m.lookup(&entry.text(), Cancellable::NONE) {
Ok(r) => (&["accent"], format!("Proxy over {}", r.join(","))),
Err(i) => (&["error"], i.to_string()), Err(i) => (&["error"], i.to_string()),
}; };
entry.set_css_classes(if profile.proxy.misc.is_highlight_request_entry() { entry.set_css_classes(if profile.proxy.misc.is_highlight_request_entry() {
@ -499,11 +502,9 @@ fn refresh_proxy_resolver(
}); });
entry.set_tooltip_text(Some(&tooltip_text)); entry.set_tooltip_text(Some(&tooltip_text));
resolver.replace(Some(m)); resolver.replace(Some(m));
} } else {
None => {
entry.set_css_classes(NONE); entry.set_css_classes(NONE);
entry.set_tooltip_text(None); entry.set_tooltip_text(None);
resolver.replace(None); resolver.replace(None);
} }
} }
}