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
3b9e6e34
Commit
3b9e6e34
authored
Jul 26, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Comments and formatting
parent
e0a71fd0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
0 deletions
+11
-0
main.go
main.go
+11
-0
No files found.
main.go
View file @
3b9e6e34
...
...
@@ -22,6 +22,8 @@ type gitHandler struct {
}
var
http_client
=
&
http
.
Client
{}
// Command-line options
var
repo_root
string
var
listen_addr
=
flag
.
String
(
"listen_addr"
,
"localhost:8181"
,
"Listen address for HTTP server"
)
var
auth_backend
=
flag
.
String
(
"auth_backend"
,
"http://localhost:8080"
,
"Authentication/authorization backend"
)
...
...
@@ -33,16 +35,20 @@ var git_handlers = [...]gitHandler{
}
func
main
()
{
// Parse the command-line
flag
.
Parse
()
repo_root
=
flag
.
Arg
(
0
)
log
.
Printf
(
"repo_root: %s"
,
repo_root
)
http
.
HandleFunc
(
"/"
,
git_handler
)
log
.
Fatal
(
http
.
ListenAndServe
(
*
listen_addr
,
nil
))
}
func
git_handler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
var
user
string
log
.
Print
(
r
.
Method
,
" "
,
r
.
URL
)
for
_
,
g
:=
range
git_handlers
{
path_match
:=
g
.
regexp
.
FindStringSubmatch
(
r
.
URL
.
Path
)
if
r
.
Method
==
g
.
method
&&
path_match
!=
nil
{
...
...
@@ -52,6 +58,9 @@ func git_handler(w http.ResponseWriter, r *http.Request) {
return
}
if
auth_response
.
StatusCode
!=
200
{
// The Git request is not allowed by the backend. Maybe the client
// needs to send HTTP Basic credentials.
// Forward the response from the auth backend to our client
for
k
,
v
:=
range
auth_response
.
Header
{
w
.
Header
()[
k
]
=
v
}
...
...
@@ -59,6 +68,7 @@ func git_handler(w http.ResponseWriter, r *http.Request) {
io
.
Copy
(
w
,
auth_response
.
Body
)
return
}
// The auth backend told us who the user is according to them
if
_
,
err
:=
fmt
.
Fscan
(
auth_response
.
Body
,
&
user
);
err
!=
nil
{
fail_500
(
w
,
err
)
return
...
...
@@ -121,6 +131,7 @@ func handle_get_info_refs(user string, _ string, path string, w http.ResponseWri
func
handle_post_rpc
(
user
string
,
rpc
string
,
path
string
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
var
body
io
.
Reader
var
err
error
if
r
.
Header
.
Get
(
"Content-Encoding"
)
==
"gzip"
{
body
,
err
=
gzip
.
NewReader
(
r
.
Body
)
if
err
!=
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