diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 913b66e..e6f8713 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -9,9 +9,9 @@ name: Test jobs: build_and_test: name: Test - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: ACTIONS_ALLOW_UNSECURE_COMMANDS id: ACTIONS_ALLOW_UNSECURE_COMMANDS @@ -20,7 +20,7 @@ jobs: - name: add cr run: | mkdir -p $GITHUB_WORKSPACE/bin - wget -O $GITHUB_WORKSPACE/bin/cr https://github.com/calcit-lang/calcit/releases/download/0.6.1/cr + wget -O $GITHUB_WORKSPACE/bin/cr https://github.com/calcit-lang/calcit/releases/download/0.6.19/cr chmod +x $GITHUB_WORKSPACE/bin/cr echo "::add-path::$GITHUB_WORKSPACE/bin" diff --git a/Cargo.lock b/Cargo.lock index 3298e51..c3068ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,10 +10,11 @@ checksum = "bbf56136a5198c7b01a49e3afcbef6cf84597273d298f54432926024107b0109" [[package]] name = "calcit_http" -version = "0.0.8" +version = "0.0.9" dependencies = [ "cirru_edn", "cirru_parser", + "querystring", "tiny_http", ] @@ -31,9 +32,9 @@ checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e" [[package]] name = "cirru_edn" -version = "0.2.15" +version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4877bd97e9660b78be5aab32990c90df02fe869e572d57090e29248a4c7589b9" +checksum = "63c8eadc7d7e440b6e2dce8b6ef16e688dc1a36dfcac8a627a1e769672664955" dependencies = [ "cirru_parser", "hex", @@ -42,19 +43,9 @@ dependencies = [ [[package]] name = "cirru_parser" -version = "0.1.18" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4818f8cbad45841e6e0166ae5f1bad3051f63ad398a1e47586fa61fb9fba6ce" - -[[package]] -name = "form_urlencoded" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" -dependencies = [ - "matches", - "percent-encoding", -] +checksum = "0c942c2dafb7e7cab267b66e6ccbb0b4ef11a471b83c90a9e072cdd02d2081aa" [[package]] name = "hex" @@ -63,21 +54,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] -name = "idna" -version = "0.2.3" +name = "httpdate" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "itoa" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] name = "lazy_static" @@ -85,12 +65,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "libc" -version = "0.2.122" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec647867e2bf0772e28c8bcde4f0d19a9216916e890543b5a03ed8ef27b8f259" - [[package]] name = "log" version = "0.4.14" @@ -101,95 +75,19 @@ dependencies = [ ] [[package]] -name = "matches" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" - -[[package]] -name = "num_threads" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aba1801fb138d8e85e11d0fc70baf4fe1cdfffda7c6cd34a854905df588e5ed0" -dependencies = [ - "libc", -] - -[[package]] -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 = "c2702e08a7a860f005826c6815dcac101b19b5eb330c27fe4a5928fec1d20ddd" -dependencies = [ - "itoa", - "libc", - "num_threads", - "time-macros", -] - -[[package]] -name = "time-macros" -version = "0.2.4" +name = "querystring" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792" +checksum = "9318ead08c799aad12a55a3e78b82e0b6167271ffd1f627b758891282f739187" [[package]] name = "tiny_http" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0d6ef4e10d23c1efb862eecad25c5054429a71958b4eeef85eb5e7170b477ca" +checksum = "389915df6413a2e74fb181895f933386023c71110878cd0825588928e64cdc82" dependencies = [ "ascii", "chunked_transfer", + "httpdate", "log", - "time", - "url", -] - -[[package]] -name = "tinyvec" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f83b2a3d4d9091d0abd7eba4dc2710b1718583bd4d8992e2190720ea38f391f7" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" - -[[package]] -name = "unicode-bidi" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" - -[[package]] -name = "unicode-normalization" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "url" -version = "2.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" -dependencies = [ - "form_urlencoded", - "idna", - "matches", - "percent-encoding", ] diff --git a/Cargo.toml b/Cargo.toml index 8603dfd..75758ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "calcit_http" -version = "0.0.8" +version = "0.0.9" authors = ["jiyinyiyong "] -edition = "2018" +edition = "2021" [lib] name = "calcit_http" @@ -13,6 +13,7 @@ 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.15" -cirru_parser = "0.1.18" -tiny_http = "0.11.0" +cirru_edn = "0.2.21" +cirru_parser = "0.1.24" +tiny_http = "0.12.0" +querystring = "1.1.0" diff --git a/src/lib.rs b/src/lib.rs index 0a39a83..302351f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,26 @@ pub fn serve_http( let mut m: HashMap = HashMap::new(); m.insert(Edn::kwd("method"), Edn::kwd(&request.method().to_string())); - m.insert(Edn::kwd("url"), Edn::str(request.url().to_string())); + let url = request.url().to_string(); + m.insert(Edn::kwd("url"), Edn::str(url.to_owned())); + + match url.split_once('?') { + Some((path_part, query_part)) => { + m.insert(Edn::kwd("path"), path_part.into()); + m.insert(Edn::kwd("querystring"), query_part.into()); + let query = querystring::querify(query_part); + let mut query_dict = HashMap::new(); + for (k, v) in query { + query_dict.insert(Edn::kwd(k), v.into()); + } + m.insert(Edn::kwd("query"), Edn::Map(query_dict)); + } + None => { + m.insert(Edn::kwd("path"), url.into()); + m.insert(Edn::kwd("querystring"), "".into()); + m.insert(Edn::kwd("query"), Edn::Map(HashMap::new())); + } + } let mut headers: HashMap = HashMap::new();