Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

max_width = 136
tab_spaces = 2
102 changes: 38 additions & 64 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "calcit_http"
version = "0.0.6"
version = "0.0.7"
authors = ["jiyinyiyong <jiyinyiyong@gmail.com>"]
edition = "2018"

Expand All @@ -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"
3 changes: 3 additions & 0 deletions calcit.cirru

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions compact.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 4 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -47,20 +47,14 @@ pub fn serve_http(
let mut headers: HashMap<Edn, Edn> = 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);
Expand All @@ -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::<tiny_http::Header>()
.unwrap(),
);
response.add_header(format!("{}: {}", field, value).parse::<tiny_http::Header>().unwrap());
}
request.respond(response).map_err(|x| x.to_string())?;
}
Expand Down