#vpn #hyper-http #wireguard #tunnel #hyper

wireguard-hyper-connector

Hyper connector for making HTTP requests through a WireGuard tunnel

2 unstable releases

0.2.0 Dec 14, 2025
0.1.0 Dec 8, 2025

#492 in HTTP client

GPL-3.0 license

105KB
2K SLoC

Hyper connector for making HTTP requests through a WireGuard tunnel.

This crate provides WgConnector, a tower::Service implementation that creates HTTP connections through a WireGuard tunnel.

DNS Configuration

You can configure different DNS servers for pre-connection (endpoint resolution) and post-connection (HTTP request DNS resolution) using DohServerConfig:

use wireguard_hyper_connector::{WgConnector, ManagedTunnel, WgConfigFile, DohServerConfig};
use hyper_util::client::legacy::Client;
use hyper_util::rt::TokioExecutor;
use http_body_util::Empty;
use bytes::Bytes;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Use Google DNS for resolving WireGuard endpoint
    let config = WgConfigFile::from_file("wg.conf")?
        .into_wireguard_config_with_dns(DohServerConfig::google())
        .await?;
    
    let tunnel = ManagedTunnel::connect(config).await?;
    
    // Use Quad9 DNS for HTTP requests through the tunnel
    let connector = WgConnector::with_dns(tunnel.netstack(), DohServerConfig::quad9());
    
    let client: Client<WgConnector, Empty<Bytes>> = Client::builder(TokioExecutor::new()).build(connector);
    
    // Make requests...
    
    tunnel.shutdown().await;
    Ok(())
}

Example (Default DNS)

use wireguard_hyper_connector::{WgConnector, ManagedTunnel, WgConfigFile};
use hyper_util::client::legacy::Client;
use hyper_util::rt::TokioExecutor;
use http_body_util::Empty;
use bytes::Bytes;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Load config and connect (uses Cloudflare DNS by default)
    let config = WgConfigFile::from_file("wg.conf")?
        .into_wireguard_config()
        .await?;
    
    let tunnel = ManagedTunnel::connect(config).await?;
    
    // Create the hyper connector (uses Cloudflare DNS by default)
    let connector = WgConnector::new(tunnel.netstack());
    
    // Create a hyper client
    let client: Client<WgConnector, Empty<Bytes>> = Client::builder(TokioExecutor::new()).build(connector);
    
    // Make requests...
    
    tunnel.shutdown().await;
    Ok(())
}

Dependencies

~31–49MB
~773K SLoC