Skip to content

Commit

Permalink
Fix proxy websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
nightfury1204 committed Aug 29, 2024
1 parent 317a496 commit fbb0fd5
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 150 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/convox/logger v0.0.0-20180522214415-e39179955b52
github.com/convox/stdapi v1.1.3-0.20221110171947-8d98f61e61ed
github.com/convox/stdcli v0.0.0-20230203181735-23ed17b69b51
github.com/convox/stdsdk v0.0.0-20190422120437-3e80a397e377
github.com/convox/stdsdk v0.0.2
github.com/convox/version v0.0.0-20160822184233-ffefa0d565d2
github.com/docker/docker v1.13.1
github.com/docker/go-units v0.3.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ github.com/convox/stdcli v0.0.0-20230203181735-23ed17b69b51 h1:03Yia3LZwsHUovVEP
github.com/convox/stdcli v0.0.0-20230203181735-23ed17b69b51/go.mod h1:kLknwv4KTN9f9fZ2DDvG/L9ndXkcijaexIZ0enACvSc=
github.com/convox/stdsdk v0.0.0-20190422120437-3e80a397e377 h1:PuSJ72MD0mYsMCTvTQ1YydIbQUWtEykNHyweI/vA0PY=
github.com/convox/stdsdk v0.0.0-20190422120437-3e80a397e377/go.mod h1:y1vtmkDKBkWSQ6e2gPXAyz1NCuWZ2x3vrP/SFeDDNco=
github.com/convox/stdsdk v0.0.2 h1:WPJ697SzzawzUBz5hW8i9VbWqwN9DM7aSfusb9USCi8=
github.com/convox/stdsdk v0.0.2/go.mod h1:y1vtmkDKBkWSQ6e2gPXAyz1NCuWZ2x3vrP/SFeDDNco=
github.com/convox/version v0.0.0-20160822184233-ffefa0d565d2 h1:tdp/1KHBnbne0yT1yuKnAdOTBHRue9yQ4oON8rzGgZc=
github.com/convox/version v0.0.0-20160822184233-ffefa0d565d2/go.mod h1:s8HHEf4LLsmPppeubX/A5bz1JpLYkDXbu+ciuYMTk8A=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
Expand Down
10 changes: 4 additions & 6 deletions pkg/api/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/convox/rack/pkg/structs"
"github.com/convox/stdapi"
"github.com/convox/stdsdk"
)

func (s *Server) AppCancel(c *stdapi.Context) error {
Expand Down Expand Up @@ -579,14 +580,13 @@ func (s *Server) InstanceShell(c *stdapi.Context) error {
}

id := c.Var("id")
rw := c

var opts structs.InstanceShellOptions
if err := stdapi.UnmarshalOptions(c.Request(), &opts); err != nil {
return err
}

v, err := s.provider(c).WithContext(c.Context()).InstanceShell(id, rw, opts)
v, err := s.provider(c).WithContext(c.Context()).InstanceShell(id, stdsdk.NewAdapterWs(c.Websocket()), opts)
if err != nil {
return err
}
Expand Down Expand Up @@ -731,14 +731,13 @@ func (s *Server) ProcessExec(c *stdapi.Context) error {
app := c.Var("app")
pid := c.Var("pid")
command := c.Value("command")
rw := c

var opts structs.ProcessExecOptions
if err := stdapi.UnmarshalOptions(c.Request(), &opts); err != nil {
return err
}

v, err := s.provider(c).WithContext(c.Context()).ProcessExec(app, pid, command, rw, opts)
v, err := s.provider(c).WithContext(c.Context()).ProcessExec(app, pid, command, stdsdk.NewAdapterWs(c.Websocket()), opts)
if err != nil {
return err
}
Expand Down Expand Up @@ -874,7 +873,6 @@ func (s *Server) Proxy(c *stdapi.Context) error {
}

host := c.Var("host")
rw := c

port, cerr := strconv.Atoi(c.Var("port"))
if cerr != nil {
Expand All @@ -886,7 +884,7 @@ func (s *Server) Proxy(c *stdapi.Context) error {
return err
}

err := s.provider(c).WithContext(c.Context()).Proxy(host, port, rw, opts)
err := s.provider(c).WithContext(c.Context()).Proxy(host, port, stdsdk.NewAdapterWs(c.Websocket()), opts)
if err != nil {
return err
}
Expand Down
61 changes: 0 additions & 61 deletions pkg/helpers/stream.go

This file was deleted.

18 changes: 0 additions & 18 deletions pkg/helpers/stream_test.go

This file was deleted.

7 changes: 4 additions & 3 deletions provider/aws/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"net"
"time"

"github.com/convox/rack/pkg/helpers"
"github.com/convox/rack/pkg/structs"
"github.com/convox/stdsdk"
)

func (p *Provider) Proxy(host string, port int, rw io.ReadWriter, opts structs.ProxyOptions) error {
cn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", host, port), 3*time.Second)
cn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", host, port), 5*time.Second)
if err != nil {
return err
}
Expand All @@ -21,7 +21,8 @@ func (p *Provider) Proxy(host string, port int, rw io.ReadWriter, opts structs.P
cn = tls.Client(cn, &tls.Config{})
}

if err := helpers.Pipe(cn, rw); err != nil {
if err := stdsdk.CopyStreamToEachOther(cn, rw); err != nil {
p.log.Errorf("proxy %s", err)
return err
}

Expand Down
3 changes: 2 additions & 1 deletion provider/k8s/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/convox/rack/pkg/helpers"
"github.com/convox/rack/pkg/structs"
"github.com/convox/stdsdk"
)

func (p *Provider) Proxy(host string, port int, rw io.ReadWriter, opts structs.ProxyOptions) error {
Expand All @@ -21,7 +22,7 @@ func (p *Provider) Proxy(host string, port int, rw io.ReadWriter, opts structs.P
cn = tls.Client(cn, &tls.Config{})
}

if err := helpers.Pipe(cn, rw); err != nil {
if err := stdsdk.CopyStreamToEachOther(cn, rw); err != nil {
return err
}

Expand Down
65 changes: 6 additions & 59 deletions vendor/github.com/convox/stdsdk/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fbb0fd5

Please sign in to comment.