Trying to make a fake Request Object in Iron


#1

I am trying instantiate a Request object to unify an API call without having to open a port on a local machine.
I’m close to making it, but couldn’t figure out how to deal with this error

use iron::request::Body;
use std::io::prelude::*;
use std::net::TcpStream;
use hyper::buffer::BufReader;
use hyper::net::HttpStream;
use hyper::net::NetworkStream;
use hyper::net::HttpsStream;

fn main(){
    
    let url = Url::parse("http://localhost").unwrap();
    let ip = IpAddr::from_str("127.0.0.1").unwrap();
    let addr = SocketAddr::new(ip,8080);
    let mut stream = TcpStream::connect("127.0.0.1:34254").unwrap();
    let mut http_stream = HttpStream(stream);
    let mut https_stream = HttpsStream::Http(http_stream);

    let content = String::new();
    let mut bufreader = BufReader::new(&mut https_stream);
    let reader = HttpReader::EmptyReader(&mut bufreader);
    let body = Body::new(reader);

    let req = Request{
        url: url,
        remote_addr: addr.clone(),
        local_addr: addr.clone(),
        headers: Headers::new(),
        body: body,
        method: Method::Get,
        extensions: TypeMap::new()
   };

}


examples/fake_request.rs:33:26: 33:32 error: mismatched types:
 expected `hyper::http::h1::HttpReader<&mut hyper::buffer::BufReader<&mut hyper::net::NetworkStream + 'static>>`,
    found `hyper::http::h1::HttpReader<&mut hyper::buffer::BufReader<&mut hyper::net::HttpsStream<_>>>`
(expected trait hyper::net::NetworkStream,
    found enum `hyper::net::HttpsStream`) [E0308]
examples/fake_request.rs:33     let body = Body::new(reader);
                                                     ^~~~~~
examples/fake_request.rs:33:26: 33:32 help: run `rustc --explain E0308` to see a detailed explanation

I’m using iron and hyper.