Crate mio_httpc [] [src]

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

For convenience it also provides a SyncCall interface. This is a simple one-line HTTP client operation.

No call will block (except SyncCall), 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: rtls (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.

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("https://www.reddit.com")
    .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 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;
           }
       }
   }
}
extern crate mio_httpc;
use mio_httpc::SyncCall;

// One line blocking call.

let (status, hdrs, body) = SyncCall::new().timeout_ms(5000).get(uri).expect("Request failed");

Re-exports

pub use http::header::*;
pub use http::method::*;
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.

HttpcCfg

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

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.

SyncCall

Simplest possible call interface. Will block until complete.

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