Skip to content

Commit 5881ee3

Browse files
committed
update example
1 parent dbf5695 commit 5881ee3

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/api/src-tauri/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ tauri-build = { workspace = true, features = ["codegen", "isolation"] }
1818
serde_json = { workspace = true }
1919
serde = { workspace = true }
2020
tiny_http = "0.12"
21+
time = "0.3"
2122
log = { workspace = true }
2223
tauri-plugin-log = { path = "../../../plugins/log", version = "2.3.1" }
2324
tauri-plugin-fs = { path = "../../../plugins/fs", version = "2.2.0", features = [
@@ -27,6 +28,7 @@ tauri-plugin-clipboard-manager = { path = "../../../plugins/clipboard-manager",
2728
tauri-plugin-dialog = { path = "../../../plugins/dialog", version = "2.2.0" }
2829
tauri-plugin-http = { path = "../../../plugins/http", features = [
2930
"multipart",
31+
"cookies",
3032
], version = "2.4.1" }
3133
tauri-plugin-notification = { path = "../../../plugins/notification", version = "2.2.2", features = [
3234
"windows7-compat",

examples/api/src-tauri/src/lib.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,24 @@ pub fn run() {
102102
if let Ok(mut request) = server.recv() {
103103
let mut body = Vec::new();
104104
let _ = request.as_reader().read_to_end(&mut body);
105+
let mut headers = request.headers().to_vec();
106+
107+
if !headers.iter().any(|header| header.field == tiny_http::HeaderField::from_bytes(b"Cookie").unwrap()) {
108+
let expires = time::OffsetDateTime::now_utc() + time::Duration::days(1);
109+
let expires_str = expires.format(&time::format_description::well_known::Rfc2822).unwrap();
110+
headers.push(
111+
tiny_http::Header::from_bytes(
112+
&b"Set-Cookie"[..],
113+
&format!("session-token=test-value; Secure; Path=/; Expires={expires_str}")
114+
.as_bytes()[..],
115+
)
116+
.unwrap(),
117+
);
118+
}
119+
105120
let response = tiny_http::Response::new(
106121
tiny_http::StatusCode(200),
107-
request.headers().to_vec(),
122+
headers,
108123
std::io::Cursor::new(body),
109124
request.body_length(),
110125
None,

0 commit comments

Comments
 (0)