Files
shadowsocks-rust/tests/http.rs
T
ty 303f96c61f Upgrade to tokio 1.0 (#358)
* upgrade to tokio v1.0

- removed tokio::prelude
- upgrade hyper to v0.14, tokio-rustls to v0.22

still working on migrating trust-dns-* and tokio-native-tls

ref #354

* tokio v1.0 removed with_poll

fix #355, ref #354

* removed CTRL-BREAK signal handler

ref #354

* fixes compliation error, add missing return

fixes #355

* allow setting SO_SNDBUF and SO_RCVBUF for sockets

ref #352

* completely removed unix socket based DNS resolving

ref shadowsocks/shadowsocks-android#2622

* fix build issue on Windows

* fixed uds poll_write loop, fixed udp outbound loopback check

ref #355

* disable default trust-dns resolver for andorid, macos, ios

This commit also:

- Optimized resolve() logging with elapsed time
- updated tokio-native-tls

* local-dns removed from default features

* fix rustc version with rust-toolchain

* Bump bytes from 0.6.0 to 1.0.0

* add dependabot badge

* indirectly depend on trust_dns_proto via trust_dns_resolver

* auto reconnect if udp sendto failed

* recreate proxied socket if recv() returns failure

* increase score precision to 0.0001

* example of log4rs configuration

* PingBalancer instance shouldn't kill probing task when dropping

- Probing task should be controlled by the internal shared state

* switch to trust-dns main for latest tokio 1.0 support
2020-12-28 10:10:19 +08:00

82 lines
2.1 KiB
Rust

#![cfg(all(feature = "local-http", feature = "server"))]
use std::time::Duration;
use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
net::TcpStream,
time,
};
use shadowsocks_service::{
config::{Config, ConfigType, ProtocolType},
run_local,
run_server,
};
#[tokio::test]
async fn http_proxy() {
let _ = env_logger::try_init();
let mut local_config = Config::load_from_str(
r#"{
"local_port": 5110,
"local_address": "127.0.0.1",
"server": "127.0.0.1",
"server_port": 5120,
"password": "password",
"method": "aes-256-gcm"
}"#,
ConfigType::Local,
)
.unwrap();
local_config.local_protocol = ProtocolType::Http;
let server_config = Config::load_from_str(
r#"{
"server": "127.0.0.1",
"server_port": 5120,
"password": "password",
"method": "aes-256-gcm"
}"#,
ConfigType::Server,
)
.unwrap();
tokio::spawn(run_local(local_config));
tokio::spawn(run_server(server_config));
time::sleep(Duration::from_secs(1)).await;
{
let mut c = TcpStream::connect("127.0.0.1:5110").await.unwrap();
c.write_all(b"GET http://www.example.com/ HTTP/1.0\r\nHost: www.example.com\r\nAccept: */*\r\n\r\n")
.await
.unwrap();
c.flush().await.unwrap();
let mut buf = Vec::new();
c.read_to_end(&mut buf).await.unwrap();
assert!(buf.starts_with(b"HTTP/1.0 200 OK\r\n"));
}
{
let mut c = TcpStream::connect("127.0.0.1:5110").await.unwrap();
c.write_all(b"CONNECT http://www.example.com/ HTTP/1.0\r\n\r\n")
.await
.unwrap();
c.flush().await.unwrap();
c.write_all(b"GET / HTTP/1.0\r\nHost: www.example.com\r\nAccept: */*\r\n\r\n")
.await
.unwrap();
c.flush().await.unwrap();
let mut buf = Vec::new();
c.read_to_end(&mut buf).await.unwrap();
assert!(buf.starts_with(b"HTTP/1.0 200 OK\r\n"));
}
}