commit 1bbb2d50001a646ee86b30b13046b1a0420ab05c
parent 35892e308b3a97195e0dd5e4eb5e2438e035513a
Author: lash <dev@holbrook.no>
Date: Sun, 9 Oct 2022 15:53:55 +0000
Only trace on-demand, make identity in trace optional
Diffstat:
4 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,6 +1,7 @@
- 0.1.2
* verify pgp signature from reader instead of copying to memory
- * announce capabilities in headers
+ * announce capabilities in response headers
+ * only trace if requested in request headers
- 0.1.1
* Replace pgp package with sequoia-openpgp
- 0.1.0
diff --git a/src/main.rs b/src/main.rs
@@ -26,6 +26,8 @@ use std::io::{
use env_logger;
+use ascii::AsciiStr;
+
use wala::auth::{
AuthSpec,
AuthResult,
@@ -325,11 +327,19 @@ fn main() {
}
#[cfg(feature="trace")]
- trace_request(&spool_path, &result);
+ {
+ for h in req.headers() {
+ if h.field.equiv("X-Wala-Trace") {
+ let mut identity = false;
+ if h.value.eq_ignore_ascii_case(AsciiStr::from_ascii("identity").unwrap()) {
+ identity = true;
+ }
+ trace_request(&spool_path, &result, identity);
+ }
+ }
+ }
exec_response(req, result);
}
}
-
-
diff --git a/src/response.rs b/src/response.rs
@@ -32,7 +32,7 @@ pub fn origin_headers() -> Vec<Header> {
});
headers.push(Header{
field: HeaderField::from_str("Access-Control-Allow-Headers").unwrap(),
- value: AsciiString::from_ascii("Content-Type,Authorization,X-Filename").unwrap(),
+ value: AsciiString::from_ascii("Content-Type,Authorization,X-Filename,X-Wala-Trace").unwrap(),
});
let server_header_v = format!("wala/{}, tiny_http (Rust)", env!("CARGO_PKG_VERSION"));
diff --git a/src/trace.rs b/src/trace.rs
@@ -15,7 +15,7 @@ use crate::record::{
};
-pub fn trace_request(p: &Path, res: &RequestResult) {
+pub fn trace_request(p: &Path, res: &RequestResult, store_identity: bool) {
if res.typ != RequestResultType::Changed {
return;
}
@@ -35,19 +35,14 @@ pub fn trace_request(p: &Path, res: &RequestResult) {
let mut identity = String::new();
match &res.a {
Some(auth) => {
- if auth.active() {
+ if auth.active() && store_identity {
content = auth.identity.clone();
identity = hex::encode(&content);
- } else {
- rf = String::new();
}
},
None => {
},
}
- if rf.len() == 0 {
- return;
- }
let fp = p.join(&rf);
let mut f = File::create(fp).unwrap();
f.write(content.as_ref());