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
Show 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 (
"net/http"
"strings"
"log"
"time"
)
func
preAuthorizeHandler
(
handleFunc
serviceHandleFunc
,
suffix
string
)
serviceHandleFunc
{
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
)
if
err
!=
nil
{
fail500
(
w
,
"newUpstreamRequest"
,
err
)
...
...
@@ -67,7 +69,13 @@ func preAuthorizeHandler(handleFunc serviceHandleFunc, suffix string) serviceHan
}
}
Tendauth
:=
time
.
Now
()
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
import
(
"io"
// "os"
"log"
"time"
"strings"
"regexp"
"net/http"
...
...
@@ -30,8 +32,10 @@ func blobPreAuthorizeHandler(handleFunc serviceHandleFunc) serviceHandleFunc {
}
func
handleGetBlobRaw
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
log
.
Printf
(
"BLOB1"
)
// extract project name
Tstart
:=
time
.
Now
()
// extract project & refpath
// /namespace/project/raw/branch/file -> /namespace/project, branch/file
projectRe
:=
regexp
.
MustCompile
(
`^/[\w\.-]+/[\w\.-]+/`
)
project
:=
projectRe
.
FindString
(
r
.
Request
.
URL
.
Path
)
refpath
:=
r
.
Request
.
URL
.
Path
[
len
(
project
)
:
]
...
...
@@ -39,21 +43,19 @@ func handleGetBlobRaw(w http.ResponseWriter, r *gitRequest) {
fail500
(
w
,
"extract project name"
,
nil
)
return
}
//assert project[-1] == "/"
project
=
project
[
:
len
(
project
)
-
1
]
log
.
Printf
(
"project: %v"
,
project
)
if
refpath
[
:
4
]
!=
"raw/"
{
fail500
(
w
,
"refpath != raw/..."
,
nil
)
return
}
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
// XXX privateToken not propagated ...
req
CheckDownload
,
err
:=
http
.
NewRequest
(
"GET"
,
project
+
".git/info/refs?service=git-upload-pack"
,
nil
)
// XXX privateToken not propagated
, etc
...
req
DownloadAccess
,
err
:=
http
.
NewRequest
(
"GET"
,
project
+
".git/info/refs?service=git-upload-pack"
,
nil
)
if
err
!=
nil
{
fail500
(
w
,
"GET git-upload-pack"
,
err
)
return
...
...
@@ -61,27 +63,32 @@ func handleGetBlobRaw(w http.ResponseWriter, r *gitRequest) {
// swap original request to 'verify-download' one
//requestBlob := r.Request
r
.
Request
=
req
CheckDownload
r
.
Request
=
req
DownloadAccess
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
handleGetBlobRaw2
(
w
,
r
,
refpath
)
},
""
)
(
w
,
r
)
Tend
:=
time
.
Now
()
log
.
Printf
(
"Tall: %s"
,
Tend
.
Sub
(
Tstart
))
}
func
handleGetBlobRaw2
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
refpath
string
)
{
Tstart
:=
time
.
Now
()
// 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
// TODO use reqDownloadAccess respose body - it contain all refs
s
:=
strings
.
SplitN
(
refpath
,
"/"
,
2
)
log
.
Printf
(
"RAW2 s: %v"
,
s
)
if
len
(
s
)
!=
2
{
fail500
(
w
,
"refpath split"
,
nil
)
return
}
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
()
if
err
!=
nil
{
fail500
(
w
,
"handleGetBlobRaw"
,
err
)
...
...
@@ -97,6 +104,10 @@ func handleGetBlobRaw2(w http.ResponseWriter, r *gitRequest, refpath string) {
//setRawHeaders(...)
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
{
logContext
(
"io.Copy"
,
err
)
return
...
...
@@ -105,4 +116,7 @@ func handleGetBlobRaw2(w http.ResponseWriter, r *gitRequest, refpath string) {
logContext
(
"wait"
,
err
)
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