mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-12-04 13:56:23 +01:00
Merge main into feat/request-versioning
Conflicts were all at registration points; both sides are kept. Main now routes every write through one connection (#642): ClientDb only reads and writes go through `with_tx` on a WriteDb. Versioning follows: snapshot, restore, prune and the cascade delete move to WriteDb, while the lookups and the "has it changed" check stay on ClientDb. Callers take a write transaction the way their neighbours do: - The HTTP send snapshots in its own transaction from `resolve_send_inputs`, and a failure there (including not getting the writer) is still logged and swallowed, so the response just has no version. - gRPC and WebSocket connect snapshot inside the transaction that upserts the connection. - The snapshot and restore RPCs, on the desktop and in the browser host, each run in a transaction. - The request and workspace cascades live on main's WriteDb deletes. The Request Changed dropdown moves into the response pane's `statusLineRight` slot, since main moved the status line into the shared pane view. The plugin runtime's copy of the model bindings picks up `versionId`, and `gen_rpc.ts` is regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
1b0a196c50
794 files changed
+76953
-18061
No files matched your search
@@ -6,9 +6,10 @@ publish = false
|
||||
|
||||
[dependencies]
|
||||
async-trait = "0.1"
|
||||
base64 = "0.22.1" # For carrying body chunks over a text-only plugin transport
|
||||
base64 = "0.23.1" # For carrying body chunks over a text-only plugin transport
|
||||
log = { workspace = true }
|
||||
md5 = "0.8.0"
|
||||
sha2 = { workspace = true }
|
||||
chrono = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
@@ -16,6 +17,7 @@ tokio = { workspace = true, features = ["sync", "rt"] }
|
||||
yaak-http = { workspace = true }
|
||||
yaak-core = { workspace = true }
|
||||
yaak-crypto = { workspace = true }
|
||||
yaak-filter = { workspace = true }
|
||||
yaak-models = { workspace = true }
|
||||
yaak-plugins = { workspace = true }
|
||||
yaak-templates = { workspace = true }
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
use crate::Result;
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
use yaak_models::query_manager::QueryManager;
|
||||
use yaak_models::util::get_workspace_export_resources;
|
||||
|
||||
pub struct ExportDataParams<'a> {
|
||||
pub query_manager: &'a QueryManager,
|
||||
pub yaak_version: &'a str,
|
||||
pub export_path: &'a Path,
|
||||
pub workspace_ids: Vec<&'a str>,
|
||||
pub include_private_environments: bool,
|
||||
}
|
||||
|
||||
pub fn export_data(params: ExportDataParams<'_>) -> Result<()> {
|
||||
let db = params.query_manager.connect();
|
||||
let export_data = get_workspace_export_resources(
|
||||
&db,
|
||||
params.yaak_version,
|
||||
params.workspace_ids,
|
||||
params.include_private_environments,
|
||||
)?;
|
||||
|
||||
let file = File::options().create(true).truncate(true).write(true).open(params.export_path)?;
|
||||
serde_json::to_writer_pretty(&file, &export_data)?;
|
||||
file.sync_all()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
+1833
-294
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,172 @@
|
||||
use serde_json::Value;
|
||||
use std::collections::BTreeMap;
|
||||
use yaak_models::util::BatchUpsertResult;
|
||||
use yaak_templates::{Parser, Token, Val};
|
||||
|
||||
/// Rewrite request references at each ID-assignment step (initial import and linked reimport).
|
||||
/// Literal text, missing targets and arguments to unrelated functions must not be rewritten.
|
||||
pub(crate) fn remap_request_references(
|
||||
resources: &mut BatchUpsertResult,
|
||||
ids: &BTreeMap<String, String>,
|
||||
) -> serde_json::Result<()> {
|
||||
if ids.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
let mut value = serde_json::to_value(&resources)?;
|
||||
remap_value(&mut value, ids);
|
||||
*resources = serde_json::from_value(value)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn remap_value(value: &mut Value, ids: &BTreeMap<String, String>) {
|
||||
match value {
|
||||
Value::String(text) => *text = remap_text(text, ids),
|
||||
Value::Array(values) => values.iter_mut().for_each(|v| remap_value(v, ids)),
|
||||
Value::Object(values) => values.values_mut().for_each(|v| remap_value(v, ids)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn remap_argument(value: &mut Val, ids: &BTreeMap<String, String>) -> bool {
|
||||
let Val::Fn { name, args } = value else {
|
||||
return false;
|
||||
};
|
||||
let request_arg = match name.as_str() {
|
||||
"response" | "response.body.raw" | "response.body.path" | "response.header" => "request",
|
||||
"request.body" | "request.body.raw" | "request.body.path" | "request.header"
|
||||
| "request.param" | "request.name" => "requestId",
|
||||
_ => "",
|
||||
};
|
||||
let mut changed = false;
|
||||
for arg in args {
|
||||
if arg.name == request_arg
|
||||
&& let Val::Str { text } = &mut arg.value
|
||||
&& let Some(id) = ids.get(text)
|
||||
&& id != text
|
||||
{
|
||||
*text = id.clone();
|
||||
changed = true;
|
||||
}
|
||||
changed |= remap_argument(&mut arg.value, ids);
|
||||
}
|
||||
changed
|
||||
}
|
||||
|
||||
fn remap_text(text: &str, ids: &BTreeMap<String, String>) -> String {
|
||||
// Parse individual unescaped tags. Parsing/reprinting the whole string would unescape raw
|
||||
// template-looking text, and change formatting even when no reference needs updating.
|
||||
let bytes = text.as_bytes();
|
||||
let mut output = String::new();
|
||||
let mut copied = 0;
|
||||
let mut cursor = 0;
|
||||
while let Some(relative) = text[cursor..].find("${[") {
|
||||
let start = cursor + relative;
|
||||
cursor = start + 3;
|
||||
let escapes = bytes[..start].iter().rev().take_while(|&&b| b == b'\\').count();
|
||||
if escapes % 2 != 0 {
|
||||
continue;
|
||||
}
|
||||
let mut end = cursor;
|
||||
let mut quoted = false;
|
||||
while end < bytes.len() {
|
||||
if quoted && bytes[end] == b'\\' {
|
||||
end += 2;
|
||||
continue;
|
||||
}
|
||||
if bytes[end] == b'\'' {
|
||||
quoted = !quoted;
|
||||
}
|
||||
if !quoted && bytes[end..].starts_with(b"]}") {
|
||||
end += 2;
|
||||
break;
|
||||
}
|
||||
end += 1;
|
||||
}
|
||||
if end > bytes.len() || !text[start..end].ends_with("]}") {
|
||||
continue;
|
||||
}
|
||||
if let Ok(mut tokens) = Parser::new(&text[start..end]).parse()
|
||||
&& let [Token::Tag { val }, Token::Eof] = tokens.tokens.as_mut_slice()
|
||||
&& remap_argument(val, ids)
|
||||
{
|
||||
output.push_str(&text[copied..start]);
|
||||
output.push_str(&tokens.to_string());
|
||||
copied = end;
|
||||
}
|
||||
cursor = end;
|
||||
}
|
||||
output.push_str(&text[copied..]);
|
||||
output
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn ids() -> BTreeMap<String, String> {
|
||||
BTreeMap::from([("req_old".into(), "rq_new".into())])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_remaps_known_literal_request_arguments() {
|
||||
let text = "${[ response.header(request='req_old', header='req_old') ]}";
|
||||
assert_eq!(
|
||||
remap_text(text, &ids()),
|
||||
"${[ response.header(request='rq_new', header='req_old') ]}"
|
||||
);
|
||||
for text in [
|
||||
"req_old",
|
||||
"${[ custom(request='req_old') ]}",
|
||||
"${[ response.header(request=req_old) ]}",
|
||||
"${[ response.header(request='req_missing') ]}",
|
||||
"${[ response.header(request='req_old' ]}",
|
||||
] {
|
||||
assert_eq!(remap_text(text, &ids()), text);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn handles_encoded_nested_and_escaped_tags_without_changing_surrounding_text() {
|
||||
let text = r#"café \${[ response.header(request='req_old') ]} ${[ json.jsonpath(input=response.body.raw(request=b64'cmVxX29sZA')) ]} end"#;
|
||||
assert_eq!(
|
||||
remap_text(text, &ids()),
|
||||
r#"café \${[ response.header(request='req_old') ]} ${[ json.jsonpath(input=response.body.raw(request='rq_new')) ]} end"#
|
||||
);
|
||||
let text = "${[ response.header(request='req_old', header=']}' ) ]}";
|
||||
assert!(remap_text(text, &ids()).contains("request='rq_new'"));
|
||||
}
|
||||
|
||||
/// Only the request ID may change. Every other argument keeps its name, order, spacing and
|
||||
/// plain single-quoted form, so a printer that falls back to base64 for values like
|
||||
/// `X-Api-Key` or `$.token` fails here.
|
||||
#[test]
|
||||
fn remapping_a_request_keeps_the_other_arguments_verbatim() {
|
||||
assert_eq!(
|
||||
remap_text("${[ response.header(request='req_old', header='X-Api-Key') ]}", &ids()),
|
||||
"${[ response.header(request='rq_new', header='X-Api-Key') ]}"
|
||||
);
|
||||
assert_eq!(
|
||||
remap_text(
|
||||
"${[ response.body.path(request='req_old', path='$.token', behavior='never') ]}",
|
||||
&ids()
|
||||
),
|
||||
"${[ response.body.path(request='rq_new', path='$.token', behavior='never') ]}"
|
||||
);
|
||||
}
|
||||
|
||||
/// An Insomnia tag that never got converted is plain text, even though it names a request
|
||||
/// that is being remapped. It must survive byte-for-byte, including alongside a real tag.
|
||||
#[test]
|
||||
fn unconverted_nunjucks_text_containing_a_request_id_is_untouched() {
|
||||
let text = "{% response 'raw', 'req_old', '', 'never', 60 %}";
|
||||
assert_eq!(remap_text(text, &ids()), text);
|
||||
|
||||
assert_eq!(
|
||||
remap_text(
|
||||
"${[ response.body.path(request='req_old', path='$.a') ]} and {% response 'raw', 'req_old' %}",
|
||||
&ids()
|
||||
),
|
||||
"${[ response.body.path(request='rq_new', path='$.a') ]} and {% response 'raw', 'req_old' %}"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
pub mod error;
|
||||
pub mod export;
|
||||
pub mod import;
|
||||
mod import_templates;
|
||||
pub mod plugin_events;
|
||||
pub mod response_body;
|
||||
pub mod send;
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
use crate::response_body::ResponseBodyStore;
|
||||
use base64::Engine;
|
||||
use base64::prelude::BASE64_STANDARD;
|
||||
use log::warn;
|
||||
use yaak_models::models::AnyModel;
|
||||
use yaak_models::query_manager::QueryManager;
|
||||
use yaak_models::util::UpdateSource;
|
||||
use yaak_plugins::events::{
|
||||
CloseWindowRequest, CopyTextRequest, DeleteKeyValueRequest, DeleteKeyValueResponse,
|
||||
DeleteModelRequest, DeleteModelResponse, ErrorResponse, FindHttpResponsesRequest,
|
||||
FindHttpResponsesResponse, GetCookieValueRequest, GetHttpRequestByIdRequest,
|
||||
GetHttpRequestByIdResponse, GetHttpResponseBodyInfoRequest, GetHttpResponseBodyInfoResponse,
|
||||
GetKeyValueRequest, GetKeyValueResponse, InternalEventPayload, ListCookieNamesRequest,
|
||||
ListFoldersRequest, ListFoldersResponse, ListHttpRequestsRequest, ListHttpRequestsResponse,
|
||||
ListOpenWorkspacesRequest, OpenExternalUrlRequest, OpenWindowRequest, PromptFormRequest,
|
||||
PromptTextRequest, ReadHttpResponseBodyChunkRequest, ReadHttpResponseBodyChunkResponse,
|
||||
ReloadResponse, RenderGrpcRequestRequest, RenderHttpRequestRequest, SendHttpRequestRequest,
|
||||
SetKeyValueRequest, ShowToastRequest, TemplateRenderRequest, UpsertModelRequest,
|
||||
UpsertModelResponse, WindowInfoRequest,
|
||||
DeleteModelRequest, DeleteModelResponse, ErrorResponse, FilterLanguage, FilterResponse,
|
||||
FilterTextRequest, FindHttpResponsesRequest, FindHttpResponsesResponse, GetCookieValueRequest,
|
||||
GetHttpRequestByIdRequest, GetHttpRequestByIdResponse, GetHttpResponseBodyInfoRequest,
|
||||
GetHttpResponseBodyInfoResponse, GetKeyValueRequest, GetKeyValueResponse, InternalEventPayload,
|
||||
ListCookieNamesRequest, ListFoldersRequest, ListFoldersResponse, ListHttpRequestsRequest,
|
||||
ListHttpRequestsResponse, ListOpenWorkspacesRequest, OpenExternalUrlRequest, OpenWindowRequest,
|
||||
PromptFormRequest, PromptTextRequest, ReadHttpResponseBodyChunkRequest,
|
||||
ReadHttpResponseBodyChunkResponse, ReloadResponse, RenderGrpcRequestRequest,
|
||||
RenderHttpRequestRequest, SendHttpRequestRequest, SetKeyValueRequest, ShowToastRequest,
|
||||
TemplateRenderRequest, UpsertModelRequest, UpsertModelResponse, WindowInfoRequest,
|
||||
};
|
||||
|
||||
pub struct SharedPluginEventContext<'a> {
|
||||
@@ -49,6 +50,7 @@ pub enum SharedRequest<'a> {
|
||||
ReadHttpResponseBodyChunk(&'a ReadHttpResponseBodyChunkRequest),
|
||||
UpsertModel(&'a UpsertModelRequest),
|
||||
DeleteModel(&'a DeleteModelRequest),
|
||||
FilterText(&'a FilterTextRequest),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -155,6 +157,9 @@ impl<'a> From<&'a InternalEventPayload> for GroupedPluginRequest<'a> {
|
||||
InternalEventPayload::DeleteModelRequest(req) => {
|
||||
GroupedPluginRequest::Shared(SharedRequest::DeleteModel(req))
|
||||
}
|
||||
InternalEventPayload::FilterTextRequest(req) => {
|
||||
GroupedPluginRequest::Shared(SharedRequest::FilterText(req))
|
||||
}
|
||||
InternalEventPayload::RenderGrpcRequestRequest(req) => {
|
||||
GroupedPluginRequest::Host(HostRequest::RenderGrpcRequest(req))
|
||||
}
|
||||
@@ -226,11 +231,18 @@ fn build_shared_reply(
|
||||
InternalEventPayload::GetKeyValueResponse(GetKeyValueResponse { value })
|
||||
}
|
||||
SharedRequest::SetKeyValue(req) => {
|
||||
query_manager.connect().set_plugin_key_value(context.plugin_name, &req.key, &req.value);
|
||||
if let Err(e) = query_manager.with_tx(|tx| {
|
||||
tx.set_plugin_key_value(context.plugin_name, &req.key, &req.value);
|
||||
Ok::<(), yaak_models::error::Error>(())
|
||||
}) {
|
||||
warn!("Failed to set plugin key value: {e}");
|
||||
}
|
||||
InternalEventPayload::SetKeyValueResponse(yaak_plugins::events::SetKeyValueResponse {})
|
||||
}
|
||||
SharedRequest::DeleteKeyValue(req) => {
|
||||
match query_manager.connect().delete_plugin_key_value(context.plugin_name, &req.key) {
|
||||
match query_manager
|
||||
.with_tx(|tx| tx.delete_plugin_key_value(context.plugin_name, &req.key))
|
||||
{
|
||||
Ok(deleted) => {
|
||||
InternalEventPayload::DeleteKeyValueResponse(DeleteKeyValueResponse { deleted })
|
||||
}
|
||||
@@ -331,7 +343,9 @@ fn build_shared_reply(
|
||||
|
||||
let model = match &req.model {
|
||||
HttpRequest(m) => {
|
||||
match query_manager.connect().upsert_http_request(m, &UpdateSource::Plugin) {
|
||||
match query_manager
|
||||
.with_tx(|tx| tx.upsert_http_request(m, &UpdateSource::Plugin))
|
||||
{
|
||||
Ok(model) => HttpRequest(model),
|
||||
Err(err) => {
|
||||
return InternalEventPayload::ErrorResponse(ErrorResponse {
|
||||
@@ -341,7 +355,9 @@ fn build_shared_reply(
|
||||
}
|
||||
}
|
||||
GrpcRequest(m) => {
|
||||
match query_manager.connect().upsert_grpc_request(m, &UpdateSource::Plugin) {
|
||||
match query_manager
|
||||
.with_tx(|tx| tx.upsert_grpc_request(m, &UpdateSource::Plugin))
|
||||
{
|
||||
Ok(model) => GrpcRequest(model),
|
||||
Err(err) => {
|
||||
return InternalEventPayload::ErrorResponse(ErrorResponse {
|
||||
@@ -351,7 +367,8 @@ fn build_shared_reply(
|
||||
}
|
||||
}
|
||||
WebsocketRequest(m) => {
|
||||
match query_manager.connect().upsert_websocket_request(m, &UpdateSource::Plugin)
|
||||
match query_manager
|
||||
.with_tx(|tx| tx.upsert_websocket_request(m, &UpdateSource::Plugin))
|
||||
{
|
||||
Ok(model) => WebsocketRequest(model),
|
||||
Err(err) => {
|
||||
@@ -362,7 +379,7 @@ fn build_shared_reply(
|
||||
}
|
||||
}
|
||||
Folder(m) => {
|
||||
match query_manager.connect().upsert_folder(m, &UpdateSource::Plugin) {
|
||||
match query_manager.with_tx(|tx| tx.upsert_folder(m, &UpdateSource::Plugin)) {
|
||||
Ok(model) => Folder(model),
|
||||
Err(err) => {
|
||||
return InternalEventPayload::ErrorResponse(ErrorResponse {
|
||||
@@ -372,7 +389,9 @@ fn build_shared_reply(
|
||||
}
|
||||
}
|
||||
Environment(m) => {
|
||||
match query_manager.connect().upsert_environment(m, &UpdateSource::Plugin) {
|
||||
match query_manager
|
||||
.with_tx(|tx| tx.upsert_environment(m, &UpdateSource::Plugin))
|
||||
{
|
||||
Ok(model) => Environment(model),
|
||||
Err(err) => {
|
||||
return InternalEventPayload::ErrorResponse(ErrorResponse {
|
||||
@@ -382,7 +401,8 @@ fn build_shared_reply(
|
||||
}
|
||||
}
|
||||
Workspace(m) => {
|
||||
match query_manager.connect().upsert_workspace(m, &UpdateSource::Plugin) {
|
||||
match query_manager.with_tx(|tx| tx.upsert_workspace(m, &UpdateSource::Plugin))
|
||||
{
|
||||
Ok(model) => Workspace(model),
|
||||
Err(err) => {
|
||||
return InternalEventPayload::ErrorResponse(ErrorResponse {
|
||||
@@ -404,8 +424,7 @@ fn build_shared_reply(
|
||||
let model = match req.model.as_str() {
|
||||
"http_request" => {
|
||||
match query_manager
|
||||
.connect()
|
||||
.delete_http_request_by_id(&req.id, &UpdateSource::Plugin)
|
||||
.with_tx(|tx| tx.delete_http_request_by_id(&req.id, &UpdateSource::Plugin))
|
||||
{
|
||||
Ok(model) => AnyModel::HttpRequest(model),
|
||||
Err(err) => {
|
||||
@@ -417,8 +436,7 @@ fn build_shared_reply(
|
||||
}
|
||||
"grpc_request" => {
|
||||
match query_manager
|
||||
.connect()
|
||||
.delete_grpc_request_by_id(&req.id, &UpdateSource::Plugin)
|
||||
.with_tx(|tx| tx.delete_grpc_request_by_id(&req.id, &UpdateSource::Plugin))
|
||||
{
|
||||
Ok(model) => AnyModel::GrpcRequest(model),
|
||||
Err(err) => {
|
||||
@@ -429,10 +447,9 @@ fn build_shared_reply(
|
||||
}
|
||||
}
|
||||
"websocket_request" => {
|
||||
match query_manager
|
||||
.connect()
|
||||
.delete_websocket_request_by_id(&req.id, &UpdateSource::Plugin)
|
||||
{
|
||||
match query_manager.with_tx(|tx| {
|
||||
tx.delete_websocket_request_by_id(&req.id, &UpdateSource::Plugin)
|
||||
}) {
|
||||
Ok(model) => AnyModel::WebsocketRequest(model),
|
||||
Err(err) => {
|
||||
return InternalEventPayload::ErrorResponse(ErrorResponse {
|
||||
@@ -442,8 +459,7 @@ fn build_shared_reply(
|
||||
}
|
||||
}
|
||||
"folder" => match query_manager
|
||||
.connect()
|
||||
.delete_folder_by_id(&req.id, &UpdateSource::Plugin)
|
||||
.with_tx(|tx| tx.delete_folder_by_id(&req.id, &UpdateSource::Plugin))
|
||||
{
|
||||
Ok(model) => AnyModel::Folder(model),
|
||||
Err(err) => {
|
||||
@@ -454,8 +470,7 @@ fn build_shared_reply(
|
||||
},
|
||||
"environment" => {
|
||||
match query_manager
|
||||
.connect()
|
||||
.delete_environment_by_id(&req.id, &UpdateSource::Plugin)
|
||||
.with_tx(|tx| tx.delete_environment_by_id(&req.id, &UpdateSource::Plugin))
|
||||
{
|
||||
Ok(model) => AnyModel::Environment(model),
|
||||
Err(err) => {
|
||||
@@ -474,6 +489,17 @@ fn build_shared_reply(
|
||||
|
||||
InternalEventPayload::DeleteModelResponse(DeleteModelResponse { model })
|
||||
}
|
||||
SharedRequest::FilterText(req) => {
|
||||
let language = match req.language {
|
||||
FilterLanguage::JsonPath => yaak_filter::Language::JsonPath,
|
||||
FilterLanguage::XPath => yaak_filter::Language::XPath,
|
||||
};
|
||||
let result = yaak_filter::filter(language, &req.text, &req.query);
|
||||
InternalEventPayload::FilterTextResponse(FilterResponse {
|
||||
content: result.content,
|
||||
error: result.error,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -508,45 +534,38 @@ mod tests {
|
||||
yaak_models::init_standalone(&db_path, &blob_path).expect("Failed to initialize DB");
|
||||
|
||||
query_manager
|
||||
.connect()
|
||||
.upsert_workspace(
|
||||
&Workspace {
|
||||
id: "wk_test".to_string(),
|
||||
name: "Workspace".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
.expect("Failed to seed workspace");
|
||||
|
||||
query_manager
|
||||
.connect()
|
||||
.upsert_folder(
|
||||
&Folder {
|
||||
id: "fl_test".to_string(),
|
||||
workspace_id: "wk_test".to_string(),
|
||||
name: "Folder".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
.expect("Failed to seed folder");
|
||||
|
||||
query_manager
|
||||
.connect()
|
||||
.upsert_http_request(
|
||||
&HttpRequest {
|
||||
id: "rq_test".to_string(),
|
||||
workspace_id: "wk_test".to_string(),
|
||||
folder_id: Some("fl_test".to_string()),
|
||||
name: "Request".to_string(),
|
||||
method: "GET".to_string(),
|
||||
url: "https://example.com".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
.expect("Failed to seed request");
|
||||
.with_tx(|tx| {
|
||||
tx.upsert_workspace(
|
||||
&Workspace {
|
||||
id: "wk_test".to_string(),
|
||||
name: "Workspace".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
&UpdateSource::Sync,
|
||||
)?;
|
||||
tx.upsert_folder(
|
||||
&Folder {
|
||||
id: "fl_test".to_string(),
|
||||
workspace_id: "wk_test".to_string(),
|
||||
name: "Folder".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
&UpdateSource::Sync,
|
||||
)?;
|
||||
tx.upsert_http_request(
|
||||
&HttpRequest {
|
||||
id: "rq_test".to_string(),
|
||||
workspace_id: "wk_test".to_string(),
|
||||
folder_id: Some("fl_test".to_string()),
|
||||
name: "Request".to_string(),
|
||||
method: "GET".to_string(),
|
||||
url: "https://example.com".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
})
|
||||
.expect("Failed to seed");
|
||||
|
||||
(query_manager, temp_dir)
|
||||
}
|
||||
@@ -634,6 +653,40 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filter_text_is_shared_handled() {
|
||||
let (query_manager, _temp_dir) = seed_query_manager();
|
||||
let cases = [
|
||||
(FilterLanguage::JsonPath, r#"{"a":[1,2]}"#, "$.a[1]", "[\n 2\n]", None),
|
||||
(FilterLanguage::XPath, "<a><b>x</b></a>", "//b", "<b>x</b>", None),
|
||||
(FilterLanguage::JsonPath, "{}", "$[?(@ ==)]", "", Some("Invalid filter: ")),
|
||||
];
|
||||
for (language, text, query, content, error) in cases {
|
||||
let payload = InternalEventPayload::FilterTextRequest(FilterTextRequest {
|
||||
language,
|
||||
text: text.to_string(),
|
||||
query: query.to_string(),
|
||||
});
|
||||
let result = dispatch(
|
||||
&query_manager,
|
||||
&payload,
|
||||
SharedPluginEventContext { plugin_name: "@yaak/test", workspace_id: None },
|
||||
);
|
||||
match result {
|
||||
GroupedPluginEvent::Handled(Some(InternalEventPayload::FilterTextResponse(
|
||||
resp,
|
||||
))) => {
|
||||
assert_eq!(resp.content, content, "{query}");
|
||||
assert_eq!(resp.error.is_some(), error.is_some(), "{query}");
|
||||
if let (Some(actual), Some(prefix)) = (resp.error, error) {
|
||||
assert!(actual.starts_with(prefix), "{actual}");
|
||||
}
|
||||
}
|
||||
other => panic!("unexpected filter result: {other:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A store that answers from memory, standing in for whatever holds the
|
||||
/// bytes — the point being that the dispatch below never learns which.
|
||||
struct FakeBodyStore {
|
||||
@@ -668,9 +721,10 @@ mod tests {
|
||||
let (query_manager, _temp_dir) = seed_query_manager();
|
||||
let store = FakeBodyStore { body: b"hello".to_vec(), reads: RefCell::new(Vec::new()) };
|
||||
|
||||
let info_payload = InternalEventPayload::GetHttpResponseBodyInfoRequest(
|
||||
GetHttpResponseBodyInfoRequest { response_id: "rs_test".to_string() },
|
||||
);
|
||||
let info_payload =
|
||||
InternalEventPayload::GetHttpResponseBodyInfoRequest(GetHttpResponseBodyInfoRequest {
|
||||
response_id: "rs_test".to_string(),
|
||||
});
|
||||
let info = handle_shared_plugin_event(
|
||||
&query_manager,
|
||||
&store,
|
||||
@@ -716,9 +770,10 @@ mod tests {
|
||||
#[test]
|
||||
fn an_unreadable_response_body_becomes_an_error_reply() {
|
||||
let (query_manager, _temp_dir) = seed_query_manager();
|
||||
let payload = InternalEventPayload::GetHttpResponseBodyInfoRequest(
|
||||
GetHttpResponseBodyInfoRequest { response_id: "rs_never_persisted".to_string() },
|
||||
);
|
||||
let payload =
|
||||
InternalEventPayload::GetHttpResponseBodyInfoRequest(GetHttpResponseBodyInfoRequest {
|
||||
response_id: "rs_never_persisted".to_string(),
|
||||
});
|
||||
let result = dispatch(
|
||||
&query_manager,
|
||||
&payload,
|
||||
@@ -727,7 +782,11 @@ mod tests {
|
||||
|
||||
match result {
|
||||
GroupedPluginEvent::Handled(Some(InternalEventPayload::ErrorResponse(resp))) => {
|
||||
assert!(resp.error.contains("rs_never_persisted"), "unhelpful error: {}", resp.error)
|
||||
assert!(
|
||||
resp.error.contains("rs_never_persisted"),
|
||||
"unhelpful error: {}",
|
||||
resp.error
|
||||
)
|
||||
}
|
||||
other => panic!("unexpected missing-response result: {other:?}"),
|
||||
}
|
||||
|
||||
@@ -126,23 +126,25 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
query_manager
|
||||
.connect()
|
||||
.upsert_workspace(
|
||||
&Workspace { id: "wk_test".to_string(), ..Default::default() },
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
.with_tx(|tx| {
|
||||
tx.upsert_workspace(
|
||||
&Workspace { id: "wk_test".to_string(), ..Default::default() },
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
query_manager
|
||||
.connect()
|
||||
.upsert_http_request(
|
||||
&HttpRequest {
|
||||
id: "rq_test".to_string(),
|
||||
workspace_id: "wk_test".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
.with_tx(|tx| {
|
||||
tx.upsert_http_request(
|
||||
&HttpRequest {
|
||||
id: "rq_test".to_string(),
|
||||
workspace_id: "wk_test".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let body_path = body.map(|bytes| {
|
||||
@@ -153,21 +155,22 @@ mod tests {
|
||||
});
|
||||
|
||||
let response = query_manager
|
||||
.connect()
|
||||
.upsert_http_response(
|
||||
&HttpResponse {
|
||||
workspace_id: "wk_test".to_string(),
|
||||
request_id: "rq_test".to_string(),
|
||||
body_path,
|
||||
headers: vec![HttpResponseHeader {
|
||||
name: "Content-Type".to_string(),
|
||||
value: "application/json; charset=utf-8".to_string(),
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
&UpdateSource::Sync,
|
||||
&blob_manager,
|
||||
)
|
||||
.with_tx(|tx| {
|
||||
tx.upsert_http_response(
|
||||
&HttpResponse {
|
||||
workspace_id: "wk_test".to_string(),
|
||||
request_id: "rq_test".to_string(),
|
||||
body_path,
|
||||
headers: vec![HttpResponseHeader {
|
||||
name: "Content-Type".to_string(),
|
||||
value: "application/json; charset=utf-8".to_string(),
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
&UpdateSource::Sync,
|
||||
&blob_manager,
|
||||
)
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let id = response.id.clone();
|
||||
@@ -209,7 +212,7 @@ mod tests {
|
||||
|
||||
let mut response = qm.connect().get_http_response(&id).unwrap();
|
||||
response.state = HttpResponseState::Closed;
|
||||
qm.connect().update_http_response_if_id(&response, &UpdateSource::Sync).unwrap();
|
||||
qm.with_tx(|tx| tx.update_http_response_if_id(&response, &UpdateSource::Sync)).unwrap();
|
||||
|
||||
assert!(FileResponseBodyStore::new(&qm).info(&id).unwrap().complete);
|
||||
}
|
||||
|
||||
+121
-108
@@ -21,7 +21,7 @@ use yaak_http::transaction::HttpTransaction;
|
||||
use yaak_http::types::{
|
||||
SendableBody, SendableHttpRequest, SendableHttpRequestOptions, append_query_params,
|
||||
};
|
||||
use yaak_models::blob_manager::{BlobManager, BodyChunk};
|
||||
use yaak_models::blob_manager::{BODY_CHUNK_SIZE, BlobManager, BodyChunk, BodyChunkWriter};
|
||||
use yaak_models::models::{
|
||||
ClientCertificate, Cookie, CookieJar, DnsOverride, Environment, HttpRequest, HttpResponse,
|
||||
HttpResponseEvent, HttpResponseEventData, HttpResponseHeader, HttpResponseState,
|
||||
@@ -40,7 +40,6 @@ use yaak_templates::{RenderOptions, TemplateCallback};
|
||||
use yaak_tls::find_client_certificate;
|
||||
|
||||
const HTTP_EVENT_CHANNEL_CAPACITY: usize = 100;
|
||||
const REQUEST_BODY_CHUNK_SIZE: usize = 1024 * 1024;
|
||||
const RESPONSE_PROGRESS_UPDATE_INTERVAL_MS: u128 = 100;
|
||||
const MAX_AUTH_BODY_BYTES: usize = 10 * 1024 * 1024;
|
||||
|
||||
@@ -444,10 +443,28 @@ pub fn resolve_send_inputs(
|
||||
// should put back. Every host reaches sending through this function — the desktop,
|
||||
// the CLI, plugin-triggered sends — so every response gets a version without each
|
||||
// of them remembering to ask for one.
|
||||
version_id: db.snapshot_request_for_send(&AnyRequest::HttpRequest(request.clone())),
|
||||
version_id: snapshot_request_for_send(query_manager, request),
|
||||
})
|
||||
}
|
||||
|
||||
/// Capture the request in its own transaction. Like the snapshot itself, a failure
|
||||
/// to get the write connection is not worth failing the send over.
|
||||
fn snapshot_request_for_send(
|
||||
query_manager: &QueryManager,
|
||||
request: &HttpRequest,
|
||||
) -> Option<String> {
|
||||
query_manager
|
||||
.with_tx(|tx| {
|
||||
Ok::<_, yaak_models::error::Error>(
|
||||
tx.snapshot_request_for_send(&AnyRequest::HttpRequest(request.clone())),
|
||||
)
|
||||
})
|
||||
.unwrap_or_else(|err| {
|
||||
warn!("Failed to snapshot request before send: {err}");
|
||||
None
|
||||
})
|
||||
}
|
||||
|
||||
/// Apply the authentication and headers a request inherits from its folder or workspace.
|
||||
pub fn resolve_inherited_request(
|
||||
query_manager: &QueryManager,
|
||||
@@ -659,8 +676,9 @@ pub async fn send_http_request<T: TemplateCallback>(
|
||||
if let Some(store) = store {
|
||||
response = store
|
||||
.query_manager
|
||||
.connect()
|
||||
.upsert_http_response(&response, &store.update_source, store.blob_manager)
|
||||
.with_tx(|tx| {
|
||||
tx.upsert_http_response(&response, &store.update_source, store.blob_manager)
|
||||
})
|
||||
.map_err(SendHttpRequestError::PersistResponse)?;
|
||||
} else if response.id.is_empty() {
|
||||
response.id = generate_prefixed_id("rs");
|
||||
@@ -713,8 +731,8 @@ pub async fn send_http_request<T: TemplateCallback>(
|
||||
&event_workspace_id,
|
||||
event.clone().into(),
|
||||
);
|
||||
if let Err(err) =
|
||||
query_manager.connect().upsert_http_response_event(&db_event, update_source)
|
||||
if let Err(err) = query_manager
|
||||
.with_tx(|tx| tx.upsert_http_response_event(&db_event, update_source))
|
||||
{
|
||||
warn!("Failed to persist HTTP response event: {}", err);
|
||||
}
|
||||
@@ -812,8 +830,13 @@ pub async fn send_http_request<T: TemplateCallback>(
|
||||
if let Some(store) = store {
|
||||
response = store
|
||||
.query_manager
|
||||
.connect()
|
||||
.upsert_http_response(&connected_response, &store.update_source, store.blob_manager)
|
||||
.with_tx(|tx| {
|
||||
tx.upsert_http_response(
|
||||
&connected_response,
|
||||
&store.update_source,
|
||||
store.blob_manager,
|
||||
)
|
||||
})
|
||||
.map_err(SendHttpRequestError::PersistResponse)?;
|
||||
} else {
|
||||
response = connected_response;
|
||||
@@ -899,12 +922,13 @@ pub async fn send_http_request<T: TemplateCallback>(
|
||||
if let Some(store) = store {
|
||||
response = store
|
||||
.query_manager
|
||||
.connect()
|
||||
.upsert_http_response(
|
||||
&progress_response,
|
||||
&store.update_source,
|
||||
store.blob_manager,
|
||||
)
|
||||
.with_tx(|tx| {
|
||||
tx.upsert_http_response(
|
||||
&progress_response,
|
||||
&store.update_source,
|
||||
store.blob_manager,
|
||||
)
|
||||
})
|
||||
.map_err(SendHttpRequestError::PersistResponse)?;
|
||||
} else {
|
||||
response = progress_response;
|
||||
@@ -973,8 +997,9 @@ pub async fn send_http_request<T: TemplateCallback>(
|
||||
if let Some(store) = store {
|
||||
response = store
|
||||
.query_manager
|
||||
.connect()
|
||||
.upsert_http_response(&final_response, &store.update_source, store.blob_manager)
|
||||
.with_tx(|tx| {
|
||||
tx.upsert_http_response(&final_response, &store.update_source, store.blob_manager)
|
||||
})
|
||||
.map_err(SendHttpRequestError::PersistResponse)?;
|
||||
} else {
|
||||
response = final_response;
|
||||
@@ -1011,8 +1036,9 @@ pub async fn send_http_request<T: TemplateCallback>(
|
||||
if update_response && let Some(store) = store {
|
||||
response = store
|
||||
.query_manager
|
||||
.connect()
|
||||
.upsert_http_response(&response, &store.update_source, store.blob_manager)
|
||||
.with_tx(|tx| {
|
||||
tx.upsert_http_response(&response, &store.update_source, store.blob_manager)
|
||||
})
|
||||
.map_err(SendHttpRequestError::PersistResponse)?;
|
||||
}
|
||||
}
|
||||
@@ -1040,17 +1066,14 @@ fn persist_request_body_bytes(
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let blob_ctx = blob_manager.connect();
|
||||
let mut offset = 0;
|
||||
let mut chunk_index: i32 = 0;
|
||||
while offset < bytes.len() {
|
||||
let end = std::cmp::min(offset + REQUEST_BODY_CHUNK_SIZE, bytes.len());
|
||||
let chunk = BodyChunk::new(body_id, chunk_index, bytes[offset..end].to_vec());
|
||||
blob_ctx.insert_chunk(&chunk).map_err(|e| e.to_string())?;
|
||||
chunk_index += 1;
|
||||
offset = end;
|
||||
}
|
||||
Ok(())
|
||||
blob_manager
|
||||
.with_tx(|b| {
|
||||
for (chunk_index, data) in bytes.chunks(BODY_CHUNK_SIZE).enumerate() {
|
||||
b.insert_chunk(&BodyChunk::new(body_id, chunk_index as i32, data.to_vec()))?;
|
||||
}
|
||||
Ok::<_, yaak_models::error::Error>(())
|
||||
})
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
async fn persist_request_body_stream(
|
||||
@@ -1058,29 +1081,11 @@ async fn persist_request_body_stream(
|
||||
body_id: String,
|
||||
mut rx: tokio::sync::mpsc::UnboundedReceiver<Vec<u8>>,
|
||||
) -> std::result::Result<usize, String> {
|
||||
let mut chunk_index: i32 = 0;
|
||||
let mut total_bytes = 0usize;
|
||||
|
||||
// Stream reads arrive in small (eg. 8-16 KiB) pieces, so accumulate them into
|
||||
// full-size chunks to avoid thousands of tiny inserts for large bodies
|
||||
let mut buf: Vec<u8> = Vec::with_capacity(REQUEST_BODY_CHUNK_SIZE);
|
||||
let mut writer = BodyChunkWriter::new(blob_manager, body_id);
|
||||
while let Some(data) = rx.recv().await {
|
||||
total_bytes += data.len();
|
||||
buf.extend_from_slice(&data);
|
||||
while buf.len() >= REQUEST_BODY_CHUNK_SIZE {
|
||||
let data = buf.drain(..REQUEST_BODY_CHUNK_SIZE).collect();
|
||||
let chunk = BodyChunk::new(&body_id, chunk_index, data);
|
||||
blob_manager.connect().insert_chunk(&chunk).map_err(|e| e.to_string())?;
|
||||
chunk_index += 1;
|
||||
}
|
||||
writer.write(&data).map_err(|e| e.to_string())?;
|
||||
}
|
||||
|
||||
if !buf.is_empty() {
|
||||
let chunk = BodyChunk::new(&body_id, chunk_index, buf);
|
||||
blob_manager.connect().insert_chunk(&chunk).map_err(|e| e.to_string())?;
|
||||
}
|
||||
|
||||
Ok(total_bytes)
|
||||
writer.finish().map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
fn append_error_message(existing_error: Option<String>, message: String) -> String {
|
||||
@@ -1127,8 +1132,7 @@ pub fn persist_cookies_after_send(
|
||||
|
||||
cookie_jar.cookies = cookies;
|
||||
query_manager
|
||||
.connect()
|
||||
.upsert_cookie_jar(cookie_jar, &UpdateSource::Background)
|
||||
.with_tx(|tx| tx.upsert_cookie_jar(cookie_jar, &UpdateSource::Background))
|
||||
.map_err(SendHttpRequestError::PersistCookieJar)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -1222,23 +1226,24 @@ fn persist_response_error(
|
||||
let elapsed = duration_to_i32(started_at.elapsed());
|
||||
store
|
||||
.query_manager
|
||||
.connect()
|
||||
.upsert_http_response(
|
||||
&HttpResponse {
|
||||
state: HttpResponseState::Closed,
|
||||
elapsed,
|
||||
elapsed_headers: if response.elapsed_headers == 0 {
|
||||
elapsed
|
||||
} else {
|
||||
response.elapsed_headers
|
||||
.with_tx(|tx| {
|
||||
tx.upsert_http_response(
|
||||
&HttpResponse {
|
||||
state: HttpResponseState::Closed,
|
||||
elapsed,
|
||||
elapsed_headers: if response.elapsed_headers == 0 {
|
||||
elapsed
|
||||
} else {
|
||||
response.elapsed_headers
|
||||
},
|
||||
error: Some(error),
|
||||
url: if response.url.is_empty() { fallback_url } else { response.url.clone() },
|
||||
..response.clone()
|
||||
},
|
||||
error: Some(error),
|
||||
url: if response.url.is_empty() { fallback_url } else { response.url.clone() },
|
||||
..response.clone()
|
||||
},
|
||||
&store.update_source,
|
||||
store.blob_manager,
|
||||
)
|
||||
&store.update_source,
|
||||
store.blob_manager,
|
||||
)
|
||||
})
|
||||
.map_err(SendHttpRequestError::PersistResponse)
|
||||
}
|
||||
|
||||
@@ -1459,23 +1464,25 @@ mod tests {
|
||||
.expect("Failed to initialize DB");
|
||||
|
||||
query_manager
|
||||
.connect()
|
||||
.upsert_workspace(
|
||||
&Workspace { id: "wk_test".to_string(), ..Default::default() },
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
.with_tx(|tx| {
|
||||
tx.upsert_workspace(
|
||||
&Workspace { id: "wk_test".to_string(), ..Default::default() },
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
})
|
||||
.expect("Failed to seed workspace");
|
||||
let cookie_jar = query_manager
|
||||
.connect()
|
||||
.upsert_cookie_jar(
|
||||
&CookieJar {
|
||||
id: "cj_test".to_string(),
|
||||
workspace_id: "wk_test".to_string(),
|
||||
name: "Default".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
.with_tx(|tx| {
|
||||
tx.upsert_cookie_jar(
|
||||
&CookieJar {
|
||||
id: "cj_test".to_string(),
|
||||
workspace_id: "wk_test".to_string(),
|
||||
name: "Default".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
})
|
||||
.expect("Failed to seed cookie jar");
|
||||
|
||||
(query_manager, cookie_jar, temp_dir)
|
||||
@@ -1488,16 +1495,17 @@ mod tests {
|
||||
async fn a_stored_send_links_the_request_version_that_produced_it() {
|
||||
let (query_manager, blob_manager, temp_dir) = seed_send_storage();
|
||||
let request = query_manager
|
||||
.connect()
|
||||
.upsert_http_request(
|
||||
&HttpRequest {
|
||||
workspace_id: "wk_test".to_string(),
|
||||
url: "http://localhost/test".to_string(),
|
||||
name: "Original".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
.with_tx(|tx| {
|
||||
tx.upsert_http_request(
|
||||
&HttpRequest {
|
||||
workspace_id: "wk_test".to_string(),
|
||||
url: "http://localhost/test".to_string(),
|
||||
name: "Original".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
})
|
||||
.expect("Failed to seed request");
|
||||
|
||||
let first = stored_send(&query_manager, &blob_manager, temp_dir.path(), &request).await;
|
||||
@@ -1514,8 +1522,12 @@ mod tests {
|
||||
|
||||
// Editing after the fact is what the response pane has to be able to notice
|
||||
query_manager
|
||||
.connect()
|
||||
.upsert_http_request(&HttpRequest { name: "Edited".to_string(), ..request.clone() }, &UpdateSource::Sync)
|
||||
.with_tx(|tx| {
|
||||
tx.upsert_http_request(
|
||||
&HttpRequest { name: "Edited".to_string(), ..request.clone() },
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
})
|
||||
.expect("Failed to edit request");
|
||||
assert!(!db.request_matches_version(&version).expect("Failed to compare"));
|
||||
}
|
||||
@@ -1558,11 +1570,12 @@ mod tests {
|
||||
)
|
||||
.expect("Failed to initialize DB");
|
||||
query_manager
|
||||
.connect()
|
||||
.upsert_workspace(
|
||||
&Workspace { id: "wk_test".to_string(), ..Default::default() },
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
.with_tx(|tx| {
|
||||
tx.upsert_workspace(
|
||||
&Workspace { id: "wk_test".to_string(), ..Default::default() },
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
})
|
||||
.expect("Failed to seed workspace");
|
||||
(query_manager, blob_manager, temp_dir)
|
||||
}
|
||||
@@ -1608,18 +1621,18 @@ mod tests {
|
||||
let (query_manager, mut cookie_jar, _temp_dir) = seed_cookie_jar();
|
||||
cookie_jar.cookies = vec![cookie("original")];
|
||||
cookie_jar = query_manager
|
||||
.connect()
|
||||
.upsert_cookie_jar(&cookie_jar, &UpdateSource::Sync)
|
||||
.with_tx(|tx| tx.upsert_cookie_jar(&cookie_jar, &UpdateSource::Sync))
|
||||
.expect("Failed to seed cookies");
|
||||
let store = CookieStore::from_cookies(cookie_jar.cookies.clone());
|
||||
|
||||
// Someone else updates the jar while the send is in flight.
|
||||
query_manager
|
||||
.connect()
|
||||
.upsert_cookie_jar(
|
||||
&CookieJar { cookies: vec![cookie("newer")], ..cookie_jar.clone() },
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
.with_tx(|tx| {
|
||||
tx.upsert_cookie_jar(
|
||||
&CookieJar { cookies: vec![cookie("newer")], ..cookie_jar.clone() },
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
})
|
||||
.expect("Failed to update cookie jar");
|
||||
|
||||
persist_cookies_after_send(&query_manager, Some(&mut cookie_jar), Some(&store))
|
||||
|
||||
Reference in new issue
Block a user