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
0
Merge Requests
0
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
iv
gitlab-workhorse
Commits
be49aebf
Commit
be49aebf
authored
Nov 05, 2015
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove RPC
parent
359219c1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
17 deletions
+39
-17
archive.go
archive.go
+19
-3
git-http.go
git-http.go
+11
-2
upstream.go
upstream.go
+9
-12
No files found.
archive.go
View file @
be49aebf
...
...
@@ -14,15 +14,31 @@ import (
"os/exec"
"path"
"time"
"path/filepath"
"errors"
)
func
handleGetArchive
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
var
format
string
switch
filepath
.
Base
(
r
.
URL
.
Path
)
{
case
"archive.zip"
:
format
=
"zip"
case
"archive.tar"
:
format
=
"tar"
case
"archive"
,
"archive.tar.gz"
:
format
=
"tar.gz"
case
"archive.tar.bz2"
:
format
=
"tar.bz2"
default
:
fail500
(
w
,
"handleGetArchive"
,
errors
.
New
(
"invalid archive format"
))
}
archiveFilename
:=
path
.
Base
(
r
.
ArchivePath
)
if
cachedArchive
,
err
:=
os
.
Open
(
r
.
ArchivePath
);
err
==
nil
{
defer
cachedArchive
.
Close
()
log
.
Printf
(
"Serving cached file %q"
,
r
.
ArchivePath
)
setArchiveHeaders
(
w
,
r
.
rpc
,
archiveFilename
)
setArchiveHeaders
(
w
,
format
,
archiveFilename
)
// Even if somebody deleted the cachedArchive from disk since we opened
// the file, Unix file semantics guarantee we can still read from the
// open file in this process.
...
...
@@ -41,7 +57,7 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest) {
defer
tempFile
.
Close
()
defer
os
.
Remove
(
tempFile
.
Name
())
compressCmd
,
archiveFormat
:=
parseArchiveFormat
(
r
.
rpc
)
compressCmd
,
archiveFormat
:=
parseArchiveFormat
(
format
)
archiveCmd
:=
gitCommand
(
""
,
"git"
,
"--git-dir="
+
r
.
RepoPath
,
"archive"
,
"--format="
+
archiveFormat
,
"--prefix="
+
r
.
ArchivePrefix
+
"/"
,
r
.
CommitId
)
archiveStdout
,
err
:=
archiveCmd
.
StdoutPipe
()
...
...
@@ -82,7 +98,7 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest) {
archiveReader
:=
io
.
TeeReader
(
stdout
,
tempFile
)
// Start writing the response
setArchiveHeaders
(
w
,
r
.
rpc
,
archiveFilename
)
setArchiveHeaders
(
w
,
format
,
archiveFilename
)
w
.
WriteHeader
(
200
)
// Don't bother with HTTP 500 from this point on, just return
if
_
,
err
:=
io
.
Copy
(
w
,
archiveReader
);
err
!=
nil
{
logContext
(
"handleGetArchive read from subprocess"
,
err
)
...
...
git-http.go
View file @
be49aebf
...
...
@@ -10,6 +10,7 @@ import (
"io"
"net/http"
"strings"
"path/filepath"
)
func
handleGetInfoRefs
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
...
...
@@ -60,6 +61,14 @@ func handlePostRPC(w http.ResponseWriter, r *gitRequest) {
var
body
io
.
ReadCloser
var
err
error
// Get Git action from URL
action
:=
filepath
.
Base
(
r
.
URL
.
Path
)
if
!
(
action
==
"git-upload-pack"
||
action
==
"git-receive-pack"
)
{
// The 'dumb' Git HTTP protocol is not supported
fail500
(
w
,
"handlePostRPC"
,
err
)
return
}
// The client request body may have been gzipped.
if
r
.
Header
.
Get
(
"Content-Encoding"
)
==
"gzip"
{
body
,
err
=
gzip
.
NewReader
(
r
.
Body
)
...
...
@@ -73,7 +82,7 @@ func handlePostRPC(w http.ResponseWriter, r *gitRequest) {
defer
body
.
Close
()
// Prepare our Git subprocess
cmd
:=
gitCommand
(
r
.
GL_ID
,
"git"
,
subCommand
(
r
.
rpc
),
"--stateless-rpc"
,
r
.
RepoPath
)
cmd
:=
gitCommand
(
r
.
GL_ID
,
"git"
,
subCommand
(
action
),
"--stateless-rpc"
,
r
.
RepoPath
)
stdout
,
err
:=
cmd
.
StdoutPipe
()
if
err
!=
nil
{
fail500
(
w
,
"handlePostRPC"
,
err
)
...
...
@@ -108,7 +117,7 @@ func handlePostRPC(w http.ResponseWriter, r *gitRequest) {
body
.
Close
()
// Start writing the response
w
.
Header
()
.
Add
(
"Content-Type"
,
fmt
.
Sprintf
(
"application/x-%s-result"
,
r
.
rpc
))
w
.
Header
()
.
Add
(
"Content-Type"
,
fmt
.
Sprintf
(
"application/x-%s-result"
,
action
))
w
.
Header
()
.
Add
(
"Cache-Control"
,
"no-cache"
)
w
.
WriteHeader
(
200
)
// Don't bother with HTTP 500 from this point on, just return
...
...
upstream.go
View file @
be49aebf
...
...
@@ -26,7 +26,6 @@ type gitService struct {
method
string
regex
*
regexp
.
Regexp
handleFunc
serviceHandleFunc
rpc
string
}
type
authorizationResponse
struct
{
...
...
@@ -53,20 +52,19 @@ type gitRequest struct {
*
http
.
Request
authorizationResponse
u
*
upstream
rpc
string
}
// Routing table
var
gitServices
=
[
...
]
gitService
{
gitService
{
"GET"
,
regexp
.
MustCompile
(
`/info/refs\z`
),
repoPreAuthorizeHandler
(
handleGetInfoRefs
)
,
""
},
gitService
{
"POST"
,
regexp
.
MustCompile
(
`/git-upload-pack\z`
),
repoPreAuthorizeHandler
(
handlePostRPC
)
,
"git-upload-pack"
},
gitService
{
"POST"
,
regexp
.
MustCompile
(
`/git-receive-pack\z`
),
repoPreAuthorizeHandler
(
handlePostRPC
)
,
"git-receive-pack"
},
gitService
{
"GET"
,
regexp
.
MustCompile
(
`/repository/archive\z`
),
repoPreAuthorizeHandler
(
handleGetArchive
)
,
"tar.gz"
},
gitService
{
"GET"
,
regexp
.
MustCompile
(
`/repository/archive.zip\z`
),
repoPreAuthorizeHandler
(
handleGetArchive
)
,
"zip"
},
gitService
{
"GET"
,
regexp
.
MustCompile
(
`/repository/archive.tar\z`
),
repoPreAuthorizeHandler
(
handleGetArchive
)
,
"tar"
},
gitService
{
"GET"
,
regexp
.
MustCompile
(
`/repository/archive.tar.gz\z`
),
repoPreAuthorizeHandler
(
handleGetArchive
)
,
"tar.gz"
},
gitService
{
"GET"
,
regexp
.
MustCompile
(
`/repository/archive.tar.bz2\z`
),
repoPreAuthorizeHandler
(
handleGetArchive
)
,
"tar.bz2"
},
gitService
{
"GET"
,
regexp
.
MustCompile
(
`/uploads/`
),
handleSendFile
,
""
},
gitService
{
"GET"
,
regexp
.
MustCompile
(
`/info/refs\z`
),
repoPreAuthorizeHandler
(
handleGetInfoRefs
)},
gitService
{
"POST"
,
regexp
.
MustCompile
(
`/git-upload-pack\z`
),
repoPreAuthorizeHandler
(
handlePostRPC
)},
gitService
{
"POST"
,
regexp
.
MustCompile
(
`/git-receive-pack\z`
),
repoPreAuthorizeHandler
(
handlePostRPC
)},
gitService
{
"GET"
,
regexp
.
MustCompile
(
`/repository/archive\z`
),
repoPreAuthorizeHandler
(
handleGetArchive
)},
gitService
{
"GET"
,
regexp
.
MustCompile
(
`/repository/archive.zip\z`
),
repoPreAuthorizeHandler
(
handleGetArchive
)},
gitService
{
"GET"
,
regexp
.
MustCompile
(
`/repository/archive.tar\z`
),
repoPreAuthorizeHandler
(
handleGetArchive
)},
gitService
{
"GET"
,
regexp
.
MustCompile
(
`/repository/archive.tar.gz\z`
),
repoPreAuthorizeHandler
(
handleGetArchive
)},
gitService
{
"GET"
,
regexp
.
MustCompile
(
`/repository/archive.tar.bz2\z`
),
repoPreAuthorizeHandler
(
handleGetArchive
)},
gitService
{
"GET"
,
regexp
.
MustCompile
(
`/uploads/`
),
handleSendFile
},
}
func
newUpstream
(
authBackend
string
,
authTransport
http
.
RoundTripper
)
*
upstream
{
...
...
@@ -96,7 +94,6 @@ func (u *upstream) ServeHTTP(w http.ResponseWriter, r *http.Request) {
request
:=
gitRequest
{
Request
:
r
,
u
:
u
,
rpc
:
g
.
rpc
,
}
g
.
handleFunc
(
w
,
&
request
)
...
...
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