2017-01-12 7 views
3

次は、プロキシ経由でHTTPSサイトに到達しようとする試みである:Hyperでプロキシ経由でHTTPSサイトにアクセスするにはどうすればよいですか?

extern crate hyper; 
extern crate hyper_native_tls; 

use hyper::net::HttpsConnector; 
use hyper::client::{Client, ProxyConfig}; 
use hyper_native_tls::NativeTlsClient; 

fn main() { 
    let ssl = NativeTlsClient::new().unwrap(); 
    let connector = HttpsConnector::new(ssl); 

    let client = Client::with_proxy_config(
     ProxyConfig::new(
      "http", "localhost", 3128, connector, ssl 
     ) 
    ); 

    let response = client.get("https://httpbin.org").send().unwrap(); 
    println!("{}", response.headers); 
} 

私はこのエラーを取得する:ここで

error[E0277]: the trait bound `hyper_native_tls::TlsStream<hyper::net::HttpStream>: std::fmt::Debug` is not satisfied 
    --> src/main.rs:13:9 
    | 
13 |   ProxyConfig::new(
    |   ^^^^^^^^^^^^^^^^ the trait `std::fmt::Debug` is not implemented for `hyper_native_tls::TlsStream<hyper::net::HttpStream>` 
    | 
    = note: `hyper_native_tls::TlsStream<hyper::net::HttpStream>` cannot be formatted using `:?`; if it is defined in your crate, add `#[derive(Debug)]` or manually implement it 
    = note: required because of the requirements on the impl of `std::fmt::Debug` for `hyper::net::HttpsStream<hyper_native_tls::TlsStream<hyper::net::HttpStream>>` 
    = note: required because of the requirements on the impl of `hyper::net::SslClient<hyper::net::HttpsStream<hyper_native_tls::TlsStream<hyper::net::HttpStream>>>` for `hyper_native_tls::NativeTlsClient` 
    = note: required by `<hyper::client::ProxyConfig<C, S>>::new` 

error[E0277]: the trait bound `hyper_native_tls::TlsStream<hyper::net::HttpStream>: std::fmt::Debug` is not satisfied 
    --> src/main.rs:13:9 
    | 
13 |   ProxyConfig::new(
    | _________^ starting here... 
14 | |    "http", "localhost", 3128, connector, ssl 
15 | |  ) 
    | |_________^ ...ending here: the trait `std::fmt::Debug` is not implemented for `hyper_native_tls::TlsStream<hyper::net::HttpStream>` 
    | 
    = note: `hyper_native_tls::TlsStream<hyper::net::HttpStream>` cannot be formatted using `:?`; if it is defined in your crate, add `#[derive(Debug)]` or manually implement it 
    = note: required because of the requirements on the impl of `std::fmt::Debug` for `hyper::net::HttpsStream<hyper_native_tls::TlsStream<hyper::net::HttpStream>>` 
    = note: required because of the requirements on the impl of `hyper::net::SslClient<hyper::net::HttpsStream<hyper_native_tls::TlsStream<hyper::net::HttpStream>>>` for `hyper_native_tls::NativeTlsClient` 
    = note: required by `hyper::client::ProxyConfig` 

error[E0277]: the trait bound `hyper_native_tls::TlsStream<hyper::net::HttpStream>: std::fmt::Debug` is not satisfied 
    --> src/main.rs:12:18 
    | 
12 |  let client = Client::with_proxy_config(
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::fmt::Debug` is not implemented for `hyper_native_tls::TlsStream<hyper::net::HttpStream>` 
    | 
    = note: `hyper_native_tls::TlsStream<hyper::net::HttpStream>` cannot be formatted using `:?`; if it is defined in your crate, add `#[derive(Debug)]` or manually implement it 
    = note: required because of the requirements on the impl of `std::fmt::Debug` for `hyper::net::HttpsStream<hyper_native_tls::TlsStream<hyper::net::HttpStream>>` 
    = note: required because of the requirements on the impl of `hyper::net::SslClient<hyper::net::HttpsStream<hyper_native_tls::TlsStream<hyper::net::HttpStream>>>` for `hyper_native_tls::NativeTlsClient` 
    = note: required by `hyper::Client::with_proxy_config` 

は、貨物の依存関係です:

[dependencies] 
hyper = "0.10" 
hyper-native-tls = "0.2" 

物事は優れています次の依存関係を使用します。

[dependencies] 
hyper = "0.10" 
hyper-openssl = "0.2" 

そして、このコード:

extern crate hyper; 
extern crate hyper_openssl; 

use hyper::net::HttpsConnector; 
use hyper::client::{Client, ProxyConfig}; 
use hyper_openssl::OpensslClient as TlsClient; 

fn main() { 
    let ssl = TlsClient::new().unwrap(); 
    let connector = HttpsConnector::new(ssl.clone()); 

    let client = Client::with_proxy_config(
     ProxyConfig::new(
      "http", "localhost", 3128, connector, ssl 
     ) 
    ); 

    let response = client.get("https://httpbin.org").send().unwrap(); 
    println!("{:#?}", response); 
} 

出力:

Response { 
    status: Ok, 
    headers: Headers { Server: nginx, Date: Thu, 12 Jan 2017 15:05:13 GMT, Content-Type: text/html; charset=utf-8, Content-Length: 12150, Connection: keep-alive, Access-Control-Allow-Origin: *, Access-Control-Allow-Credentials: true, }, 
    version: Http11, 
    url: "https://httpbin.org/", 
    status_raw: RawStatus(
     200, 
     "OK" 
    ), 
    message: Http11Message { 
     is_proxied: false, 
     method: None, 
     stream: Wrapper { 
      obj: Some(
       Reading(
        SizedReader(remaining=12150) 
       ) 
      ) 
     } 
    } 
} 

ありませんが失敗を構築するが、それは、プロキシを経由しません。

+0

これらのエラーのすべては、 'Debug'を実装していない間に' response'をデバッグモードで表示しようとしているという事実によるものではありませんか? – ljedrz

+0

何も印刷しなくても同じエラーが出る – Tshepang

+1

['hyper_native_tls'](https://docs.rs/hyper-native-tls/0.2.0/hyper_native_tls/)の構造はimplするように見えません'Debug'のため、そのコードに見られる動作は正しいでしょう。 'fmt()'を実行していないことを確認し、あなたの調査結果に質問を更新してください。 –

答えて

4

箱の周りにいくつかの未解決の競合があったhyper_native_tlsと​​。

の実装には、現在のところNativeTlsClientの実装には、T: Debugcode)が必要です。 TlsStreamは、そのパラメータの種類に関係なく、Debugを実装していないため、質問内のコードはコンパイルされません。

最初に、前述の制約を削除することを検討できます。しかし、それはhyper_native_tlsでいくつかの他のエラーをトリガ:

error[E0277]: the trait bound `T: std::fmt::Debug` is not satisfied 
    --> src/lib.rs:129:45 
    | 
129 |    Err(e) => Err(hyper::Error::Ssl(Box::new(e))), 
    |            ^^^^^^^^^^^ the trait `std::fmt::Debug` is not implemented for `T` 
    | 
    = help: consider adding a `where T: std::fmt::Debug` bound 
    = note: required because of the requirements on the impl of `std::error::Error` for `native_tls::HandshakeError<T>` 
    = note: required for the cast to the object type `std::error::Error + std::marker::Sync + std::marker::Send + 'static` 

は、ウサギの穴を下に行く、我々はnative_tls::HandshakeErrorが(この特定のエラーの場合)中断されたストリームのパラメータの型Sを保持していることを発見します。タイプはDebugしか実装していないため、S: DebugError特性に従って、エラータイプは常にDebugを実装する必要があるため、これは別の問題になりました。

この特定の問題に対する修正はTlsStreamDebugを提供することです:

#[derive(Debug, Clone)] 
pub struct TlsStream<S>(Arc<Mutex<native_tls::TlsStream<S>>>); 

sslが移動した後に使用され、コピーが、ここでは許容されていないため、最初のコードスニペットは、まだコンパイルされません。 2番目のスニペットはオブジェクトをクローンして動作しますが、残念ながらNativeTlsClientでは実装されていません。 native_tls::TlsConnectorにはCloneも実装されていないため、実装を導き出すこともできません。このウサギの穴が開けば、これがデバッグレポートになる前にここで終わるはずです。

ネイティブTLSを使用しているのではなく、ここで何ができるのかが完全にはわかりませんが、私の現在のアドバイスではhyper_native_tls_clientに問題が提起されていて、ハイパーのクライアントプロキシでは機能しません編集:it's done and fixed!)。

+0

https://github.com/sfackler/hyper-native-tls/commit/30e9d1574774aa9267ca8d4770f9af21f04edb13 – Tshepang

+0

@Tshepangいい仕事です。 ;) –

関連する問題