forked from Soroban-Pulse/SorobanPulse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch2.py
More file actions
69 lines (60 loc) · 2.29 KB
/
patch2.py
File metadata and controls
69 lines (60 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
with open('src/handlers.rs', 'r') as f:
c = f.read()
# ETag injection into cursor path of get_events_by_contract
c = c.replace(
""" let columns = resolve_columns(¶ms)?;
let events = rows_to_json(
&rows,
&columns,
state.encryption_key.as_ref(),
state.encryption_key_old.as_ref(),
params.compact.unwrap_or(false),
)?;
let mut response = json!({""",
""" let columns = resolve_columns(¶ms)?;
let events = rows_to_json(
&rows,
&columns,
state.encryption_key.as_ref(),
state.encryption_key_old.as_ref(),
params.compact.unwrap_or(false),
)?;
let etag = rows.first().and_then(|row| {
let id: Option<uuid::Uuid> = row.try_get("id").ok();
let created_at: Option<chrono::DateTime<chrono::Utc>> = row.try_get("created_at").ok();
id.zip(created_at)
.map(|(id, ca)| compute_etag(&id, &ca, None))
});
if let Some(ref tag) = etag {
if let Some(inm) = headers.get("if-none-match").and_then(|v| v.to_str().ok()) {
if inm == tag {
let resp = axum::http::Response::builder()
.status(axum::http::StatusCode::NOT_MODIFIED)
.header("ETag", tag.as_str())
.header("Cache-Control", "no-cache")
.body(axum::body::Body::empty())
.unwrap();
return Ok(resp.into_response());
}
}
}
let mut response = json!({""")
# Modify return statement of cursor path
c = c.replace(
""" if let Some(tl) = params.to_ledger {
response["to_ledger"] = json!(tl);
}
return Ok(Json(response));
}""",
""" if let Some(tl) = params.to_ledger {
response["to_ledger"] = json!(tl);
}
let mut resp = Json(response).into_response();
if let Some(ref tag) = etag {
resp.headers_mut().insert("ETag", tag.parse().unwrap());
resp.headers_mut().insert("Cache-Control", "no-cache".parse().unwrap());
}
return Ok(resp);
}""")
with open('src/handlers.rs', 'w') as f:
f.write(c)