Skip to content

Commit 21e5855

Browse files
committed
Fix requests with input data for http
We need to make sure we read our peeked data from our buffer aswell Also close request connection if no remote can be connected Signed-off-by: Jo De Boeck <deboeck.jo@gmail.com>
1 parent 77161df commit 21e5855

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,10 @@ func (s *Server) handleHTTPConnection(conn WriteCloser) {
234234
}
235235
if host == "" {
236236
log.Error().Msg("could not find host in HTTP header")
237+
conn.Close()
237238
return
238239
}
240+
peeked += getPeeked(br)
239241
log.Info().Msgf("Host found: '%s'", host)
240242
if err := s.handleService(conn, host, peeked, false); err != nil {
241243
log.Error().
@@ -258,6 +260,7 @@ func (s *Server) handleService(incoming WriteCloser, serverName, peeked string,
258260
if !exists {
259261
service, exists = s.Services["CATCH_ALL"]
260262
if !exists {
263+
incoming.Close()
261264
return fmt.Errorf("service doesn't exist: %v and no 'CATCH_ALL' service for request", service)
262265
}
263266
}
@@ -274,12 +277,14 @@ func (s *Server) handleService(incoming WriteCloser, serverName, peeked string,
274277
// retrive an active connection and forward traffic on it
275278
activeConn, ok := s.activeConnections[service.ClientSecret]
276279
if !ok {
280+
incoming.Close()
277281
return fmt.Errorf("no active connection for service %s", serverName)
278282
}
279283

280284
log.Info().Msgf("open new stream to client %s", serverName)
281285
stream, err := activeConn.OpenStream()
282286
if err != nil {
287+
incoming.Close()
283288
return fmt.Errorf("failed to open stream: %w", err)
284289
}
285290
outgoing = WrapConn(stream)
@@ -292,6 +297,7 @@ func (s *Server) handleService(incoming WriteCloser, serverName, peeked string,
292297
}
293298
outgoing, err = net.DialTCP("tcp", nil, &net.TCPAddr{IP: net.ParseIP(service.Addr), Port: remotePort})
294299
if err != nil {
300+
incoming.Close()
295301
return fmt.Errorf("error while connection to service: %v", err)
296302
}
297303
}

0 commit comments

Comments
 (0)