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
ad3c668c
Commit
ad3c668c
authored
Nov 26, 2015
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X blob serving very draftly works
parent
fa260e77
Pipeline
#109
failed with stage
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
11 deletions
+33
-11
authorization.go
authorization.go
+9
-1
blob.go
blob.go
+24
-10
No files found.
authorization.go
View file @
ad3c668c
...
@@ -9,11 +9,13 @@ import (
...
@@ -9,11 +9,13 @@ import (
"net/http"
"net/http"
"strings"
"strings"
"log"
"log"
"time"
)
)
func
preAuthorizeHandler
(
handleFunc
serviceHandleFunc
,
suffix
string
)
serviceHandleFunc
{
func
preAuthorizeHandler
(
handleFunc
serviceHandleFunc
,
suffix
string
)
serviceHandleFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
return
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
log
.
Printf
(
"AUTH1"
)
Tstart
:=
time
.
Now
()
//log.Printf("AUTH1")
authReq
,
err
:=
r
.
u
.
newUpstreamRequest
(
r
.
Request
,
nil
,
suffix
)
authReq
,
err
:=
r
.
u
.
newUpstreamRequest
(
r
.
Request
,
nil
,
suffix
)
if
err
!=
nil
{
if
err
!=
nil
{
fail500
(
w
,
"newUpstreamRequest"
,
err
)
fail500
(
w
,
"newUpstreamRequest"
,
err
)
...
@@ -67,7 +69,13 @@ func preAuthorizeHandler(handleFunc serviceHandleFunc, suffix string) serviceHan
...
@@ -67,7 +69,13 @@ func preAuthorizeHandler(handleFunc serviceHandleFunc, suffix string) serviceHan
}
}
}
}
Tendauth
:=
time
.
Now
()
handleFunc
(
w
,
r
)
handleFunc
(
w
,
r
)
Tend
:=
time
.
Now
()
log
.
Printf
(
"Tauth:
\t
%s"
,
Tendauth
.
Sub
(
Tstart
))
log
.
Printf
(
"Tauth+handle:
\t
%s"
,
Tend
.
Sub
(
Tstart
))
}
}
}
}
...
...
blob.go
View file @
ad3c668c
...
@@ -6,7 +6,9 @@ package main
...
@@ -6,7 +6,9 @@ package main
import
(
import
(
"io"
"io"
// "os"
"log"
"log"
"time"
"strings"
"strings"
"regexp"
"regexp"
"net/http"
"net/http"
...
@@ -30,8 +32,10 @@ func blobPreAuthorizeHandler(handleFunc serviceHandleFunc) serviceHandleFunc {
...
@@ -30,8 +32,10 @@ func blobPreAuthorizeHandler(handleFunc serviceHandleFunc) serviceHandleFunc {
}
}
func
handleGetBlobRaw
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
func
handleGetBlobRaw
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
log
.
Printf
(
"BLOB1"
)
Tstart
:=
time
.
Now
()
// extract project name
// extract project & refpath
// /namespace/project/raw/branch/file -> /namespace/project, branch/file
projectRe
:=
regexp
.
MustCompile
(
`^/[\w\.-]+/[\w\.-]+/`
)
projectRe
:=
regexp
.
MustCompile
(
`^/[\w\.-]+/[\w\.-]+/`
)
project
:=
projectRe
.
FindString
(
r
.
Request
.
URL
.
Path
)
project
:=
projectRe
.
FindString
(
r
.
Request
.
URL
.
Path
)
refpath
:=
r
.
Request
.
URL
.
Path
[
len
(
project
)
:
]
refpath
:=
r
.
Request
.
URL
.
Path
[
len
(
project
)
:
]
...
@@ -39,21 +43,19 @@ func handleGetBlobRaw(w http.ResponseWriter, r *gitRequest) {
...
@@ -39,21 +43,19 @@ func handleGetBlobRaw(w http.ResponseWriter, r *gitRequest) {
fail500
(
w
,
"extract project name"
,
nil
)
fail500
(
w
,
"extract project name"
,
nil
)
return
return
}
}
//assert project[-1] == "/"
//assert project[-1] == "/"
project
=
project
[
:
len
(
project
)
-
1
]
project
=
project
[
:
len
(
project
)
-
1
]
log
.
Printf
(
"project: %v"
,
project
)
if
refpath
[
:
4
]
!=
"raw/"
{
if
refpath
[
:
4
]
!=
"raw/"
{
fail500
(
w
,
"refpath != raw/..."
,
nil
)
fail500
(
w
,
"refpath != raw/..."
,
nil
)
return
return
}
}
refpath
=
refpath
[
4
:
]
refpath
=
refpath
[
4
:
]
log
.
Printf
(
"refpath: %v"
,
refpath
)
//log.Printf("BLOB1 %v %v", project
, refpath)
// request to verify whether download is possible via asking as git fetch would do
// request to verify whether download is possible via asking as git fetch would do
// XXX privateToken not propagated ...
// XXX privateToken not propagated
, etc
...
req
CheckDownload
,
err
:=
http
.
NewRequest
(
"GET"
,
project
+
".git/info/refs?service=git-upload-pack"
,
nil
)
req
DownloadAccess
,
err
:=
http
.
NewRequest
(
"GET"
,
project
+
".git/info/refs?service=git-upload-pack"
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
fail500
(
w
,
"GET git-upload-pack"
,
err
)
fail500
(
w
,
"GET git-upload-pack"
,
err
)
return
return
...
@@ -61,27 +63,32 @@ func handleGetBlobRaw(w http.ResponseWriter, r *gitRequest) {
...
@@ -61,27 +63,32 @@ func handleGetBlobRaw(w http.ResponseWriter, r *gitRequest) {
// swap original request to 'verify-download' one
// swap original request to 'verify-download' one
//requestBlob := r.Request
//requestBlob := r.Request
r
.
Request
=
req
CheckDownload
r
.
Request
=
req
DownloadAccess
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
handleGetBlobRaw2
(
w
,
r
,
refpath
)
handleGetBlobRaw2
(
w
,
r
,
refpath
)
},
""
)
(
w
,
r
)
},
""
)
(
w
,
r
)
Tend
:=
time
.
Now
()
log
.
Printf
(
"Tall: %s"
,
Tend
.
Sub
(
Tstart
))
}
}
func
handleGetBlobRaw2
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
refpath
string
)
{
func
handleGetBlobRaw2
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
refpath
string
)
{
Tstart
:=
time
.
Now
()
// XXX we assume <ref>/<path> format and ref not containing "/"
// XXX we assume <ref>/<path> format and ref not containing "/"
// XXX but gitlab allows ref with / and tries to do longest-match to existing refs
// XXX but gitlab allows ref with / and tries to do longest-match to existing refs
// TODO use reqDownloadAccess respose body - it contain all refs
s
:=
strings
.
SplitN
(
refpath
,
"/"
,
2
)
s
:=
strings
.
SplitN
(
refpath
,
"/"
,
2
)
log
.
Printf
(
"RAW2 s: %v"
,
s
)
if
len
(
s
)
!=
2
{
if
len
(
s
)
!=
2
{
fail500
(
w
,
"refpath split"
,
nil
)
fail500
(
w
,
"refpath split"
,
nil
)
return
return
}
}
ref
,
path
:=
s
[
0
],
s
[
1
]
ref
,
path
:=
s
[
0
],
s
[
1
]
//log.Printf("BLOB2 %v %v", ref, path)
blobCmd
:=
gitCommand
(
""
/*XXX GL_ID*/
,
"git"
,
"--git-dir="
+
r
.
RepoPath
,
"cat-file"
,
"blob"
,
ref
+
":"
+
path
)
blobCmd
:=
gitCommand
(
""
/*XXX GL_ID*/
,
"git"
,
"--git-dir="
+
r
.
RepoPath
,
"cat-file"
,
"blob"
,
"--"
,
ref
+
":"
+
path
)
blobStdout
,
err
:=
blobCmd
.
StdoutPipe
()
blobStdout
,
err
:=
blobCmd
.
StdoutPipe
()
if
err
!=
nil
{
if
err
!=
nil
{
fail500
(
w
,
"handleGetBlobRaw"
,
err
)
fail500
(
w
,
"handleGetBlobRaw"
,
err
)
...
@@ -97,6 +104,10 @@ func handleGetBlobRaw2(w http.ResponseWriter, r *gitRequest, refpath string) {
...
@@ -97,6 +104,10 @@ func handleGetBlobRaw2(w http.ResponseWriter, r *gitRequest, refpath string) {
//setRawHeaders(...)
//setRawHeaders(...)
w
.
WriteHeader
(
200
)
// XXX too early
w
.
WriteHeader
(
200
)
// XXX too early
//_, err = io.Copy(os.Stdout, blobStdout)
if
err
!=
nil
{
panic
(
err
)
}
if
_
,
err
:=
io
.
Copy
(
w
,
blobStdout
);
err
!=
nil
{
if
_
,
err
:=
io
.
Copy
(
w
,
blobStdout
);
err
!=
nil
{
logContext
(
"io.Copy"
,
err
)
logContext
(
"io.Copy"
,
err
)
return
return
...
@@ -105,4 +116,7 @@ func handleGetBlobRaw2(w http.ResponseWriter, r *gitRequest, refpath string) {
...
@@ -105,4 +116,7 @@ func handleGetBlobRaw2(w http.ResponseWriter, r *gitRequest, refpath string) {
logContext
(
"wait"
,
err
)
logContext
(
"wait"
,
err
)
return
return
}
}
Tend
:=
time
.
Now
()
log
.
Printf
(
"Tblob2: %s"
,
Tend
.
Sub
(
Tstart
))
}
}
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