Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
e7365241
Commit
e7365241
authored
Jul 21, 2015
by
Andy Goldstein
Committed by
Steve Milner
Sep 29, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add http proxy support for exec/port-forward
Add http proxy support for exec/port-forward in SpdyRoundTripper
parent
26c51881
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
4 deletions
+67
-4
roundtripper.go
pkg/util/httpstream/spdy/roundtripper.go
+67
-4
No files found.
pkg/util/httpstream/spdy/roundtripper.go
View file @
e7365241
...
@@ -23,6 +23,8 @@ import (
...
@@ -23,6 +23,8 @@ import (
"io/ioutil"
"io/ioutil"
"net"
"net"
"net/http"
"net/http"
"net/http/httputil"
"net/url"
"strings"
"strings"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
...
@@ -53,21 +55,82 @@ type SpdyRoundTripper struct {
...
@@ -53,21 +55,82 @@ type SpdyRoundTripper struct {
Dialer
*
net
.
Dialer
Dialer
*
net
.
Dialer
}
}
// New
Spdy
RoundTripper creates a new SpdyRoundTripper that will use
// NewRoundTripper creates a new SpdyRoundTripper that will use
// the specified tlsConfig.
// the specified tlsConfig.
func
NewRoundTripper
(
tlsConfig
*
tls
.
Config
)
httpstream
.
UpgradeRoundTripper
{
func
NewRoundTripper
(
tlsConfig
*
tls
.
Config
)
httpstream
.
UpgradeRoundTripper
{
return
NewSpdyRoundTripper
(
tlsConfig
)
return
NewSpdyRoundTripper
(
tlsConfig
)
}
}
// NewSpdyRoundTripper creates a new SpdyRoundTripper that will use
// the specified tlsConfig. This function is mostly meant for unit tests.
func
NewSpdyRoundTripper
(
tlsConfig
*
tls
.
Config
)
*
SpdyRoundTripper
{
func
NewSpdyRoundTripper
(
tlsConfig
*
tls
.
Config
)
*
SpdyRoundTripper
{
return
&
SpdyRoundTripper
{
tlsConfig
:
tlsConfig
}
return
&
SpdyRoundTripper
{
tlsConfig
:
tlsConfig
}
}
}
// dial dials the host specified by req, using TLS if appropriate.
// dial dials the host specified by req, using TLS if appropriate, optionally
// using a proxy server if one is configured via environment variables.
func
(
s
*
SpdyRoundTripper
)
dial
(
req
*
http
.
Request
)
(
net
.
Conn
,
error
)
{
func
(
s
*
SpdyRoundTripper
)
dial
(
req
*
http
.
Request
)
(
net
.
Conn
,
error
)
{
dialAddr
:=
netutil
.
CanonicalAddr
(
req
.
URL
)
proxyURL
,
err
:=
http
.
ProxyFromEnvironment
(
req
)
if
err
!=
nil
{
return
nil
,
err
}
if
proxyURL
==
nil
{
return
s
.
dialWithoutProxy
(
req
.
URL
)
}
// proxying logic adapted from http://blog.h6t.eu/post/74098062923/golang-websocket-with-http-proxy-support
proxyReq
:=
http
.
Request
{
Method
:
"CONNECT"
,
URL
:
&
url
.
URL
{},
Host
:
req
.
URL
.
Host
,
}
proxyDialConn
,
err
:=
s
.
dialWithoutProxy
(
proxyURL
)
if
err
!=
nil
{
return
nil
,
err
}
proxyClientConn
:=
httputil
.
NewProxyClientConn
(
proxyDialConn
,
nil
)
_
,
err
=
proxyClientConn
.
Do
(
&
proxyReq
)
if
err
!=
nil
&&
err
!=
httputil
.
ErrPersistEOF
{
return
nil
,
err
}
rwc
,
_
:=
proxyClientConn
.
Hijack
()
if
req
.
URL
.
Scheme
!=
"https"
{
return
rwc
,
nil
}
host
,
_
,
err
:=
net
.
SplitHostPort
(
req
.
URL
.
Host
)
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
s
.
tlsConfig
.
ServerName
)
==
0
{
s
.
tlsConfig
.
ServerName
=
host
}
tlsConn
:=
tls
.
Client
(
rwc
,
s
.
tlsConfig
)
// need to manually call Handshake() so we can call VerifyHostname() below
if
err
:=
tlsConn
.
Handshake
();
err
!=
nil
{
return
nil
,
err
}
if
err
:=
tlsConn
.
VerifyHostname
(
host
);
err
!=
nil
{
return
nil
,
err
}
return
tlsConn
,
nil
}
// dialWithoutProxy dials the host specified by url, using TLS if appropriate.
func
(
s
*
SpdyRoundTripper
)
dialWithoutProxy
(
url
*
url
.
URL
)
(
net
.
Conn
,
error
)
{
dialAddr
:=
netutil
.
CanonicalAddr
(
url
)
if
req
.
URL
.
Scheme
==
"http"
{
if
url
.
Scheme
==
"http"
{
if
s
.
Dialer
==
nil
{
if
s
.
Dialer
==
nil
{
return
net
.
Dial
(
"tcp"
,
dialAddr
)
return
net
.
Dial
(
"tcp"
,
dialAddr
)
}
else
{
}
else
{
...
...
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