Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
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-workhorse
Commits
ec168f4b
Commit
ec168f4b
authored
Feb 02, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use interfaces
parent
3ec457b4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
38 deletions
+56
-38
internal/git/archive.go
internal/git/archive.go
+6
-3
internal/git/blob.go
internal/git/blob.go
+6
-17
internal/inject/sendfile.go
internal/inject/sendfile.go
+10
-16
internal/proxy/proxy.go
internal/proxy/proxy.go
+2
-2
internal/senddata/handler.go
internal/senddata/handler.go
+32
-0
No files found.
internal/git/archive.go
View file @
ec168f4b
...
@@ -6,6 +6,7 @@ package git
...
@@ -6,6 +6,7 @@ package git
import
(
import
(
"../helper"
"../helper"
"../senddata"
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"io/ioutil"
...
@@ -19,16 +20,18 @@ import (
...
@@ -19,16 +20,18 @@ import (
"time"
"time"
)
)
const
SendArchivePrefix
=
"git-archive:"
type
archive
struct
{
senddata
.
Prefix
}
func
SendArchive
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
sendData
string
)
{
var
SendArchive
=
&
archive
{
"git-archive:"
}
func
(
a
*
archive
)
Handle
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
sendData
string
)
{
var
params
struct
{
var
params
struct
{
RepoPath
string
RepoPath
string
ArchivePath
string
ArchivePath
string
ArchivePrefix
string
ArchivePrefix
string
CommitId
string
CommitId
string
}
}
if
err
:=
unpackSendData
(
&
params
,
sendData
,
SendArchivePrefix
);
err
!=
nil
{
if
err
:=
a
.
Unpack
(
&
params
,
sendData
);
err
!=
nil
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendArchive: unpack sendData: %v"
,
err
))
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendArchive: unpack sendData: %v"
,
err
))
return
return
}
}
...
...
internal/git/blob.go
View file @
ec168f4b
...
@@ -2,20 +2,20 @@ package git
...
@@ -2,20 +2,20 @@ package git
import
(
import
(
"../helper"
"../helper"
"encoding/base64"
"../senddata"
"encoding/json"
"fmt"
"fmt"
"io"
"io"
"log"
"log"
"net/http"
"net/http"
"strings"
)
)
const
SendBlobPrefix
=
"git-blob:"
type
blob
struct
{
senddata
.
Prefix
}
func
SendBlob
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
sendData
string
)
{
var
SendBlob
=
&
blob
{
"git-blob:"
}
func
(
b
*
blob
)
Handle
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
sendData
string
)
{
var
params
struct
{
RepoPath
,
BlobId
string
}
var
params
struct
{
RepoPath
,
BlobId
string
}
if
err
:=
unpackSendData
(
&
params
,
sendData
,
SendBlobPrefix
);
err
!=
nil
{
if
err
:=
b
.
Unpack
(
&
params
,
sendData
);
err
!=
nil
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendBlob: unpack sendData: %v"
,
err
))
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendBlob: unpack sendData: %v"
,
err
))
return
return
}
}
...
@@ -43,14 +43,3 @@ func SendBlob(w http.ResponseWriter, r *http.Request, sendData string) {
...
@@ -43,14 +43,3 @@ func SendBlob(w http.ResponseWriter, r *http.Request, sendData string) {
return
return
}
}
}
}
func
unpackSendData
(
result
interface
{},
sendData
string
,
prefix
string
)
error
{
jsonBytes
,
err
:=
base64
.
URLEncoding
.
DecodeString
(
strings
.
TrimPrefix
(
sendData
,
prefix
))
if
err
!=
nil
{
return
err
}
if
err
:=
json
.
Unmarshal
([]
byte
(
jsonBytes
),
result
);
err
!=
nil
{
return
err
}
return
nil
}
internal/
senddata
/sendfile.go
→
internal/
inject
/sendfile.go
View file @
ec168f4b
...
@@ -4,20 +4,17 @@ via the X-Sendfile mechanism. All that is needed in the Rails code is the
...
@@ -4,20 +4,17 @@ via the X-Sendfile mechanism. All that is needed in the Rails code is the
'send_file' method.
'send_file' method.
*/
*/
package
senddata
package
inject
import
(
import
(
"../git"
"../git"
"../helper"
"../helper"
"../senddata"
"log"
"log"
"net/http"
"net/http"
"strings"
)
)
const
(
const
sendFileResponseHeader
=
"X-Sendfile"
sendDataResponseHeader
=
"Gitlab-Workhorse-Send-Data"
sendFileResponseHeader
=
"X-Sendfile"
)
type
sendFileResponseWriter
struct
{
type
sendFileResponseWriter
struct
{
rw
http
.
ResponseWriter
rw
http
.
ResponseWriter
...
@@ -71,18 +68,15 @@ func (s *sendFileResponseWriter) WriteHeader(status int) {
...
@@ -71,18 +68,15 @@ func (s *sendFileResponseWriter) WriteHeader(status int) {
return
return
}
}
sendData
:=
s
.
Header
()
.
Get
(
sendDataResponseHeader
)
header
:=
s
.
Header
()
.
Get
(
senddata
.
Header
)
s
.
Header
()
.
Del
(
sendDataResponseHeader
)
s
.
Header
()
.
Del
(
senddata
.
Header
)
for
_
,
handler
:=
range
[]
struct
{
for
_
,
handler
:=
range
[]
senddata
.
Handler
{
prefix
string
git
.
SendBlob
,
f
func
(
http
.
ResponseWriter
,
*
http
.
Request
,
string
)
git
.
SendArchive
,
}{
{
git
.
SendBlobPrefix
,
git
.
SendBlob
},
{
git
.
SendArchivePrefix
,
git
.
SendArchive
},
}
{
}
{
if
strings
.
HasPrefix
(
sendData
,
handler
.
prefix
)
{
if
handler
.
Match
(
header
)
{
s
.
hijacked
=
true
s
.
hijacked
=
true
handler
.
f
(
s
.
rw
,
s
.
req
,
sendData
)
handler
.
Handle
(
s
.
rw
,
s
.
req
,
header
)
return
return
}
}
}
}
...
...
internal/proxy/proxy.go
View file @
ec168f4b
...
@@ -3,7 +3,7 @@ package proxy
...
@@ -3,7 +3,7 @@ package proxy
import
(
import
(
"../badgateway"
"../badgateway"
"../helper"
"../helper"
"../
senddata
"
"../
inject
"
"net/http"
"net/http"
"net/http/httputil"
"net/http/httputil"
"net/url"
"net/url"
...
@@ -34,7 +34,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
...
@@ -34,7 +34,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Set Workhorse version
// Set Workhorse version
req
.
Header
.
Set
(
"Gitlab-Workhorse"
,
p
.
Version
)
req
.
Header
.
Set
(
"Gitlab-Workhorse"
,
p
.
Version
)
rw
:=
senddata
.
NewSendFileResponseWriter
(
w
,
&
req
)
rw
:=
inject
.
NewSendFileResponseWriter
(
w
,
&
req
)
defer
rw
.
Flush
()
defer
rw
.
Flush
()
p
.
reverseProxy
.
ServeHTTP
(
&
rw
,
&
req
)
p
.
reverseProxy
.
ServeHTTP
(
&
rw
,
&
req
)
...
...
internal/senddata/handler.go
0 → 100644
View file @
ec168f4b
package
senddata
import
(
"encoding/base64"
"encoding/json"
"net/http"
"strings"
)
type
Handler
interface
{
Match
(
string
)
bool
Handle
(
http
.
ResponseWriter
,
*
http
.
Request
,
string
)
}
type
Prefix
string
const
Header
=
"Gitlab-Workhorse-Send-Data"
func
(
p
Prefix
)
Match
(
s
string
)
bool
{
return
strings
.
HasPrefix
(
s
,
string
(
p
))
}
func
(
p
Prefix
)
Unpack
(
result
interface
{},
sendData
string
)
error
{
jsonBytes
,
err
:=
base64
.
URLEncoding
.
DecodeString
(
strings
.
TrimPrefix
(
sendData
,
string
(
p
)))
if
err
!=
nil
{
return
err
}
if
err
:=
json
.
Unmarshal
([]
byte
(
jsonBytes
),
result
);
err
!=
nil
{
return
err
}
return
nil
}
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