diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..79bf0b7 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,3 @@ + +max_width = 136 +tab_spaces = 2 diff --git a/Cargo.lock b/Cargo.lock index 7dc8f13..ced4415 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,15 +8,9 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbf56136a5198c7b01a49e3afcbef6cf84597273d298f54432926024107b0109" -[[package]] -name = "autocfg" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" - [[package]] name = "calcit_http" -version = "0.0.6" +version = "0.0.7" dependencies = [ "cirru_edn", "cirru_parser", @@ -29,18 +23,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "chrono" -version = "0.4.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" -dependencies = [ - "libc", - "num-integer", - "num-traits", - "winapi", -] - [[package]] name = "chunked_transfer" version = "1.4.0" @@ -49,9 +31,9 @@ checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e" [[package]] name = "cirru_edn" -version = "0.2.8" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4888ae76433b2504f820e97d63297db438f9d3ba377456f203ebb0747282c613" +checksum = "92227d12bd2bd8874930d31d987e194bb70066851a4bf833e2d1086ecd1a7460" dependencies = [ "cirru_parser", "hex", @@ -60,9 +42,9 @@ dependencies = [ [[package]] name = "cirru_parser" -version = "0.1.12" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7344fe701ed60135a9caad1269b200a7dc559abd9860ac5a8b29c674ce579a05" +checksum = "f4818f8cbad45841e6e0166ae5f1bad3051f63ad398a1e47586fa61fb9fba6ce" [[package]] name = "form_urlencoded" @@ -76,9 +58,9 @@ dependencies = [ [[package]] name = "hex" -version = "0.3.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "idna" @@ -91,6 +73,12 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "itoa" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" + [[package]] name = "lazy_static" version = "1.4.0" @@ -99,9 +87,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.104" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b2f96d100e1cf1929e7719b7edb3b90ab5298072638fccd77be9ce942ecdfce" +checksum = "ec647867e2bf0772e28c8bcde4f0d19a9216916e890543b5a03ed8ef27b8f259" [[package]] name = "log" @@ -119,40 +107,48 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] -name = "num-integer" -version = "0.1.44" +name = "num_threads" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +checksum = "aba1801fb138d8e85e11d0fc70baf4fe1cdfffda7c6cd34a854905df588e5ed0" dependencies = [ - "autocfg", - "num-traits", + "libc", ] [[package]] -name = "num-traits" -version = "0.2.14" +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "time" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +checksum = "c2702e08a7a860f005826c6815dcac101b19b5eb330c27fe4a5928fec1d20ddd" dependencies = [ - "autocfg", + "itoa", + "libc", + "num_threads", + "time-macros", ] [[package]] -name = "percent-encoding" -version = "2.1.0" +name = "time-macros" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792" [[package]] name = "tiny_http" -version = "0.9.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96155b5f7149ba7a99ea5d516c538250b26eab60b4485c0f5344432573e7a450" +checksum = "e0d6ef4e10d23c1efb862eecad25c5054429a71958b4eeef85eb5e7170b477ca" dependencies = [ "ascii", - "chrono", "chunked_transfer", "log", + "time", "url", ] @@ -197,25 +193,3 @@ dependencies = [ "matches", "percent-encoding", ] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index f3dc58a..9661a2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "calcit_http" -version = "0.0.6" +version = "0.0.7" authors = ["jiyinyiyong "] edition = "2018" @@ -13,6 +13,6 @@ crate-type = ["dylib"] # Creates dynamic lib # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cirru_edn = "0.2.8" -cirru_parser = "0.1.12" -tiny_http = "0.9" +cirru_edn = "0.2.14" +cirru_parser = "0.1.18" +tiny_http = "0.11.0" diff --git a/calcit.cirru b/calcit.cirru index 9d2a7b6..a9bed00 100644 --- a/calcit.cirru +++ b/calcit.cirru @@ -279,3 +279,6 @@ :configs $ {} (:port 6001) (:init-fn |http.test/main!) (:reload-fn |http.test/reload!) :modules $ [] :version |0.0.6 + :entries $ {} + :server $ {} (:init-fn |http.test/demo-server!) (:reload-fn |http.test/reload!) + :modules $ [] diff --git a/compact.cirru b/compact.cirru index 3478aae..1b61f2c 100644 --- a/compact.cirru +++ b/compact.cirru @@ -3,6 +3,9 @@ :configs $ {} (:init-fn |http.test/main!) (:reload-fn |http.test/reload!) :modules $ [] :version |0.0.6 + :entries $ {} + :server $ {} (:init-fn |http.test/demo-server!) (:reload-fn |http.test/reload!) + :modules $ [] :files $ {} |http.core $ {} :ns $ quote diff --git a/src/lib.rs b/src/lib.rs index 73aa67a..a423aee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ struct ResponseSkeleton { #[no_mangle] pub fn abi_version() -> String { - String::from("0.0.5") + String::from("0.0.6") } #[no_mangle] @@ -47,20 +47,14 @@ pub fn serve_http( let mut headers: HashMap = HashMap::new(); for pair in request.headers() { - headers.insert( - Edn::kwd(&pair.field.to_string()), - Edn::str(pair.value.to_string()), - ); + headers.insert(Edn::kwd(&pair.field.to_string()), Edn::str(pair.value.to_string())); } m.insert(Edn::kwd("headers"), Edn::Map(headers)); if request.method() != &Method::Get { let mut content = String::new(); request.as_reader().read_to_string(&mut content).unwrap(); - m.insert( - Edn::kwd("body"), - Edn::Str(content.to_string().into_boxed_str()), - ); + m.insert(Edn::kwd("body"), Edn::Str(content.to_string().into_boxed_str())); } let info = Edn::Map(m); @@ -70,11 +64,7 @@ pub fn serve_http( let mut response = Response::from_string(res.body.to_string()).with_status_code(res.code); for (field, value) in res.headers { - response.add_header( - format!("{}: {}", field, value) - .parse::() - .unwrap(), - ); + response.add_header(format!("{}: {}", field, value).parse::().unwrap()); } request.respond(response).map_err(|x| x.to_string())?; }