Skip to content

Instantly share code, notes, and snippets.

@vird
Created August 12, 2017 16:27
Show Gist options
  • Save vird/b5251bf298a9365401c3f25df223ee51 to your computer and use it in GitHub Desktop.
Save vird/b5251bf298a9365401c3f25df223ee51 to your computer and use it in GitHub Desktop.
[package]
name = "wtf"
version = "0.1.0"
authors = ["vird <[email protected]>"]
[dependencies]
tokio-proto = "0.1.1"
tokio-minihttp = { git = "https://github.com/tokio-rs/tokio-minihttp" }
tokio-service = "0.1.0"
futures = "0.1.14"
env_logger = "0.4.3"
extern crate env_logger;
extern crate futures;
extern crate tokio_minihttp;
extern crate tokio_proto;
extern crate tokio_service;
use std::io;
use futures::future;
use tokio_minihttp::{Request, Response, Http};
use tokio_proto::TcpServer;
use tokio_service::Service;
/// `HelloWorld` is the *service* that we're going to be implementing to service
/// the HTTP requests we receive.
///
/// The tokio-minihttp crate, and much of Tokio itself, are centered around the
/// concept of a service for interoperability between crates. Our service here
/// carries no data with it.
///
/// Note that a new instance of `HelloWorld` is created for each TCP connection
/// we service, created below in the closure passed to `serve`.
struct HelloWorld;
impl Service for HelloWorld {
type Request = Request;
type Response = Response;
type Error = io::Error;
type Future = future::Ok<Response, io::Error>;
fn call(&self, _request: Request) -> Self::Future {
let mut resp = Response::new();
resp.body("Hello, world!");
future::ok(resp)
}
}
fn main() {
drop(env_logger::init());
let addr = "0.0.0.0:8080".parse().unwrap();
TcpServer::new(Http, addr)
.serve(|| Ok(HelloWorld));
}
#!/bin/sh
curl http://localhost:8080/
echo ""
curl -X POST http://localhost:8080/
echo ""
curl -X POST -d 'somenoise' http://localhost:8080/
echo ""
curl -X POST -d 'some noise' http://localhost:8080/
echo ""
curl -X POST -d 'some noise1111111111111111111111111111111111111111111111111' http://localhost:8080/
echo ""
curl -X POST -d ' singlespace_is_ok' http://localhost:8080/
echo ""
curl -X POST -d ' multi_space is ok?' http://localhost:8080/
echo ""
echo "now fail comes"
curl -X POST -d ' multi space is ok?' http://localhost:8080/
curl -X POST -d ' b bbbbbbbbb' http://localhost:8080/
curl -d ' b bbbbbbbbb' http://localhost:8080/
curl -X POST -d 'a b bbbbbbbbb' http://localhost:8080/
curl -d 'a b bbbbbbbbb' http://localhost:8080/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment