Files
Local_Perplexity/internal/handler/middleware.go
fedos 8e74e53b3d feat: add Ollama proxy with LLM router and Codex CLI support
Go-сервис-прокси между Codex CLI и Ollama. Добавляет Bearer-авторизацию,
LLM-маршрутизатор (deepseek классифицирует запросы: code/doc/general),
поддержку OpenAI Responses API для Codex CLI, стриминг SSE, кеш модели.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 15:25:15 +03:00

29 lines
828 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package handler
import (
"net/http"
"strings"
)
// TokenAuth — middleware для проверки Bearer-токена.
// Сравнивает токен из заголовка Authorization с AUTH_TOKEN из конфига.
func TokenAuth(token string) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
header := r.Header.Get("Authorization")
if header == "" {
http.Error(w, `{"error":"missing authorization header"}`, http.StatusUnauthorized)
return
}
bearerToken := strings.TrimPrefix(header, "Bearer ")
if bearerToken == header || bearerToken != token {
http.Error(w, `{"error":"invalid or missing token"}`, http.StatusUnauthorized)
return
}
next.ServeHTTP(w, r)
})
}
}