@@ -39,11 +39,11 @@ type SSLHostFunc func(host string) (newHost string)
3939// AllowRequestFunc is a custom function type that can be used to dynamically determine if a request should proceed or not.
4040type AllowRequestFunc func (r * http.Request ) bool
4141
42- func defaultBadHostHandler (w http.ResponseWriter , r * http.Request ) {
42+ func defaultBadHostHandler (w http.ResponseWriter , _ * http.Request ) {
4343 http .Error (w , "Bad Host" , http .StatusInternalServerError )
4444}
4545
46- func defaultBadRequestHandler (w http.ResponseWriter , r * http.Request ) {
46+ func defaultBadRequestHandler (w http.ResponseWriter , _ * http.Request ) {
4747 http .Error (w , "Bad Request" , http .StatusBadRequest )
4848}
4949
@@ -302,6 +302,7 @@ func (s *Secure) processRequest(w http.ResponseWriter, r *http.Request) (http.He
302302 for _ , header := range s .opt .HostsProxyHeaders {
303303 if h := r .Header .Get (header ); h != "" {
304304 host = h
305+
305306 break
306307 }
307308 }
@@ -314,20 +315,23 @@ func (s *Secure) processRequest(w http.ResponseWriter, r *http.Request) (http.He
314315 for _ , allowedHost := range s .cRegexAllowedHosts {
315316 if match := allowedHost .MatchString (host ); match {
316317 isGoodHost = true
318+
317319 break
318320 }
319321 }
320322 } else {
321323 for _ , allowedHost := range s .opt .AllowedHosts {
322324 if strings .EqualFold (allowedHost , host ) {
323325 isGoodHost = true
326+
324327 break
325328 }
326329 }
327330 }
328331
329332 if ! isGoodHost {
330333 s .badHostHandler .ServeHTTP (w , r )
334+
331335 return nil , nil , fmt .Errorf ("bad host name: %s" , host )
332336 }
333337 }
@@ -389,6 +393,7 @@ func (s *Secure) processRequest(w http.ResponseWriter, r *http.Request) (http.He
389393 // If the AllowRequestFunc is set, call it and exit early if needed.
390394 if s .opt .AllowRequestFunc != nil && ! s .opt .AllowRequestFunc (r ) {
391395 s .badRequestHandler .ServeHTTP (w , r )
396+
392397 return nil , nil , fmt .Errorf ("request not allowed" )
393398 }
394399
@@ -487,6 +492,7 @@ func (s *Secure) isSSL(r *http.Request) bool {
487492 for k , v := range s .opt .SSLProxyHeaders {
488493 if r .Header .Get (k ) == v {
489494 ssl = true
495+
490496 break
491497 }
492498 }
0 commit comments