Skip to content

Commit d1dfd81

Browse files
authored
Merge pull request #6 from calcit-lang/query
parse querystring; upgrade deps
2 parents fde6827 + 16a9ad9 commit d1dfd81

File tree

4 files changed

+44
-126
lines changed

4 files changed

+44
-126
lines changed

.github/workflows/check.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ name: Test
99
jobs:
1010
build_and_test:
1111
name: Test
12-
runs-on: ubuntu-latest
12+
runs-on: ubuntu-22.04
1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v3
1515

1616
- name: ACTIONS_ALLOW_UNSECURE_COMMANDS
1717
id: ACTIONS_ALLOW_UNSECURE_COMMANDS
@@ -20,7 +20,7 @@ jobs:
2020
- name: add cr
2121
run: |
2222
mkdir -p $GITHUB_WORKSPACE/bin
23-
wget -O $GITHUB_WORKSPACE/bin/cr https://github.com/calcit-lang/calcit/releases/download/0.6.1/cr
23+
wget -O $GITHUB_WORKSPACE/bin/cr https://github.com/calcit-lang/calcit/releases/download/0.6.19/cr
2424
chmod +x $GITHUB_WORKSPACE/bin/cr
2525
echo "::add-path::$GITHUB_WORKSPACE/bin"
2626

Cargo.lock

Lines changed: 15 additions & 117 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "calcit_http"
3-
version = "0.0.8"
3+
version = "0.0.9"
44
authors = ["jiyinyiyong <[email protected]>"]
5-
edition = "2018"
5+
edition = "2021"
66

77
[lib]
88
name = "calcit_http"
@@ -13,6 +13,7 @@ crate-type = ["dylib"] # Creates dynamic lib
1313
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1414

1515
[dependencies]
16-
cirru_edn = "0.2.15"
17-
cirru_parser = "0.1.18"
18-
tiny_http = "0.11.0"
16+
cirru_edn = "0.2.21"
17+
cirru_parser = "0.1.24"
18+
tiny_http = "0.12.0"
19+
querystring = "1.1.0"

src/lib.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,26 @@ pub fn serve_http(
4242

4343
let mut m: HashMap<Edn, Edn> = HashMap::new();
4444
m.insert(Edn::kwd("method"), Edn::kwd(&request.method().to_string()));
45-
m.insert(Edn::kwd("url"), Edn::str(request.url().to_string()));
45+
let url = request.url().to_string();
46+
m.insert(Edn::kwd("url"), Edn::str(url.to_owned()));
47+
48+
match url.split_once('?') {
49+
Some((path_part, query_part)) => {
50+
m.insert(Edn::kwd("path"), path_part.into());
51+
m.insert(Edn::kwd("querystring"), query_part.into());
52+
let query = querystring::querify(query_part);
53+
let mut query_dict = HashMap::new();
54+
for (k, v) in query {
55+
query_dict.insert(Edn::kwd(k), v.into());
56+
}
57+
m.insert(Edn::kwd("query"), Edn::Map(query_dict));
58+
}
59+
None => {
60+
m.insert(Edn::kwd("path"), url.into());
61+
m.insert(Edn::kwd("querystring"), "".into());
62+
m.insert(Edn::kwd("query"), Edn::Map(HashMap::new()));
63+
}
64+
}
4665

4766
let mut headers: HashMap<Edn, Edn> = HashMap::new();
4867

0 commit comments

Comments
 (0)