Skip to content

Commit

Permalink
Attempt to fix "No data available for forward proxy to work on"
Browse files Browse the repository at this point in the history
Signed-off-by: Chun-Hung Tseng <[email protected]>
  • Loading branch information
henrybear327 committed May 12, 2024
1 parent 7e2e3b5 commit 9df3252
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions pkg/proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,16 +365,19 @@ func (s *server) listenAndServe() {
continue
}

parseHeaderForDestination := func() string {
parseHeaderForDestination := func() *string {
// the first request should always contain a CONNECT header field
// since we set the transport to forward the traffic to the proxy
buf := make([]byte, s.bufferSize)
var data []byte
var nr1 int
if nr1, err = in.Read(buf); err != nil {
if err == io.EOF {
panic("No data available for forward proxy to work on")
return nil
// why??
// panic("No data available for forward proxy to work on")
}
panic(err)
} else {
data = buf[:nr1]
}
Expand All @@ -394,7 +397,7 @@ func (s *server) listenAndServe() {
}
connectResponse.Write(in)

return req.URL.Host
return &req.URL.Host
}

panic("Wrong header type to start the connection")
Expand All @@ -418,15 +421,21 @@ func (s *server) listenAndServe() {
continue
}
if s.isForwardProxy {
dest := parseHeaderForDestination()
out, err = tp.DialContext(ctx, "tcp", dest)
if dest := parseHeaderForDestination(); dest == nil {
continue
} else {
out, err = tp.DialContext(ctx, "tcp", *dest)
}
} else {
out, err = tp.DialContext(ctx, s.to.Scheme, s.to.Host)
}
} else {
if s.isForwardProxy {
dest := parseHeaderForDestination()
out, err = net.Dial("tcp", dest)
if dest := parseHeaderForDestination(); dest == nil {
continue
} else {
out, err = net.Dial("tcp", *dest)
}
} else {
out, err = net.Dial(s.to.Scheme, s.to.Host)
}
Expand Down

0 comments on commit 9df3252

Please sign in to comment.