Skip to content

Commit

Permalink
handler: close rejected connections properly
Browse files Browse the repository at this point in the history
Updated the connection listener to close the rejections that happen due
to IP, properly with the proper status code
  • Loading branch information
kofoworola committed May 3, 2021
1 parent e1ee065 commit 5e5451b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type ConnectionHandler interface {
Handle(logger *logging.Logger)
}

func writeResponse(out io.Writer, version string, status string, header http.Header) error {
func WriteResponse(out io.Writer, version string, status string, header http.Header) error {
var builder strings.Builder
if _, err := builder.WriteString(fmt.Sprintf("%s %s\n", version, status)); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion handler/proxyhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (p *ProxyHandler) Handle(logger *logging.Logger) {

// check the authorization
if !checkAuthorization(p.cfg, req) {
if err := writeResponse(
if err := WriteResponse(
p.incoming,
req.Proto,
"407 Proxy Authentication Required",
Expand Down
2 changes: 1 addition & 1 deletion handler/tunnelhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (h *TunnelHandler) Handle(logger *logging.Logger) {
}
// check the authorization
if !checkAuthorization(h.cfg, req) {
if err := writeResponse(
if err := WriteResponse(
h.incoming,
req.Proto,
"407 Proxy Authentication Required",
Expand Down
1 change: 1 addition & 0 deletions tunnelify.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (s *Server) Start() error {

// check if allowed
if !s.config.ShouldAllowIP(c.RemoteAddr().String()) {
handler.WriteResponse(c, "HTTP/1.1", "403 Forbidden", nil)
c.Close()
continue
}
Expand Down

0 comments on commit 5e5451b

Please sign in to comment.