Crate mio_httpc [] [src]

mio_httpc is an async http client that runs on top of mio only.

No call will block, not even for DNS resolution as it is implemented internally to avoid blocking.

mio_httpc requires you specify one of the TLS implementations using features: rustls, native, openssl. Default is noop for everything.

mio_httpc does a minimal amount of allocation and in general works with buffers you provide and an internal pool of buffers that get reused on new calls.

extern crate mio_httpc;
extern crate mio;
use mio_httpc::{Request,CallBuilder,Httpc,SimpleCall};
use mio::{Poll,Events};

let poll = Poll::new().unwrap();
let mut htp = Httpc::new(10);
let mut req = Request::builder();
let req = req.uri("https://www.reddit.com").body(Vec::new())?;
let call = CallBuilder::new(req).timeout_ms(500).call(&mut htp, &poll)?;
let mut call = SimpleCall::from(call);
let to = ::std::time::Duration::from_millis(100);
'outer: loop {
    let mut events = Events::with_capacity(8);
    poll.poll(&mut events, Some(to)).unwrap();
    for cref in htp.timeout().into_iter() {
       if call.is_ref(cref) {
           println!("Request timed out");
           break 'outer;
       }
   }

   for ev in events.iter() {
       let cref = htp.event(&ev);

       if call.is_call(&cref) {
           if call.perform(&mut htp, &poll)? {
               let mut resp = call.close()?;
               let v = mio_httpc::extract_body(&mut resp);
               if let Ok(s) = String::from_utf8(v) {
                   println!("Body: {}",s);
               }
               break 'outer;
           }
       }
   }
}

Reexports

pub use http::header::*;
pub use http::method::*;
pub use http::request::*;
pub use http::response::*;
pub use http::status::*;
pub use http::uri::*;
pub use http::version::*;

Structs

Call

Call structure.

CallBuilder

Used to start a call and get a Call for it.

CallRef

Reference to call. Used for matching mio Token with call. If you have lots of calls, you can use this as a key in a HashMap (you probably want fnv HashMap).

HttpError

A generic "error" for HTTP connections

Httpc

Send requests, receive responses.

SimpleCall

Simplified API for non-streaming requests and responses. If body exists it needs to be provided to Request. If response has a body it is returned in Response.

WebSocket

WebSocket interface.

Enums

Error
RecvState

Used when call is in receive response state.

ResponseBody
SendState

Used when call is in send request state.

WSPacket

WebSocket packet received from server.

Functions

extract_body

Extract body from http::Response

Type Definitions

Result