Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
825e2afb
Commit
825e2afb
authored
Feb 01, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use only one header to send git blobs
parent
0a5bd0fe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
19 deletions
+48
-19
internal/git/blob.go
internal/git/blob.go
+34
-7
internal/senddata/sendfile.go
internal/senddata/sendfile.go
+14
-12
No files found.
internal/git/blob.go
View file @
825e2afb
...
@@ -2,33 +2,60 @@ package git
...
@@ -2,33 +2,60 @@ package git
import
(
import
(
"../helper"
"../helper"
"encoding/base64"
"encoding/json"
"fmt"
"fmt"
"io"
"io"
"log"
"log"
"net/http"
"net/http"
"strings"
)
)
func
SendGitBlob
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
repoPath
string
,
blobId
string
)
{
type
blobParams
struct
{
log
.
Printf
(
"SendGitBlob: sending %q for %q"
,
blobId
,
r
.
URL
.
Path
)
RepoPath
string
BlobId
string
}
const
SendBlobPrefix
=
"git-blob:"
func
SendBlob
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
sendData
string
)
{
params
,
err
:=
unpackSendData
(
sendData
)
if
err
!=
nil
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendBlob: unpack sendData: %v"
,
err
))
return
}
log
.
Printf
(
"SendBlob: sending %q for %q"
,
params
.
BlobId
,
r
.
URL
.
Path
)
gitShowCmd
:=
gitCommand
(
""
,
"git"
,
"--git-dir="
+
repoPath
,
"show"
,
b
lobId
)
gitShowCmd
:=
gitCommand
(
""
,
"git"
,
"--git-dir="
+
params
.
RepoPath
,
"show"
,
params
.
B
lobId
)
stdout
,
err
:=
gitShowCmd
.
StdoutPipe
()
stdout
,
err
:=
gitShowCmd
.
StdoutPipe
()
if
err
!=
nil
{
if
err
!=
nil
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"Send
Git
Blob: git show stdout: %v"
,
err
))
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendBlob: git show stdout: %v"
,
err
))
return
return
}
}
if
err
:=
gitShowCmd
.
Start
();
err
!=
nil
{
if
err
:=
gitShowCmd
.
Start
();
err
!=
nil
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"Send
Git
Blob: start %v: %v"
,
gitShowCmd
,
err
))
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendBlob: start %v: %v"
,
gitShowCmd
,
err
))
return
return
}
}
defer
helper
.
CleanUpProcessGroup
(
gitShowCmd
)
defer
helper
.
CleanUpProcessGroup
(
gitShowCmd
)
if
_
,
err
:=
io
.
Copy
(
w
,
stdout
);
err
!=
nil
{
if
_
,
err
:=
io
.
Copy
(
w
,
stdout
);
err
!=
nil
{
helper
.
LogError
(
fmt
.
Errorf
(
"Send
Git
Blob: copy git show stdout: %v"
,
err
))
helper
.
LogError
(
fmt
.
Errorf
(
"SendBlob: copy git show stdout: %v"
,
err
))
return
return
}
}
if
err
:=
gitShowCmd
.
Wait
();
err
!=
nil
{
if
err
:=
gitShowCmd
.
Wait
();
err
!=
nil
{
helper
.
LogError
(
fmt
.
Errorf
(
"Send
Git
Blob: wait for git show: %v"
,
err
))
helper
.
LogError
(
fmt
.
Errorf
(
"SendBlob: wait for git show: %v"
,
err
))
return
return
}
}
}
}
func
unpackSendData
(
sendData
string
)
(
*
blobParams
,
error
)
{
jsonBytes
,
err
:=
base64
.
URLEncoding
.
DecodeString
(
strings
.
TrimPrefix
(
sendData
,
SendBlobPrefix
))
if
err
!=
nil
{
return
nil
,
err
}
result
:=
&
blobParams
{}
if
err
:=
json
.
Unmarshal
([]
byte
(
jsonBytes
),
result
);
err
!=
nil
{
return
nil
,
err
}
return
result
,
nil
}
internal/senddata/sendfile.go
View file @
825e2afb
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
"../helper"
"../helper"
"log"
"log"
"net/http"
"net/http"
"strings"
)
)
type
sendFileResponseWriter
struct
{
type
sendFileResponseWriter
struct
{
...
@@ -44,6 +45,13 @@ func (s *sendFileResponseWriter) Write(data []byte) (n int, err error) {
...
@@ -44,6 +45,13 @@ func (s *sendFileResponseWriter) Write(data []byte) (n int, err error) {
}
}
func
(
s
*
sendFileResponseWriter
)
WriteHeader
(
status
int
)
{
func
(
s
*
sendFileResponseWriter
)
WriteHeader
(
status
int
)
{
// Never pass these headers to the client
defer
func
()
{
s
.
Header
()
.
Del
(
"X-Sendfile"
)
s
.
Header
()
.
Del
(
"Gitlab-Workhorse-Send-Data"
)
}()
if
s
.
status
!=
0
{
if
s
.
status
!=
0
{
return
return
}
}
...
@@ -55,27 +63,21 @@ func (s *sendFileResponseWriter) WriteHeader(status int) {
...
@@ -55,27 +63,21 @@ func (s *sendFileResponseWriter) WriteHeader(status int) {
}
}
if
file
:=
s
.
Header
()
.
Get
(
"X-Sendfile"
);
file
!=
""
{
if
file
:=
s
.
Header
()
.
Get
(
"X-Sendfile"
);
file
!=
""
{
s
.
Header
()
.
Del
(
"X-Sendfile"
)
// Mark this connection as hijacked
// Mark this connection as hijacked
s
.
hijacked
=
true
s
.
hijacked
=
true
// Serve the file
// Serve the file
sendFileFromDisk
(
s
.
rw
,
s
.
req
,
file
)
sendFileFromDisk
(
s
.
rw
,
s
.
req
,
file
)
return
return
}
else
if
repoPath
:=
s
.
Header
()
.
Get
(
"Gitlab-Workhorse-Repo-Path"
);
repoPath
!=
""
{
}
if
sendData
:=
s
.
Header
()
.
Get
(
"Gitlab-Workhorse-Send-Data"
);
strings
.
HasPrefix
(
sendData
,
"git-blob:"
)
{
s
.
hijacked
=
true
s
.
hijacked
=
true
git
.
SendBlob
(
s
.
rw
,
s
.
req
,
sendData
)
s
.
Header
()
.
Del
(
"Gitlab-Workhorse-Repo-Path"
)
sendBlob
:=
s
.
Header
()
.
Get
(
"Gitlab-Workhorse-Send-Blob"
)
s
.
Header
()
.
Del
(
"Gitlab-Workhorse-Send-Blob"
)
git
.
SendGitBlob
(
s
.
rw
,
s
.
req
,
repoPath
,
sendBlob
)
return
return
}
else
{
}
s
.
rw
.
WriteHeader
(
s
.
status
)
s
.
rw
.
WriteHeader
(
s
.
status
)
return
return
}
}
}
func
sendFileFromDisk
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
file
string
)
{
func
sendFileFromDisk
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
file
string
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment