2023-05-31 01:13:46 +04:30
|
|
|
package middleware
|
|
|
|
|
|
|
|
|
|
import (
|
2024-05-22 17:51:55 +02:00
|
|
|
"net"
|
2023-05-31 01:13:46 +04:30
|
|
|
"net/http"
|
2024-07-14 23:55:04 +02:00
|
|
|
"strings"
|
2023-05-31 01:13:46 +04:30
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func DomainValidatorMiddleware(domain string) gin.HandlerFunc {
|
|
|
|
|
return func(c *gin.Context) {
|
2024-08-08 10:52:59 +02:00
|
|
|
host := c.Request.Host
|
|
|
|
|
if colonIndex := strings.LastIndex(host, ":"); colonIndex != -1 {
|
|
|
|
|
host, _, _ = net.SplitHostPort(c.Request.Host)
|
2024-05-24 04:51:19 +07:00
|
|
|
}
|
2024-07-14 23:55:04 +02:00
|
|
|
|
|
|
|
|
if host != domain {
|
|
|
|
|
c.AbortWithStatus(http.StatusForbidden)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.Next()
|
2023-05-31 01:13:46 +04:30
|
|
|
}
|
|
|
|
|
}
|