|
|
@ -17,9 +17,14 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
func Test_listenWSAndDial(t *testing.T) {
|
|
|
|
func Test_listenWSAndDial(t *testing.T) {
|
|
|
|
assert := With(t)
|
|
|
|
assert := With(t)
|
|
|
|
listen, err := ListenWS(internet.ContextWithTransportSettings(context.Background(), &Config{
|
|
|
|
|
|
|
|
Path: "ws",
|
|
|
|
lctx := internet.ContextWithStreamSettings(context.Background(), &internet.MemoryStreamConfig{
|
|
|
|
}), net.DomainAddress("localhost"), 13146, func(conn internet.Connection) {
|
|
|
|
ProtocolName: "websocket",
|
|
|
|
|
|
|
|
ProtocolSettings: &Config{
|
|
|
|
|
|
|
|
Path: "ws",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
listen, err := ListenWS(lctx, net.DomainAddress("localhost"), 13146, func(conn internet.Connection) {
|
|
|
|
go func(c internet.Connection) {
|
|
|
|
go func(c internet.Connection) {
|
|
|
|
defer c.Close()
|
|
|
|
defer c.Close()
|
|
|
|
|
|
|
|
|
|
|
@ -37,7 +42,10 @@ func Test_listenWSAndDial(t *testing.T) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
assert(err, IsNil)
|
|
|
|
assert(err, IsNil)
|
|
|
|
|
|
|
|
|
|
|
|
ctx := internet.ContextWithTransportSettings(context.Background(), &Config{Path: "ws"})
|
|
|
|
ctx := internet.ContextWithStreamSettings(context.Background(), &internet.MemoryStreamConfig{
|
|
|
|
|
|
|
|
ProtocolName: "websocket",
|
|
|
|
|
|
|
|
ProtocolSettings: &Config{Path: "ws"},
|
|
|
|
|
|
|
|
})
|
|
|
|
conn, err := Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146))
|
|
|
|
conn, err := Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146))
|
|
|
|
|
|
|
|
|
|
|
|
assert(err, IsNil)
|
|
|
|
assert(err, IsNil)
|
|
|
@ -65,9 +73,13 @@ func Test_listenWSAndDial(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestDialWithRemoteAddr(t *testing.T) {
|
|
|
|
func TestDialWithRemoteAddr(t *testing.T) {
|
|
|
|
assert := With(t)
|
|
|
|
assert := With(t)
|
|
|
|
listen, err := ListenWS(internet.ContextWithTransportSettings(context.Background(), &Config{
|
|
|
|
lctx := internet.ContextWithStreamSettings(context.Background(), &internet.MemoryStreamConfig{
|
|
|
|
Path: "ws",
|
|
|
|
ProtocolName: "websocket",
|
|
|
|
}), net.DomainAddress("localhost"), 13148, func(conn internet.Connection) {
|
|
|
|
ProtocolSettings: &Config{
|
|
|
|
|
|
|
|
Path: "ws",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
listen, err := ListenWS(lctx, net.DomainAddress("localhost"), 13148, func(conn internet.Connection) {
|
|
|
|
go func(c internet.Connection) {
|
|
|
|
go func(c internet.Connection) {
|
|
|
|
defer c.Close()
|
|
|
|
defer c.Close()
|
|
|
|
|
|
|
|
|
|
|
@ -87,7 +99,10 @@ func TestDialWithRemoteAddr(t *testing.T) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
assert(err, IsNil)
|
|
|
|
assert(err, IsNil)
|
|
|
|
|
|
|
|
|
|
|
|
ctx := internet.ContextWithTransportSettings(context.Background(), &Config{Path: "ws", Header: []*Header{{Key: "X-Forwarded-For", Value: "1.1.1.1"}}})
|
|
|
|
ctx := internet.ContextWithStreamSettings(context.Background(), &internet.MemoryStreamConfig{
|
|
|
|
|
|
|
|
ProtocolName: "websocket",
|
|
|
|
|
|
|
|
ProtocolSettings: &Config{Path: "ws", Header: []*Header{{Key: "X-Forwarded-For", Value: "1.1.1.1"}}},
|
|
|
|
|
|
|
|
})
|
|
|
|
conn, err := Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13148))
|
|
|
|
conn, err := Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13148))
|
|
|
|
|
|
|
|
|
|
|
|
assert(err, IsNil)
|
|
|
|
assert(err, IsNil)
|
|
|
@ -111,13 +126,18 @@ func Test_listenWSAndDial_TLS(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
start := time.Now()
|
|
|
|
start := time.Now()
|
|
|
|
|
|
|
|
|
|
|
|
ctx := internet.ContextWithTransportSettings(context.Background(), &Config{
|
|
|
|
ctx := internet.ContextWithStreamSettings(context.Background(), &internet.MemoryStreamConfig{
|
|
|
|
Path: "wss",
|
|
|
|
ProtocolName: "websocket",
|
|
|
|
})
|
|
|
|
ProtocolSettings: &Config{
|
|
|
|
ctx = internet.ContextWithSecuritySettings(ctx, &tls.Config{
|
|
|
|
Path: "wss",
|
|
|
|
AllowInsecure: true,
|
|
|
|
},
|
|
|
|
Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil, cert.CommonName("localhost")))},
|
|
|
|
SecurityType: "tls",
|
|
|
|
|
|
|
|
SecuritySettings: &tls.Config{
|
|
|
|
|
|
|
|
AllowInsecure: true,
|
|
|
|
|
|
|
|
Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil, cert.CommonName("localhost")))},
|
|
|
|
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
listen, err := ListenWS(ctx, net.DomainAddress("localhost"), 13143, func(conn internet.Connection) {
|
|
|
|
listen, err := ListenWS(ctx, net.DomainAddress("localhost"), 13143, func(conn internet.Connection) {
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
_ = conn.Close()
|
|
|
|
_ = conn.Close()
|
|
|
|