Ver Fonte

New framework: tokio-minihttp (#2472)

* New framework: tokio-minihttp

* fix trailing comma
Gökberk YALTIRAKLI há 8 anos atrás
pai
commit
a149e839e5

+ 1 - 0
.travis.yml

@@ -173,6 +173,7 @@ env:
     - "TESTDIR=Rust/iron"
     - "TESTDIR=Rust/nickel"
     - "TESTDIR=Rust/hyper"
+    - "TESTDIR=Rust/tokio-minihttp"
     - "TESTDIR=Scala/akka-http"
     - "TESTDIR=Scala/colossus"
     - "TESTDIR=Scala/finagle"

+ 13 - 0
frameworks/Rust/tokio-minihttp/Cargo.toml

@@ -0,0 +1,13 @@
+[package]
+name = "tokio-minihttp"
+version = "0.1.0"
+authors = ["Gökberk Yaltıraklı <[email protected]>"]
+
+[dependencies]
+futures = "0.1"
+httparse = "1.1"
+serde_json = "0.8"
+num_cpus = "1.0"
+tokio-proto = { git = "https://github.com/tokio-rs/tokio-proto", revision = "e42b3bfb" }
+tokio-service = { git = "https://github.com/tokio-rs/tokio-service", revision = "0c904c40" }
+tokio-minihttp = { git = "https://github.com/tokio-rs/tokio-minihttp", revision = "6ac81b31" }

+ 22 - 0
frameworks/Rust/tokio-minihttp/benchmark_config.json

@@ -0,0 +1,22 @@
+{
+  "framework": "tokio-minihttp",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Micro",
+      "database": "None",
+      "framework": "tokio-minihttp",
+      "language": "rust",
+      "orm": "raw",
+      "platform": "Rust",
+      "webserver": "tokio-minihttp",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "tokio-minihttp"
+    }
+  }]
+}

+ 7 - 0
frameworks/Rust/tokio-minihttp/setup.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+
+fw_depends rust
+
+cargo clean
+cargo build --release
+./target/release/tokio-minihttp &

+ 53 - 0
frameworks/Rust/tokio-minihttp/src/main.rs

@@ -0,0 +1,53 @@
+extern crate tokio_service;
+extern crate tokio_proto;
+extern crate tokio_minihttp;
+extern crate futures;
+extern crate num_cpus;
+extern crate serde_json;
+
+use futures::future;
+use tokio_service::Service;
+use tokio_proto::TcpServer;
+use tokio_minihttp::{Request, Response, Http};
+use serde_json::builder::ObjectBuilder;
+
+struct Techempower;
+
+impl Service for Techempower {
+    type Request = Request;
+    type Response = Response;
+    type Error = std::io::Error;
+    type Future = future::Ok<Response, std::io::Error>;
+
+    fn call(&mut self, req: Request) -> Self::Future {
+        let mut resp = Response::new();
+
+        // Bare-bones router
+        match req.path() {
+            "/json" => {
+                let json = serde_json::to_string(
+                    &ObjectBuilder::new().insert("message", "Hello, World!")
+                .build()).unwrap();
+
+                resp.header("Content-Type", "application/json")
+                    .body(&json);
+            },
+            "/plaintext" => {
+                resp.header("Content-Type", "text/plain")
+                    .body("Hello, World!");
+            },
+            _ => {
+                resp.status_code(404, "Not Found");
+            }
+        }
+
+        future::ok(resp)
+    }
+}
+
+fn main() {
+    let addr = "0.0.0.0:8080".parse().unwrap();
+    let mut srv = TcpServer::new(Http, addr);
+    srv.threads(num_cpus::get());
+    srv.serve(|| Ok(Techempower))
+}