hyper-socks-async

Crates.iohyper-socks-async
lib.rshyper-socks-async
version0.1.0
sourcesrc
created_at2018-01-10 17:31:11.506795
updated_at2018-01-10 17:31:11.506795
descriptionSocks V5 connector with TLS support for async hyper (>= 0.11)
homepage
repositoryhttps://github.com/vvilhonen/hyper-socks-async
max_upload_size
id46254
size10,708
Vesa Vilhonen (vvilhonen)

documentation

README

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));
}
Commit count: 13

cargo fmt