#sock #hyper #v5 #async #connector #future #11

hyper-socks-async

Socks V5 connector with TLS support for async hyper (>= 0.11)

1 unstable release

Uses old Rust 2015

0.1.0 Jan 10, 2018

#16 in #11

MIT license

9KB
122 lines

hyper-socks-async

Implements currently only socks V5 client with IPv4 but works with the current async hyper.

Doesn't support authentication or IPv6. Make an issue if you would need it..

MIT licensed

Installation

# Cargo.toml
[dependencies]
hyper-socks-async = "0.1.0"

Usage

Just configure hyper::Client with Socksv5Connector. Connector uses native-tls if url scheme is https.

Example below assumes you're running socks v5 compatible server on 127.0.0.1:9150. You can also run this example with cargo run --example client after cloning the project.

extern crate futures;
extern crate hyper;
extern crate hyper_socks_async;
extern crate tokio_core;

use futures::Future;
use futures::stream::Stream;
use hyper::Client;
use hyper_socks_async::Socksv5Connector;
use std::net::{SocketAddrV4, SocketAddr, Ipv4Addr};

fn main() {
    let mut core = tokio_core::reactor::Core::new().unwrap();
    
    // Proxy running on 127.0.0.1:9150
    let proxy_addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 9150));
    let client = Client::configure()
        .connector(Socksv5Connector::new(&core.handle(), proxy_addr))
        .build(&core.handle());

    // http://example.com or http://1.2.3.4 work as well
    let url = "https://ifconfig.co/json".parse::<hyper::Uri>().unwrap();
    let response_body = client.get(url)
        .and_then(|res| res.body().concat2());
    let bytes = core.run(response_body).expect("Request failed").to_vec();
    println!("Got: {}", String::from_utf8_lossy(&bytes));
}

Dependencies

~8–17MB
~199K SLoC