Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions apps/global-proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use chrono::Utc;
use serde_json::{Value, json};

type HttpClient = Client<hyper_rustls::HttpsConnector<HttpConnector>, Body>;
type ProxyResponseError = Box<Response<Body>>;

const VERSION: &str = env!("CARGO_PKG_VERSION");
const GIT_COMMIT: &str = match option_env!("GIT_COMMIT") {
Expand Down Expand Up @@ -626,7 +627,7 @@ async fn handle_websocket(
let (backend_stream, backend_headers) =
match connect_upstream_websocket(state.client.clone(), backend_request).await {
Ok(result) => result,
Err(response) => return response,
Err(response) => return *response,
};

let client_upgrade = hyper::upgrade::on(req);
Expand Down Expand Up @@ -762,35 +763,37 @@ fn check_upgrade_request(req: &Request<Body>) -> UpgradeCheck {
async fn connect_upstream_websocket(
client: HttpClient,
request: Request<Body>,
) -> Result<(Upgraded, HeaderMap), Response<Body>> {
) -> Result<(Upgraded, HeaderMap), ProxyResponseError> {
let response = client.request(request).await.map_err(|err| {
error!(%err, "upstream websocket request error");
text_response(
Box::new(text_response(
StatusCode::BAD_GATEWAY,
"Failed to connect to websocket backend",
)
))
})?;

if response.status() != StatusCode::SWITCHING_PROTOCOLS {
let status = response.status();
let body_bytes = body::to_bytes(response.into_body())
.await
.unwrap_or_else(|_| Bytes::new());
return Err(Response::builder()
.status(status)
.body(Body::from(body_bytes))
.unwrap());
return Err(Box::new(
Response::builder()
.status(status)
.body(Body::from(body_bytes))
.unwrap(),
));
}

let headers = response.headers().clone();
match hyper::upgrade::on(response).await {
Ok(upgraded) => Ok((upgraded, headers)),
Err(err) => {
error!(%err, "upstream websocket upgrade failed");
Err(text_response(
Err(Box::new(text_response(
StatusCode::BAD_GATEWAY,
"Failed to upgrade websocket backend",
))
)))
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions apps/global-proxy/tests/proxy_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ impl TestWsBackend {
}
}

// Tungstenite fixes the callback error type to its large HTTP response.
#[expect(
clippy::result_large_err,
reason = "the dependency fixes this callback error type"
)]
async fn spawn_with_handshake(protocol: Option<&str>, extensions: Option<&str>) -> Self {
let listener = tokio::net::TcpListener::bind(SocketAddr::from((Ipv4Addr::LOCALHOST, 0)))
.await
Expand Down Expand Up @@ -325,6 +330,11 @@ impl TestWsBackend {
}
}

// Tungstenite fixes the callback error type to its large HTTP response.
#[expect(
clippy::result_large_err,
reason = "the dependency fixes this callback error type"
)]
async fn spawn_capture_workspace_header()
-> (Self, tokio::sync::oneshot::Receiver<Option<String>>) {
let listener = tokio::net::TcpListener::bind(SocketAddr::from((Ipv4Addr::LOCALHOST, 0)))
Expand Down
60 changes: 30 additions & 30 deletions apps/server/native/core/src/diff/refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,38 +761,38 @@ pub fn diff_refs(opts: GitDiffOptions) -> Result<Vec<DiffEntry>> {
}
}
"R" | "R100" | "R099" | "R098" | "R097" | "R096" | "R095" | "R094" | "R093"
| "R092" | "R091" | "R090" => {
if parts.len() >= 3 {
let oldp = parts[1].to_string();
let newp = parts[2].to_string();
let mut e = DiffEntry {
filePath: newp.clone(),
oldPath: Some(oldp.clone()),
status: "renamed".into(),
additions: 0,
deletions: 0,
isBinary: false,
..Default::default()
};
if include {
let new_s = crate::util::run_git(
&cwd,
&["show", &format!("{}:{}", head_oid, newp)],
)
.unwrap_or_default();
let new_sz = new_s.len();
e.newSize = Some(new_sz as i32);
e.oldSize = Some(new_sz as i32);
if new_sz <= max_bytes {
e.oldContent = Some(new_s.clone());
e.newContent = Some(new_s);
e.contentOmitted = Some(false);
} else {
e.contentOmitted = Some(true);
}
| "R092" | "R091" | "R090"
if parts.len() >= 3 =>
{
let oldp = parts[1].to_string();
let newp = parts[2].to_string();
let mut e = DiffEntry {
filePath: newp.clone(),
oldPath: Some(oldp.clone()),
status: "renamed".into(),
additions: 0,
deletions: 0,
isBinary: false,
..Default::default()
};
if include {
let new_s = crate::util::run_git(
&cwd,
&["show", &format!("{}:{}", head_oid, newp)],
)
.unwrap_or_default();
let new_sz = new_s.len();
e.newSize = Some(new_sz as i32);
e.oldSize = Some(new_sz as i32);
if new_sz <= max_bytes {
e.oldContent = Some(new_s.clone());
e.newContent = Some(new_s);
e.contentOmitted = Some(false);
} else {
e.contentOmitted = Some(true);
}
fallback.push(e);
}
fallback.push(e);
}
_ => {}
}
Expand Down
6 changes: 3 additions & 3 deletions apps/server/native/core/src/repo/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn update_cache_index(root: &Path, repo_path: &Path) -> Result<()> {
});
}
idx.entries
.sort_by(|a, b| b.last_access_ms.cmp(&a.last_access_ms));
.sort_by_key(|entry| std::cmp::Reverse(entry.last_access_ms));
idx.entries.dedup_by(|a, b| a.slug == b.slug);
save_index(root, &idx)?;
Ok(())
Expand Down Expand Up @@ -186,7 +186,7 @@ fn update_cache_index_with(
});
}
idx.entries
.sort_by(|a, b| b.last_access_ms.cmp(&a.last_access_ms));
.sort_by_key(|entry| std::cmp::Reverse(entry.last_access_ms));
idx.entries.dedup_by(|a, b| a.slug == b.slug);
save_index(root, &idx)?;
Ok(())
Expand Down Expand Up @@ -265,7 +265,7 @@ fn enforce_cache_limit(root: &Path) -> Result<()> {
return Ok(());
}
idx.entries
.sort_by(|a, b| b.last_access_ms.cmp(&a.last_access_ms));
.sort_by_key(|entry| std::cmp::Reverse(entry.last_access_ms));
let survivors = idx.entries[..MAX_CACHE_REPOS].to_vec();
let victims = idx.entries[MAX_CACHE_REPOS..].to_vec();
for v in &victims {
Expand Down
Loading
Loading