feat: support file:// URL scheme for local HTML testing

Allow loading local HTML/CSS/JS files via the file:// protocol,
enabling Obscura to be used for testing static sites without
running a local HTTP server.

Changes:
- Allow "file" scheme in validate_url() and validate_fetch_url()
- Add fetch_file_url() to read local files and return synthetic
  HTTP responses with appropriate content-type headers
- Skip private IP / localhost checks for file:// URLs

Closes #16
This commit is contained in:
ben1009 committed 2026-04-25 00:18:31 +08:00
1 parent b00a1f20e7
commit 21136ca819
2 files changed
+51 -4

No files matched your search

+6 -2
View File
@@ -551,13 +551,17 @@ fn glob_match(pattern: &str, url: &str) -> bool {
fn validate_fetch_url(url: &url::Url) -> Result<(), String> {
let scheme = url.scheme();
if scheme != "http" && scheme != "https" {
if scheme != "http" && scheme != "https" && scheme != "file" {
return Err(format!(
"Forbidden URL scheme '{}' - only http and https are allowed",
"Forbidden URL scheme '{}' - only http, https, and file are allowed",
scheme
));
}
if scheme == "file" {
return Ok(());
}
if let Some(host) = url.host() {
match host {
url::Host::Ipv4(ip) => {