Skip to content

Commit 86d5ede

Browse files
Add redirect to support git lfs (#656)
Git lfs requests are just redirected to the upstream host.
1 parent 5649df3 commit 86d5ede

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

josh-proxy/src/bin/josh-proxy.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,17 +438,24 @@ async fn call_service(
438438
}
439439
};
440440

441-
let mut headref = parsed_url.headref.trim_start_matches('@').to_owned();
442-
if headref.is_empty() {
443-
headref = "HEAD".to_string();
444-
}
445-
446441
let remote_url = [
447442
serv.upstream_url.as_str(),
448443
parsed_url.upstream_repo.as_str(),
449444
]
450445
.join("");
451446

447+
if parsed_url.pathinfo.starts_with("/info/lfs") {
448+
return Ok(Response::builder()
449+
.status(307)
450+
.header("Location", format!("{}{}", remote_url, parsed_url.pathinfo))
451+
.body(hyper::Body::empty())?);
452+
}
453+
454+
let mut headref = parsed_url.headref.trim_start_matches('@').to_owned();
455+
if headref.is_empty() {
456+
headref = "HEAD".to_string();
457+
}
458+
452459
if !josh_proxy::auth::check_auth(&remote_url, &auth, ARGS.is_present("require-auth"))
453460
.in_current_span()
454461
.await?

tests/proxy/lfs_redirect.t

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
$ . ${TESTDIR}/setup_test_env.sh
2+
$ cd ${TESTTMP}
3+
4+
$ git clone -q http://localhost:8001/real_repo.git
5+
warning: You appear to have cloned an empty repository.
6+
7+
$ cd real_repo
8+
9+
$ git status
10+
On branch master
11+
12+
No commits yet
13+
14+
nothing to commit (create/copy files and use "git add" to track)
15+
16+
$ curl -is http://localhost:8002/real_repo.git/info/lfs/objects/batch | grep -v "date:"
17+
HTTP/1.1 307 Temporary Redirect\r (esc)
18+
location: http://localhost:8001/real_repo.git/info/lfs/objects/batch\r (esc)
19+
content-length: 0\r (esc)
20+
\r (esc)
21+
22+
$ curl -is http://localhost:8002/real_repo.git/info/lfs | grep -v "date:"
23+
HTTP/1.1 307 Temporary Redirect\r (esc)
24+
location: http://localhost:8001/real_repo.git/info/lfs\r (esc)
25+
content-length: 0\r (esc)
26+
\r (esc)
27+
28+
$ curl -is http://localhost:8002/real_repo.git@refs/heads/master:/sub1.git/info/lfs | grep -v "date:"
29+
HTTP/1.1 307 Temporary Redirect\r (esc)
30+
location: http://localhost:8001/real_repo.git/info/lfs\r (esc)
31+
content-length: 0\r (esc)
32+
\r (esc)

0 commit comments

Comments
 (0)