xudong-huang / may_minihttp Goto Github PK
View Code? Open in Web Editor NEWmini http implemented on top of may
License: Apache License 2.0
mini http implemented on top of may
License: Apache License 2.0
Hi,
I am trying to do a simple POST. I tried this,
match (req.method(), req.path()) { ("GET", "/json") => { rsp.header("Content-Type: application/json"); serde_json::to_writer( BodyWriter(rsp.body_mut()), &HelloMessage { message: "Hello, World!", }, )?; }, ("POST", "/json") => { rsp.header("Content-Type: application/json"); serde_json::to_writer( BodyWriter(rsp.body_mut()), req.data(), )?; }, ("GET", "/plaintext") => { rsp.header("Content-Type: text/plain").body("Hello, World!"); }, _ => { rsp.status_code("404", "Not Found"); }, }
However, I am not able to access the request Body. Do you have any suggestions perhaps ?
Kind regards
Savi
Hi 👋,
I see may_minihttp uses the 2018 edition of rust.
Are there any plans to port to the 2021 edition?
ditto for the examples ?
Anyway, thank you for this crate!
req
value borrowed here after move
extern crate may_minihttp;
use may_minihttp::{HttpServer, HttpService, Request, Response};
use serde_json::Value;
#[derive(Clone)]
struct JsonParse;
impl HttpService for JsonParse {
fn call(&mut self, req: Request, rsp: &mut Response) -> std::io::Result<()> {
let mut reader = req.body();
let value: Value = serde_json::from_reader(&mut reader).unwrap();
let path = req.path();
let resp: &str = value[req.path()].as_str().unwrap();
Ok(())
}
}
fn main() {
let server = HttpServer(JsonParse).start("0.0.0.0:8080").unwrap();
server.join().unwrap();
}
error[E0382]: borrow of moved value: `req`
--> src\main.rs:15:20
|
10 | fn call(&mut self, req: Request, rsp: &mut Response) -> std::io::Result<()> {
| --- move occurs because `req` has type `may_minihttp::Request<'_, '_, '_>`, which does not implement the `Copy` trait
11 | let mut reader = req.body();
| ------ `req` moved due to this method call
...
15 | let path = req.path();
| ^^^ value borrowed here after move
|
Do you plan to support TLS at some point directly in the library?
Thanks
need a mini http client.
像hyper那个框架一样,提供一个基于may的http client可以发起请求,不然又得使用其他的框架了
want arm64 windows plz!
cargo build is wrong at windows arm64 device.:
The following warnings were emitted during compilation:
warning: The MSVC ARM assemblers do not support -D flags
error: failed to run custom build command for `generator v0.7.5`
Caused by:
process didn't exit successfully: `C:\dev\gh\may_minihttp\target\debug\build\generator-03cf22b39963fe75\build-script-build` (exit code: 1)
--- stdout
cargo:rerun-if-changed=src/detail/asm\asm_aarch64_aapcs_pe_masm.asm
TARGET = Some("aarch64-pc-windows-msvc")
OPT_LEVEL = Some("0")
HOST = Some("aarch64-pc-windows-msvc")
cargo:rerun-if-env-changed=CC_aarch64-pc-windows-msvc
CC_aarch64-pc-windows-msvc = None
cargo:rerun-if-env-changed=CC_aarch64_pc_windows_msvc
CC_aarch64_pc_windows_msvc = None
cargo:rerun-if-env-changed=HOST_CC
HOST_CC = None
cargo:rerun-if-env-changed=CC
CC = None
cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("neon")
DEBUG = Some("true")
cargo:rerun-if-env-changed=CFLAGS_aarch64-pc-windows-msvc
CFLAGS_aarch64-pc-windows-msvc = None
cargo:rerun-if-env-changed=CFLAGS_aarch64_pc_windows_msvc
CFLAGS_aarch64_pc_windows_msvc = None
cargo:rerun-if-env-changed=HOST_CFLAGS
HOST_CFLAGS = None
cargo:rerun-if-env-changed=CFLAGS
CFLAGS = None
cargo:warning=The MSVC ARM assemblers do not support -D flags
running: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\bin\\HostARM64\\ARM64\\armasm64.exe" "-nologo" "-g" "-o" "C:\\dev\\gh\\may_minihttp\\target\\debug\\build\\generator-f0cc99bf5c1e309c\\out\\src/detail/asm\\asm_aarch64_aapcs_pe_masm.o" "src/detail/asm\\asm_aarch64_aapcs_pe_masm.asm"
error A2027: can't open file: src/detail/asm\asm_aarch64_aapcs_pe_masm.asm
exit code: 1
--- stderr
error occurred: Command "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\bin\\HostARM64\\ARM64\\armasm64.exe" "-nologo" "-g" "-o" "C:\\dev\\gh\\may_minihttp\\target\\debug\\build\\generator-f0cc99bf5c1e309c\\out\\src/detail/asm\\asm_aarch64_aapcs_pe_masm.o" "src/detail/asm\\asm_aarch64_aapcs_pe_masm.asm" with args "armasm64.exe" did not execute successfully (status code exit code: 1).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.