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
1
Merge Requests
1
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
nexedi
gitlab-workhorse
Commits
04677a38
Commit
04677a38
authored
Jul 26, 2019
by
John Cai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gzip info refs response
parent
11b160da
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
10 deletions
+34
-10
go.mod
go.mod
+2
-0
go.sum
go.sum
+4
-0
internal/git/info-refs.go
internal/git/info-refs.go
+28
-10
No files found.
go.mod
View file @
04677a38
...
@@ -8,8 +8,10 @@ require (
...
@@ -8,8 +8,10 @@ require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/garyburd/redigo v1.6.0 // indirect
github.com/garyburd/redigo v1.6.0 // indirect
github.com/getsentry/raven-go v0.1.2
github.com/getsentry/raven-go v0.1.2
github.com/golang/gddo v0.0.0-20190419222130-af0f2af80721
github.com/golang/protobuf v1.3.1
github.com/golang/protobuf v1.3.1
github.com/gomodule/redigo v2.0.0+incompatible
github.com/gomodule/redigo v2.0.0+incompatible
github.com/google/go-cmp v0.3.1 // indirect
github.com/gorilla/websocket v1.4.0
github.com/gorilla/websocket v1.4.0
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
...
...
go.sum
View file @
04677a38
...
@@ -34,6 +34,8 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
...
@@ -34,6 +34,8 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=
github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang/gddo v0.0.0-20190419222130-af0f2af80721 h1:KRMr9A3qfbVM7iV/WcLY/rL5LICqwMHLhwRXKu99fXw=
github.com/golang/gddo v0.0.0-20190419222130-af0f2af80721/go.mod h1:xEhNfoBDX1hzLm2Nf80qUvZ2sVwoMZ8d6IE2SrsQfh4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E=
github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E=
...
@@ -43,6 +45,8 @@ github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg
...
@@ -43,6 +45,8 @@ github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
...
...
internal/git/info-refs.go
View file @
04677a38
package
git
package
git
import
(
import
(
"compress/gzip"
"context"
"context"
"fmt"
"fmt"
"io"
"io"
"net/http"
"net/http"
"github.com/golang/gddo/httputil"
"gitlab.com/gitlab-org/labkit/log"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
...
@@ -16,30 +21,31 @@ func GetInfoRefsHandler(a *api.API) http.Handler {
...
@@ -16,30 +21,31 @@ func GetInfoRefsHandler(a *api.API) http.Handler {
}
}
func
handleGetInfoRefs
(
rw
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
api
.
Response
)
{
func
handleGetInfoRefs
(
rw
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
api
.
Response
)
{
w
:=
NewHttpResponseWriter
(
rw
)
responseWriter
:=
NewHttpResponseWriter
(
rw
)
// Log 0 bytes in because we ignore the request body (and there usually is none anyway).
// Log 0 bytes in because we ignore the request body (and there usually is none anyway).
defer
w
.
Log
(
r
,
0
)
defer
responseWriter
.
Log
(
r
,
0
)
rpc
:=
getService
(
r
)
rpc
:=
getService
(
r
)
if
!
(
rpc
==
"git-upload-pack"
||
rpc
==
"git-receive-pack"
)
{
if
!
(
rpc
==
"git-upload-pack"
||
rpc
==
"git-receive-pack"
)
{
// The 'dumb' Git HTTP protocol is not supported
// The 'dumb' Git HTTP protocol is not supported
http
.
Error
(
w
,
"Not Found"
,
404
)
http
.
Error
(
responseWriter
,
"Not Found"
,
404
)
return
return
}
}
w
.
Header
()
.
Set
(
"Content-Type"
,
fmt
.
Sprintf
(
"application/x-%s-advertisement"
,
rpc
))
responseWriter
.
Header
()
.
Set
(
"Content-Type"
,
fmt
.
Sprintf
(
"application/x-%s-advertisement"
,
rpc
))
w
.
Header
()
.
Set
(
"Cache-Control"
,
"no-cache"
)
responseWriter
.
Header
()
.
Set
(
"Cache-Control"
,
"no-cache"
)
gitProtocol
:=
r
.
Header
.
Get
(
"Git-Protocol"
)
gitProtocol
:=
r
.
Header
.
Get
(
"Git-Protocol"
)
err
:=
handleGetInfoRefsWithGitaly
(
r
.
Context
(),
w
,
a
,
rpc
,
gitProtocol
)
offers
:=
[]
string
{
"gzip"
,
"identity"
}
encoding
:=
httputil
.
NegotiateContentEncoding
(
r
,
offers
)
if
err
!=
nil
{
if
err
:=
handleGetInfoRefsWithGitaly
(
r
.
Context
(),
responseWriter
,
a
,
rpc
,
gitProtocol
,
encoding
);
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"handleGetInfoRefs: %v"
,
err
))
helper
.
Fail500
(
responseWriter
,
r
,
fmt
.
Errorf
(
"handleGetInfoRefs: %v"
,
err
))
}
}
}
}
func
handleGetInfoRefsWithGitaly
(
ctx
context
.
Context
,
w
http
.
ResponseWriter
,
a
*
api
.
Response
,
rpc
string
,
gitProtocol
string
)
error
{
func
handleGetInfoRefsWithGitaly
(
ctx
context
.
Context
,
responseWriter
*
HttpResponseWriter
,
a
*
api
.
Response
,
rpc
,
gitProtocol
,
encoding
string
)
error
{
smarthttp
,
err
:=
gitaly
.
NewSmartHTTPClient
(
a
.
GitalyServer
)
smarthttp
,
err
:=
gitaly
.
NewSmartHTTPClient
(
a
.
GitalyServer
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"GetInfoRefsHandler: %v"
,
err
)
return
fmt
.
Errorf
(
"GetInfoRefsHandler: %v"
,
err
)
...
@@ -50,8 +56,20 @@ func handleGetInfoRefsWithGitaly(ctx context.Context, w http.ResponseWriter, a *
...
@@ -50,8 +56,20 @@ func handleGetInfoRefsWithGitaly(ctx context.Context, w http.ResponseWriter, a *
return
fmt
.
Errorf
(
"GetInfoRefsHandler: %v"
,
err
)
return
fmt
.
Errorf
(
"GetInfoRefsHandler: %v"
,
err
)
}
}
var
w
io
.
Writer
if
encoding
==
"gzip"
{
gzWriter
:=
gzip
.
NewWriter
(
responseWriter
)
w
=
gzWriter
defer
gzWriter
.
Close
()
responseWriter
.
Header
()
.
Set
(
"Content-Encoding"
,
"gzip"
)
}
else
{
w
=
responseWriter
}
if
_
,
err
=
io
.
Copy
(
w
,
infoRefsResponseReader
);
err
!=
nil
{
if
_
,
err
=
io
.
Copy
(
w
,
infoRefsResponseReader
);
err
!=
nil
{
return
fmt
.
Errorf
(
"GetInfoRefsHandler: copy Gitaly response: %v"
,
err
)
log
.
WithError
(
err
)
.
Error
(
"GetInfoRefsHandler: error copying gitaly response"
)
}
}
return
nil
return
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