fix domain validator

This commit is contained in:
Alireza Ahmadi
2024-07-18 22:44:59 +02:00
parent 58f4a676b5
commit b2d0134567
+5 -1
View File
@@ -1,6 +1,7 @@
package middleware
import (
"net"
"net/http"
"strings"
@@ -9,7 +10,10 @@ import (
func DomainValidator(domain string) gin.HandlerFunc {
return func(c *gin.Context) {
host := strings.Split(c.Request.Host, ":")[0]
host := c.Request.Host
if colonIndex := strings.LastIndex(host, ":"); colonIndex != -1 {
host, _, _ = net.SplitHostPort(c.Request.Host)
}
if host != domain {
c.AbortWithStatus(http.StatusForbidden)