Commit 1500542c authored by Jacob Vosmaer's avatar Jacob Vosmaer
parents 162424b9 74efa43f
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"io" "io"
"log" "log"
"net/http" "net/http"
"strings"
) )
type blob struct{ senddata.Prefix } type blob struct{ senddata.Prefix }
...@@ -23,10 +24,16 @@ func (b *blob) Inject(w http.ResponseWriter, r *http.Request, sendData string) { ...@@ -23,10 +24,16 @@ func (b *blob) Inject(w http.ResponseWriter, r *http.Request, sendData string) {
log.Printf("SendBlob: sending %q for %q", params.BlobId, r.URL.Path) log.Printf("SendBlob: sending %q for %q", params.BlobId, r.URL.Path)
sizeOutput, err := gitCommand("", "git", "--git-dir="+params.RepoPath, "cat-file", "-s", params.BlobId).Output()
if err != nil {
helper.Fail500(w, fmt.Errorf("SendBlob: get blob size: %v", err))
return
}
gitShowCmd := gitCommand("", "git", "--git-dir="+params.RepoPath, "cat-file", "blob", params.BlobId) gitShowCmd := gitCommand("", "git", "--git-dir="+params.RepoPath, "cat-file", "blob", params.BlobId)
stdout, err := gitShowCmd.StdoutPipe() stdout, err := gitShowCmd.StdoutPipe()
if err != nil { if err != nil {
helper.Fail500(w, fmt.Errorf("SendBlob: git stdout: %v", err)) helper.Fail500(w, fmt.Errorf("SendBlob: git cat-file stdout: %v", err))
return return
} }
if err := gitShowCmd.Start(); err != nil { if err := gitShowCmd.Start(); err != nil {
...@@ -35,8 +42,7 @@ func (b *blob) Inject(w http.ResponseWriter, r *http.Request, sendData string) { ...@@ -35,8 +42,7 @@ func (b *blob) Inject(w http.ResponseWriter, r *http.Request, sendData string) {
} }
defer helper.CleanUpProcessGroup(gitShowCmd) defer helper.CleanUpProcessGroup(gitShowCmd)
// Ignore incorrect Content-Length that may have been set by Rails w.Header().Set("Content-Length", strings.TrimSpace(string(sizeOutput)))
w.Header().Del("Content-Length")
if _, err := io.Copy(w, stdout); err != nil { if _, err := io.Copy(w, stdout); err != nil {
helper.LogError(fmt.Errorf("SendBlob: copy git cat-file stdout: %v", err)) helper.LogError(fmt.Errorf("SendBlob: copy git cat-file stdout: %v", err))
return return
......
...@@ -590,6 +590,9 @@ func TestGetGitBlob(t *testing.T) { ...@@ -590,6 +590,9 @@ func TestGetGitBlob(t *testing.T) {
if len(body) != blobLength { if len(body) != blobLength {
t.Fatalf("Expected body of %d bytes, got %d", blobLength, len(body)) t.Fatalf("Expected body of %d bytes, got %d", blobLength, len(body))
} }
if cl := resp.Header.Get("Content-Length"); cl != fmt.Sprintf("%d", blobLength) {
t.Fatalf("Expected Content-Length %v, got %q", blobLength, cl)
}
if !strings.HasPrefix(string(body), "The MIT License (MIT)") { if !strings.HasPrefix(string(body), "The MIT License (MIT)") {
t.Fatalf("Expected MIT license, got %q", body) t.Fatalf("Expected MIT license, got %q", body)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment