httpbin 0.3.3

A httpbin reimplementation in rust. Works as a library and as a standalone webserver binary. (not affiliated to the original httpbin)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use std::str::from_utf8;
use std::ascii::AsciiExt;

use pages::{Response};
use service::{Request};


pub fn serve<S: 'static>(req: Request) -> Response<S> {
    let ua = req.headers()
        .find(|h| h.name.eq_ignore_ascii_case("User-Agent"))
        .map(|h| &h.value[..])
        .map(|v| from_utf8(v).unwrap_or("--<<Invalid Utf8>>--"))
        .unwrap_or("");
    req.json(json!({
        "user_agent": ua,
    }))
}