Skip to content

Commit

Permalink
Merge pull request #108 from ngrok/josh/forward-urls-tls
Browse files Browse the repository at this point in the history
Switch to forwarding based on URL and add TLS forwarding
  • Loading branch information
jrobsonchase authored Aug 29, 2023
2 parents fc54e72 + e55db75 commit d5e36c1
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 179 deletions.
3 changes: 2 additions & 1 deletion ngrok/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ngrok"
version = "0.14.0-pre.2"
version = "0.14.0-pre.3"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "The ngrok agent SDK"
Expand Down Expand Up @@ -32,6 +32,7 @@ regex = "1.7.3"
tokio-socks = "0.5.1"
hyper-proxy = "0.9.1"
url = "2.4.0"
rustls-native-certs = "0.6.3"

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.45.0", features = ["Win32_Foundation"] }
Expand Down
15 changes: 6 additions & 9 deletions ngrok/examples/mingrok.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use futures::{
use ngrok::prelude::*;
use tokio::sync::oneshot;
use tracing::info;
use url::Url;

#[tokio::main]
async fn main() -> Result<(), Error> {
Expand All @@ -21,7 +22,8 @@ async fn main() -> Result<(), Error> {

let forwards_to = std::env::args()
.nth(1)
.ok_or_else(|| anyhow::anyhow!("missing forwarding address"))?;
.ok_or_else(|| anyhow::anyhow!("missing forwarding address"))
.and_then(|s| Ok(Url::parse(&s)?))?;

loop {
let (stop_tx, stop_rx) = oneshot::channel();
Expand Down Expand Up @@ -55,18 +57,13 @@ async fn main() -> Result<(), Error> {
.connect()
.await?
.http_endpoint()
.forwards_to(&forwards_to)
.forwards_to(forwards_to.as_str())
.listen()
.await?;

info!(url = tun.url(), forwards_to, "started tunnel");
info!(url = tun.url(), %forwards_to, "started tunnel");

let mut fut = if forwards_to.contains('/') {
tun.forward_pipe(&forwards_to)
} else {
tun.forward_http(&forwards_to)
}
.fuse();
let mut fut = TunnelExt::forward(&mut tun, forwards_to.clone()).fuse();

let mut stop_rx = stop_rx.fuse();
let mut restart_rx = restart_rx.fuse();
Expand Down
6 changes: 6 additions & 0 deletions ngrok/src/tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ macro_rules! tunnel_trait {
fn forwards_to(&self) -> &str;
/// Returns the arbitrary metadata string for this tunnel.
fn metadata(&self) -> &str;
/// Returns the protocol for this tunnel.
fn proto(&self) -> &str;
/// Close the tunnel.
///
/// This is an RPC call that must be `.await`ed.
Expand Down Expand Up @@ -286,6 +288,10 @@ macro_rules! make_tunnel_type {
fn metadata(&self) -> &str {
self.inner.metadata()
}

fn proto(&self) -> &str {
self.inner.proto()
}
}

impl $wrapper {
Expand Down
Loading

0 comments on commit d5e36c1

Please sign in to comment.