Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
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-ce
Commits
6764676e
Commit
6764676e
authored
Sep 01, 2021
by
Michael Kozono
Committed by
Jacob Vosmaer
Sep 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Workhorse support for HTTPS backend
parent
e3b3eca8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
5 deletions
+61
-5
workhorse/internal/upstream/roundtripper/roundtripper.go
workhorse/internal/upstream/roundtripper/roundtripper.go
+6
-4
workhorse/internal/upstream/roundtripper/roundtripper_test.go
...horse/internal/upstream/roundtripper/roundtripper_test.go
+55
-1
No files found.
workhorse/internal/upstream/roundtripper/roundtripper.go
View file @
6764676e
...
...
@@ -2,6 +2,7 @@ package roundtripper
import
(
"context"
"crypto/tls"
"fmt"
"net"
"net/http"
...
...
@@ -15,10 +16,6 @@ import (
)
func
mustParseAddress
(
address
,
scheme
string
)
string
{
if
scheme
==
"https"
{
panic
(
"TLS is not supported for backend connections"
)
}
for
_
,
suffix
:=
range
[]
string
{
""
,
":"
+
scheme
}
{
address
+=
suffix
if
host
,
port
,
err
:=
net
.
SplitHostPort
(
address
);
err
==
nil
&&
host
!=
""
&&
port
!=
""
{
...
...
@@ -31,9 +28,14 @@ func mustParseAddress(address, scheme string) string {
// NewBackendRoundTripper returns a new RoundTripper instance using the provided values
func
NewBackendRoundTripper
(
backend
*
url
.
URL
,
socket
string
,
proxyHeadersTimeout
time
.
Duration
,
developmentMode
bool
)
http
.
RoundTripper
{
return
newBackendRoundTripper
(
backend
,
socket
,
proxyHeadersTimeout
,
developmentMode
,
nil
)
}
func
newBackendRoundTripper
(
backend
*
url
.
URL
,
socket
string
,
proxyHeadersTimeout
time
.
Duration
,
developmentMode
bool
,
tlsConf
*
tls
.
Config
)
http
.
RoundTripper
{
// Copied from the definition of http.DefaultTransport. We can't literally copy http.DefaultTransport because of its hidden internal state.
transport
,
dialer
:=
newBackendTransport
()
transport
.
ResponseHeaderTimeout
=
proxyHeadersTimeout
transport
.
TLSClientConfig
=
tlsConf
if
backend
!=
nil
&&
socket
==
""
{
address
:=
mustParseAddress
(
backend
.
Host
,
backend
.
Scheme
)
...
...
workhorse/internal/upstream/roundtripper/roundtripper_test.go
View file @
6764676e
package
roundtripper
import
(
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"strconv"
"testing"
...
...
@@ -12,6 +19,7 @@ func TestMustParseAddress(t *testing.T) {
{
"1.2.3.4:56"
,
"http"
,
"1.2.3.4:56"
},
{
"[::1]:23"
,
"http"
,
"::1:23"
},
{
"4.5.6.7"
,
"http"
,
"4.5.6.7:http"
},
{
"4.5.6.7"
,
"https"
,
"4.5.6.7:https"
},
}
for
i
,
example
:=
range
successExamples
{
t
.
Run
(
strconv
.
Itoa
(
i
),
func
(
t
*
testing
.
T
)
{
...
...
@@ -23,7 +31,6 @@ func TestMustParseAddress(t *testing.T) {
func
TestMustParseAddressPanic
(
t
*
testing
.
T
)
{
panicExamples
:=
[]
struct
{
address
,
scheme
string
}{
{
"1.2.3.4"
,
""
},
{
"1.2.3.4"
,
"https"
},
}
for
i
,
panicExample
:=
range
panicExamples
{
...
...
@@ -37,3 +44,50 @@ func TestMustParseAddressPanic(t *testing.T) {
})
}
}
func
TestSupportsHTTPBackend
(
t
*
testing
.
T
)
{
ts
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
200
)
fmt
.
Fprint
(
w
,
"successful response"
)
}))
defer
ts
.
Close
()
testNewBackendRoundTripper
(
t
,
ts
,
nil
,
"successful response"
)
}
func
TestSupportsHTTPSBackend
(
t
*
testing
.
T
)
{
ts
:=
httptest
.
NewTLSServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
200
)
fmt
.
Fprint
(
w
,
"successful response"
)
}))
defer
ts
.
Close
()
certpool
:=
x509
.
NewCertPool
()
certpool
.
AddCert
(
ts
.
Certificate
())
tlsClientConfig
:=
&
tls
.
Config
{
RootCAs
:
certpool
,
}
testNewBackendRoundTripper
(
t
,
ts
,
tlsClientConfig
,
"successful response"
)
}
func
testNewBackendRoundTripper
(
t
*
testing
.
T
,
ts
*
httptest
.
Server
,
tlsClientConfig
*
tls
.
Config
,
expectedResponseBody
string
)
{
t
.
Helper
()
backend
,
err
:=
url
.
Parse
(
ts
.
URL
)
require
.
NoError
(
t
,
err
,
"parse url"
)
rt
:=
newBackendRoundTripper
(
backend
,
""
,
0
,
true
,
tlsClientConfig
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
ts
.
URL
+
"/"
,
nil
)
require
.
NoError
(
t
,
err
,
"build request"
)
response
,
err
:=
rt
.
RoundTrip
(
req
)
require
.
NoError
(
t
,
err
,
"perform roundtrip"
)
defer
response
.
Body
.
Close
()
body
,
err
:=
ioutil
.
ReadAll
(
response
.
Body
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
expectedResponseBody
,
string
(
body
))
}
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