(boundHost string, guardErr error, openAICompatible bool)
| 280 | } |
| 281 | |
| 282 | func loopbackGuard(boundHost string, guardErr error, openAICompatible bool) gin.HandlerFunc { |
| 283 | allowed := isLoopbackHost(canonicalHost(boundHost)) |
| 284 | return func(c *gin.Context) { |
| 285 | if allowed { |
| 286 | c.Next() |
| 287 | return |
| 288 | } |
| 289 | if openAICompatible && isOpenAICompatiblePath(c) { |
| 290 | core.RespondOpenAIError(c, http.StatusForbidden, guardErr, false) |
| 291 | } else { |
| 292 | core.RespondError(c, http.StatusForbidden, guardErr, false) |
| 293 | } |
| 294 | c.Abort() |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | func isOpenAICompatiblePath(c *gin.Context) bool { |
| 299 | if c == nil || c.Request == nil || c.Request.URL == nil { |
no test coverage detected