@@ -71,10 +71,29 @@ var vmuiFileServer = http.FileServer(http.FS(vmuiFiles))
7171// RequestHandler handles select requests for VictoriaLogs
7272func RequestHandler (w http.ResponseWriter , r * http.Request ) bool {
7373 path := r .URL .Path
74+ if ! strings .HasPrefix (path , "/select/" ) {
75+ // Skip requests, which do not start with /select/, since these aren't our requests.
76+ return false
77+ }
7478 path = strings .TrimPrefix (path , "/select" )
7579 path = strings .ReplaceAll (path , "//" , "/" )
7680
77- // Limit the number of concurrent queries.
81+ if path == "/vmui" {
82+ // VMUI access via incomplete url without `/` in the end. Redirect to complete url.
83+ // Use relative redirect, since the hostname and path prefix may be incorrect if VictoriaMetrics
84+ // is hidden behind vmauth or similar proxy.
85+ _ = r .ParseForm ()
86+ newURL := "vmui/?" + r .Form .Encode ()
87+ httpserver .Redirect (w , newURL )
88+ return true
89+ }
90+ if strings .HasPrefix (path , "/vmui/" ) {
91+ r .URL .Path = path
92+ vmuiFileServer .ServeHTTP (w , r )
93+ return true
94+ }
95+
96+ // Limit the number of concurrent queries, which can consume big amounts of CPU.
7897 startTime := time .Now ()
7998 stopCh := r .Context ().Done ()
8099 select {
@@ -115,24 +134,11 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
115134 }
116135
117136 switch {
118- case path == "/vmui" :
119- // VMUI access via incomplete url without `/` in the end. Redirect to complete url.
120- // Use relative redirect, since, since the hostname and path prefix may be incorrect if VictoriaMetrics
121- // is hidden behind vmauth or similar proxy.
122- _ = r .ParseForm ()
123- path = strings .TrimPrefix (path , "/" )
124- newURL := path + "/?" + r .Form .Encode ()
125- httpserver .Redirect (w , newURL )
126- return true
127137 case path == "/logsql/query" :
128138 logsqlQueryRequests .Inc ()
129139 httpserver .EnableCORS (w , r )
130140 logsql .ProcessQueryRequest (w , r , stopCh )
131141 return true
132- case strings .HasPrefix (path , "/vmui/" ):
133- r .URL .Path = path
134- vmuiFileServer .ServeHTTP (w , r )
135- return true
136142 default :
137143 return false
138144 }
0 commit comments