Crate mio_httpc [] [src]

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

For convenience it also provides CallBuilder::exec for a simple one-line blocking HTTP call.

Except CallBuilder::exec no call will block, not even for DNS resolution as it is implemented internally to avoid blocking.

For https to work you must specify one of the TLS implementations using features: rtls (rustls), native, openssl. Default build will fail on any https URI.

CallBuilder also has URL construction functions (host/path_segm/query/set_https/auth/https) which will take care of url-safe encoding.

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.

Examples

extern crate mio_httpc;
extern crate mio;

use mio_httpc::{CallBuilder,Httpc};
use mio::{Poll,Events};

let poll = Poll::new().unwrap();
let mut htp = Httpc::new(10,None);
let mut call = CallBuilder::get()
    .url("https://www.reddit.com").expect("Invalid url")
    .timeout_ms(500)
    .simple_call(&mut htp, &poll)?;

let to = ::std::time::Duration::from_millis(100);
let mut events = Events::with_capacity(8);
'outer: loop {
    poll.poll(&mut events, Some(to)).unwrap();
    for cref in htp.timeout().into_iter() {
       if call.is_ref(cref) {
           println!("Request timed out");
           call.abort(&mut htp);
           break 'outer;
       }
   }

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

       if call.is_call(&cref) {
           if call.perform(&mut htp, &poll)? {
               let (resp,body) = call.finish()?;
               if let Ok(s) = String::from_utf8(body) {
                   println!("Body: {}",s);
               }
               break 'outer;
           }
       }
   }
}
extern crate mio_httpc;
use mio_httpc::CallBuilder;

// One line blocking call.

let (response_meta, body) = CallBuilder::get().timeout_ms(5000).url("http://www.example.com")?.exec()?;

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).

Header

A single header

Headers

Iterator over headers in response

Httpc
HttpcCfg

Top level configuration for mio_http. For now just additional root ssl certificates.

Response
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.

Type Definitions

Result