feat #14740: admin backend client and transcript upload text
recorder-core side of linking the app to the euvino admin backend: - backend: BackendClient (create a key with the admin's session cookie, check a key, upload a transcript; redirects never followed), German error messages, the login-window decision (LoginStep) and the upload flow with login, one retry after a refused key and no loop - call_view: the upload text (header + merged, renamed lines) and the upload fields on the call - store: schema v3 with crm_transcript_id and uploaded_at - settings: backend_url (validated https), the app-managed login fields, kept on edit and cleared when the backend URL changes - secrets: Service::Backend; http: per-request follow_redirects; FakeTransport can script transport errors Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+31
-12
@@ -50,6 +50,9 @@ pub struct HttpRequest {
|
||||
pub url: String,
|
||||
pub headers: Vec<(String, String)>,
|
||||
pub body: HttpBody,
|
||||
/// `false` returns a redirect (3xx) as the response instead of
|
||||
/// following it.
|
||||
pub follow_redirects: bool,
|
||||
}
|
||||
|
||||
impl HttpRequest {
|
||||
@@ -98,22 +101,30 @@ pub trait HttpTransport: Send + Sync {
|
||||
async fn send(&self, req: HttpRequest) -> Result<HttpResponse, TransportError>;
|
||||
}
|
||||
|
||||
/// Live `HttpTransport` backed by `reqwest` (rustls). Shares one
|
||||
/// `reqwest::Client` (connection pooling) with a 10 minute request timeout
|
||||
/// Live `HttpTransport` backed by `reqwest` (rustls). Shares its
|
||||
/// `reqwest::Client`s (connection pooling) with a 10 minute request timeout
|
||||
/// and a 30 second connect timeout, matching the DeepScript client's
|
||||
/// worst-case wait.
|
||||
/// worst-case wait. reqwest sets the redirect policy per client, so there
|
||||
/// is one that follows redirects and one that does not.
|
||||
pub struct ReqwestTransport {
|
||||
client: reqwest::Client,
|
||||
no_redirect_client: reqwest::Client,
|
||||
}
|
||||
|
||||
impl ReqwestTransport {
|
||||
pub fn new() -> Self {
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(10 * 60))
|
||||
.connect_timeout(Duration::from_secs(30))
|
||||
.build()
|
||||
.expect("failed to build reqwest client");
|
||||
ReqwestTransport { client }
|
||||
let build = |redirects| {
|
||||
reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(10 * 60))
|
||||
.connect_timeout(Duration::from_secs(30))
|
||||
.redirect(redirects)
|
||||
.build()
|
||||
.expect("failed to build reqwest client")
|
||||
};
|
||||
ReqwestTransport {
|
||||
client: build(reqwest::redirect::Policy::default()),
|
||||
no_redirect_client: build(reqwest::redirect::Policy::none()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,10 +137,15 @@ impl Default for ReqwestTransport {
|
||||
#[async_trait]
|
||||
impl HttpTransport for ReqwestTransport {
|
||||
async fn send(&self, req: HttpRequest) -> Result<HttpResponse, TransportError> {
|
||||
let client = if req.follow_redirects {
|
||||
&self.client
|
||||
} else {
|
||||
&self.no_redirect_client
|
||||
};
|
||||
let mut builder = match req.method {
|
||||
Method::Get => self.client.get(&req.url),
|
||||
Method::Post => self.client.post(&req.url),
|
||||
Method::Delete => self.client.delete(&req.url),
|
||||
Method::Get => client.get(&req.url),
|
||||
Method::Post => client.post(&req.url),
|
||||
Method::Delete => client.delete(&req.url),
|
||||
};
|
||||
for (name, value) in &req.headers {
|
||||
builder = builder.header(name, value);
|
||||
@@ -202,6 +218,7 @@ mod tests {
|
||||
url: url.to_string(),
|
||||
headers: vec![],
|
||||
body: HttpBody::Empty,
|
||||
follow_redirects: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,6 +241,7 @@ mod tests {
|
||||
url: "https://api.example.com/b?x=1".to_string(),
|
||||
headers: vec![("x-test".to_string(), "1".to_string())],
|
||||
body: HttpBody::Empty,
|
||||
follow_redirects: true,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -264,6 +282,7 @@ mod tests {
|
||||
url: "https://api.example.com".to_string(),
|
||||
headers: vec![("Authorization".to_string(), "Bearer xyz".to_string())],
|
||||
body: HttpBody::Empty,
|
||||
follow_redirects: true,
|
||||
};
|
||||
assert_eq!(req.header("authorization"), Some("Bearer xyz"));
|
||||
assert_eq!(req.header("missing"), None);
|
||||
|
||||
Reference in New Issue
Block a user