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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-workhorse
Commits
b35b91e1
Commit
b35b91e1
authored
Jul 26, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More changes
parent
b45d281f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
19 deletions
+16
-19
main.go
main.go
+16
-19
No files found.
main.go
View file @
b35b91e1
package
main
import
(
"bytes"
"compress/gzip"
"flag"
"fmt"
...
...
@@ -41,24 +40,24 @@ func main() {
}
func
git_handler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
var
user
string
log
.
Print
(
r
.
Method
,
" "
,
r
.
URL
)
for
_
,
g
:=
range
git_handlers
{
m
:=
g
.
regexp
.
FindStringSubmatch
(
r
.
URL
.
Path
)
if
r
.
Method
==
g
.
method
&&
m
!=
nil
{
response
:=
validation_request
(
r
)
if
response
.
StatusCode
!=
200
{
w
.
Header
()
.
Set
(
"WWW-Authenticate"
,
response
.
Header
.
Get
(
"WWW-Authenticate"
))
w
.
WriteHeader
(
response
.
StatusCode
)
path_match
:=
g
.
regexp
.
FindStringSubmatch
(
r
.
URL
.
Path
)
if
r
.
Method
==
g
.
method
&&
path_match
!=
nil
{
auth_response
:=
do_auth_request
(
r
)
if
auth_response
.
StatusCode
!=
200
{
for
k
,
v
:=
range
auth_response
.
Header
{
w
.
Header
()[
k
]
=
v
}
w
.
WriteHeader
(
auth_response
.
StatusCode
)
io
.
Copy
(
w
,
auth_response
.
Body
)
return
}
buf
:=
new
(
bytes
.
Buffer
)
_
,
err
:=
buf
.
ReadFrom
(
response
.
Body
)
if
err
!=
nil
{
if
_
,
err
:=
fmt
.
Fscan
(
auth_response
.
Body
,
user
);
err
!=
nil
{
fail_500
(
w
,
err
)
return
}
user
:=
buf
.
String
()
g
.
handle_func
(
user
,
g
.
rpc
,
path
.
Join
(
repo_root
,
m
[
1
]),
w
,
r
)
g
.
handle_func
(
user
,
g
.
rpc
,
path
.
Join
(
repo_root
,
path_match
[
1
]),
w
,
r
)
return
}
}
...
...
@@ -66,21 +65,19 @@ func git_handler(w http.ResponseWriter, r *http.Request) {
w
.
WriteHeader
(
404
)
}
func
validation
_request
(
r
*
http
.
Request
)
*
http
.
Response
{
func
do_auth
_request
(
r
*
http
.
Request
)
*
http
.
Response
{
var
err
error
result
:=
&
http
.
Response
{}
url
:=
fmt
.
Sprintf
(
"http://localhost:8080%s"
,
r
.
URL
.
RequestURI
())
v
req
,
err
:=
http
.
NewRequest
(
r
.
Method
,
url
,
nil
)
auth_
req
,
err
:=
http
.
NewRequest
(
r
.
Method
,
url
,
nil
)
if
err
!=
nil
{
result
.
StatusCode
=
500
return
result
}
for
k
,
v
:=
range
r
.
Header
{
v
req
.
Header
[
k
]
=
v
auth_
req
.
Header
[
k
]
=
v
}
user
,
password
,
_
:=
r
.
BasicAuth
()
vreq
.
SetBasicAuth
(
user
,
password
)
result
,
err
=
http_client
.
Do
(
vreq
)
result
,
err
=
http_client
.
Do
(
auth_req
)
if
err
!=
nil
{
result
.
StatusCode
=
500
return
result
...
...
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