1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-04 02:09:26 +02:00

Resolve AP through proxy as well

This commit is contained in:
Johan Anderholm 2018-03-23 16:52:24 +01:00
parent 3bdc5e0073
commit 1a04e3b899
6 changed files with 63 additions and 37 deletions

View file

@ -1,13 +1,13 @@
use std::error::Error;
use std::io;
use std::str::FromStr;
use futures::{Async, Future, Poll};
use httparse;
use std::io;
use std::net::SocketAddr;
use hyper::Uri;
use tokio_io::io::{read, write_all, Read, Window, WriteAll};
use tokio_io::{AsyncRead, AsyncWrite};
use std::error::Error;
pub struct ProxyTunnel<T> {
state: ProxyState<T>,
}
@ -17,7 +17,7 @@ enum ProxyState<T> {
ProxyResponse(Read<T, Window<Vec<u8>>>),
}
pub fn connect<T: AsyncRead + AsyncWrite>(connection: T, connect_url: SocketAddr) -> ProxyTunnel<T> {
pub fn connect<T: AsyncRead + AsyncWrite>(connection: T, connect_url: &str) -> ProxyTunnel<T> {
let proxy = proxy_connect(connection, connect_url);
ProxyTunnel {
state: ProxyState::ProxyConnect(proxy),
@ -95,14 +95,13 @@ impl<T: AsyncRead + AsyncWrite> Future for ProxyTunnel<T> {
}
}
fn proxy_connect<T: AsyncWrite>(connection: T, connect_url: SocketAddr) -> WriteAll<T, Vec<u8>> {
// TODO: It would be better to use a non-resolved url here. This usually works,
// but it may fail in some environments and it will leak DNS requests.
fn proxy_connect<T: AsyncWrite>(connection: T, connect_url: &str) -> WriteAll<T, Vec<u8>> {
let uri = Uri::from_str(&connect_url).unwrap();
let buffer = format!(
"CONNECT {0}:{1} HTTP/1.1\r\n\
\r\n",
connect_url.ip(),
connect_url.port()
uri.host().expect(&format!("No host in {}", uri)),
uri.port().expect(&format!("No port in {}", uri))
).into_bytes();
write_all(connection, buffer)