Update server.go
Browse files
server.go
CHANGED
|
@@ -99,8 +99,6 @@ func (s *Server) authorize(r *http.Request) bool {
|
|
| 99 |
if key == "" {
|
| 100 |
return true
|
| 101 |
}
|
| 102 |
-
|
| 103 |
-
// 检查 Authorization Header
|
| 104 |
if ah := r.Header.Get("Authorization"); ah != "" {
|
| 105 |
const p = "Bearer "
|
| 106 |
if strings.HasPrefix(ah, p) {
|
|
@@ -110,27 +108,20 @@ func (s *Server) authorize(r *http.Request) bool {
|
|
| 110 |
}
|
| 111 |
}
|
| 112 |
}
|
| 113 |
-
|
| 114 |
-
// 检查 x-goog-api-key Header
|
| 115 |
if h := r.Header.Get("x-goog-api-key"); h != "" {
|
| 116 |
if 1 == subtle.ConstantTimeCompare([]byte(h), []byte(key)) {
|
| 117 |
return true
|
| 118 |
}
|
| 119 |
}
|
| 120 |
-
|
| 121 |
-
// ====== 新增改动开始 ======
|
| 122 |
-
// 检查 URL 查询参数中的 key
|
| 123 |
if qk := r.URL.Query().Get("key"); qk != "" {
|
| 124 |
if 1 == subtle.ConstantTimeCompare([]byte(qk), []byte(key)) {
|
| 125 |
return true
|
| 126 |
}
|
| 127 |
}
|
| 128 |
-
// ====== 新增改动结束 ======
|
| 129 |
-
|
| 130 |
return false
|
| 131 |
}
|
| 132 |
|
| 133 |
-
|
| 134 |
func (s *Server) handleListModels(w http.ResponseWriter, r *http.Request) {
|
| 135 |
if r.Method != http.MethodGet {
|
| 136 |
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
|
|
|
| 99 |
if key == "" {
|
| 100 |
return true
|
| 101 |
}
|
|
|
|
|
|
|
| 102 |
if ah := r.Header.Get("Authorization"); ah != "" {
|
| 103 |
const p = "Bearer "
|
| 104 |
if strings.HasPrefix(ah, p) {
|
|
|
|
| 108 |
}
|
| 109 |
}
|
| 110 |
}
|
|
|
|
|
|
|
| 111 |
if h := r.Header.Get("x-goog-api-key"); h != "" {
|
| 112 |
if 1 == subtle.ConstantTimeCompare([]byte(h), []byte(key)) {
|
| 113 |
return true
|
| 114 |
}
|
| 115 |
}
|
| 116 |
+
// 新增:检查 URL 查询参数中的 key
|
|
|
|
|
|
|
| 117 |
if qk := r.URL.Query().Get("key"); qk != "" {
|
| 118 |
if 1 == subtle.ConstantTimeCompare([]byte(qk), []byte(key)) {
|
| 119 |
return true
|
| 120 |
}
|
| 121 |
}
|
|
|
|
|
|
|
| 122 |
return false
|
| 123 |
}
|
| 124 |
|
|
|
|
| 125 |
func (s *Server) handleListModels(w http.ResponseWriter, r *http.Request) {
|
| 126 |
if r.Method != http.MethodGet {
|
| 127 |
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|