Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
gost
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
gost
Commits
9ae36e42
Commit
9ae36e42
authored
Sep 23, 2016
by
rui.zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init http2+tls
parent
7b84fc6c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
3 deletions
+39
-3
conn.go
conn.go
+13
-0
http.go
http.go
+2
-1
http2.go
http2.go
+21
-0
tls.go
tls.go
+3
-2
No files found.
conn.go
View file @
9ae36e42
...
...
@@ -18,6 +18,7 @@ import (
"strings"
"sync"
//"sync/atomic"
"golang.org/x/net/http2"
"time"
)
...
...
@@ -50,6 +51,9 @@ func listenAndServe(arg Args) error {
case
"wss"
:
// websocket security connection
return
NewWs
(
arg
)
.
listenAndServeTLS
()
case
"tls"
:
// tls connection
if
arg
.
Protocol
==
"http2"
||
arg
.
Protocol
==
"h2"
{
// only support http2 over TLS
return
listenAndServeHttp2
(
arg
)
}
ln
,
err
=
tls
.
Listen
(
"tcp"
,
arg
.
Addr
,
&
tls
.
Config
{
Certificates
:
[]
tls
.
Certificate
{
arg
.
Cert
}})
case
"tcp"
:
// Local TCP port forwarding
...
...
@@ -83,6 +87,15 @@ func listenAndServe(arg Args) error {
}
}
func
listenAndServeHttp2
(
arg
Args
)
error
{
srv
:=
http
.
Server
{
Addr
:
arg
.
Addr
,
Handler
:
http
.
HandlerFunc
(
handlerHttp2Request
),
}
http2
.
ConfigureServer
(
&
srv
,
nil
)
return
srv
.
ListenAndServeTLS
(
certFile
,
keyFile
)
}
func
listenAndServeTcpForward
(
arg
Args
)
error
{
raddr
,
err
:=
net
.
ResolveTCPAddr
(
"tcp"
,
arg
.
Remote
)
if
err
!=
nil
{
...
...
http.go
View file @
9ae36e42
...
...
@@ -10,6 +10,8 @@ import (
)
func
handleHttpRequest
(
req
*
http
.
Request
,
conn
net
.
Conn
,
arg
Args
)
{
glog
.
V
(
LINFO
)
.
Infof
(
"[http] %s - %s"
,
conn
.
RemoteAddr
(),
req
.
Host
)
if
glog
.
V
(
LDEBUG
)
{
dump
,
err
:=
httputil
.
DumpRequest
(
req
,
false
)
if
err
!=
nil
{
...
...
@@ -18,7 +20,6 @@ func handleHttpRequest(req *http.Request, conn net.Conn, arg Args) {
glog
.
Infoln
(
string
(
dump
))
}
}
glog
.
V
(
LINFO
)
.
Infof
(
"[http] %s - %s"
,
conn
.
RemoteAddr
(),
req
.
Host
)
var
username
,
password
string
if
arg
.
User
!=
nil
{
...
...
http2.go
0 → 100644
View file @
9ae36e42
package
main
import
(
"github.com/golang/glog"
"net/http"
"net/http/httputil"
)
func
handlerHttp2Request
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
glog
.
V
(
LINFO
)
.
Infof
(
"[http2] %s - %s"
,
r
.
RemoteAddr
,
r
.
Host
)
if
glog
.
V
(
LDEBUG
)
{
dump
,
err
:=
httputil
.
DumpRequest
(
r
,
false
)
if
err
!=
nil
{
glog
.
Infoln
(
err
)
}
else
{
glog
.
Infoln
(
string
(
dump
))
}
}
}
tls.go
View file @
9ae36e42
...
...
@@ -6,7 +6,8 @@ import (
)
const
(
certFile
=
"cert.pem"
keyFile
=
"key.pem"
// This is the default cert file for convenience, providing your own cert is recommended.
rawCert
=
`-----BEGIN CERTIFICATE-----
MIIC5jCCAdCgAwIBAgIBADALBgkqhkiG9w0BAQUwEjEQMA4GA1UEChMHQWNtZSBD
...
...
@@ -58,7 +59,7 @@ nh/BAoGBAMY5z2f1pmMhrvtPDSlEVjgjELbaInxFaxPLR4Pdyzn83gtIIU14+R8X
func
init
()
{
var
err
error
if
tlsCert
,
err
=
tls
.
LoadX509KeyPair
(
"cert.pem"
,
"key.pem"
);
err
!=
nil
{
if
tlsCert
,
err
=
tls
.
LoadX509KeyPair
(
certFile
,
keyFile
);
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
err
)
tlsCert
,
err
=
tls
.
X509KeyPair
([]
byte
(
rawCert
),
[]
byte
(
rawKey
))
...
...
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