update example

pull/1978/head
Lucas Nogueira 4 months ago
parent dbf5695c62
commit 5881ee36d2
No known key found for this signature in database
GPG Key ID: A05EE2227C581CD7

1
Cargo.lock generated

@ -233,6 +233,7 @@ dependencies = [
"tauri-plugin-store", "tauri-plugin-store",
"tauri-plugin-updater", "tauri-plugin-updater",
"tauri-plugin-window-state", "tauri-plugin-window-state",
"time",
"tiny_http", "tiny_http",
] ]

@ -18,6 +18,7 @@ tauri-build = { workspace = true, features = ["codegen", "isolation"] }
serde_json = { workspace = true } serde_json = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
tiny_http = "0.12" tiny_http = "0.12"
time = "0.3"
log = { workspace = true } log = { workspace = true }
tauri-plugin-log = { path = "../../../plugins/log", version = "2.3.1" } tauri-plugin-log = { path = "../../../plugins/log", version = "2.3.1" }
tauri-plugin-fs = { path = "../../../plugins/fs", version = "2.2.0", features = [ tauri-plugin-fs = { path = "../../../plugins/fs", version = "2.2.0", features = [
@ -27,6 +28,7 @@ tauri-plugin-clipboard-manager = { path = "../../../plugins/clipboard-manager",
tauri-plugin-dialog = { path = "../../../plugins/dialog", version = "2.2.0" } tauri-plugin-dialog = { path = "../../../plugins/dialog", version = "2.2.0" }
tauri-plugin-http = { path = "../../../plugins/http", features = [ tauri-plugin-http = { path = "../../../plugins/http", features = [
"multipart", "multipart",
"cookies",
], version = "2.4.1" } ], version = "2.4.1" }
tauri-plugin-notification = { path = "../../../plugins/notification", version = "2.2.2", features = [ tauri-plugin-notification = { path = "../../../plugins/notification", version = "2.2.2", features = [
"windows7-compat", "windows7-compat",

@ -102,9 +102,24 @@ pub fn run() {
if let Ok(mut request) = server.recv() { if let Ok(mut request) = server.recv() {
let mut body = Vec::new(); let mut body = Vec::new();
let _ = request.as_reader().read_to_end(&mut body); let _ = request.as_reader().read_to_end(&mut body);
let mut headers = request.headers().to_vec();
if !headers.iter().any(|header| header.field == tiny_http::HeaderField::from_bytes(b"Cookie").unwrap()) {
let expires = time::OffsetDateTime::now_utc() + time::Duration::days(1);
let expires_str = expires.format(&time::format_description::well_known::Rfc2822).unwrap();
headers.push(
tiny_http::Header::from_bytes(
&b"Set-Cookie"[..],
&format!("session-token=test-value; Secure; Path=/; Expires={expires_str}")
.as_bytes()[..],
)
.unwrap(),
);
}
let response = tiny_http::Response::new( let response = tiny_http::Response::new(
tiny_http::StatusCode(200), tiny_http::StatusCode(200),
request.headers().to_vec(), headers,
std::io::Cursor::new(body), std::io::Cursor::new(body),
request.body_length(), request.body_length(),
None, None,

Loading…
Cancel
Save