(next http.Handler)
| 100 | } |
| 101 | |
| 102 | func (s *Server) withMiddleware(next http.Handler) http.Handler { |
| 103 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 104 | w.Header().Set("Access-Control-Allow-Origin", "*") |
| 105 | w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type") |
| 106 | w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS") |
| 107 | if r.Method == http.MethodOptions { |
| 108 | w.WriteHeader(http.StatusNoContent) |
| 109 | return |
| 110 | } |
| 111 | if s.token != "" && r.Header.Get("Authorization") != "Bearer "+s.token { |
| 112 | writeError(w, http.StatusUnauthorized, "unauthorized") |
| 113 | return |
| 114 | } |
| 115 | next.ServeHTTP(w, r) |
| 116 | }) |
| 117 | } |
| 118 | |
| 119 | func (s *Server) handleVersion(w http.ResponseWriter, r *http.Request) { |
| 120 | if r.Method != http.MethodGet { |
no test coverage detected