From 00c291ba7b15b9402f647cde544e521164c7e2f5 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Wed, 26 Apr 2023 09:50:08 +0300 Subject: [PATCH] pprofhandler: use bytes.HasPrefix for consistency (#1543) --- pprofhandler/pprof.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pprofhandler/pprof.go b/pprofhandler/pprof.go index 7709e4c453..f372a808f3 100644 --- a/pprofhandler/pprof.go +++ b/pprofhandler/pprof.go @@ -1,9 +1,9 @@ package pprofhandler import ( + "bytes" "net/http/pprof" rtp "runtime/pprof" - "strings" "github.com/valyala/fasthttp" "github.com/valyala/fasthttp/fasthttpadaptor" @@ -22,18 +22,19 @@ var ( // See https://pkg.go.dev/net/http/pprof for details. func PprofHandler(ctx *fasthttp.RequestCtx) { ctx.Response.Header.Set("Content-Type", "text/html") - if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/cmdline") { + switch { + case bytes.HasPrefix(ctx.Path(), []byte("/debug/pprof/cmdline")): cmdline(ctx) - } else if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/profile") { + case bytes.HasPrefix(ctx.Path(), []byte("/debug/pprof/profile")): profile(ctx) - } else if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/symbol") { + case bytes.HasPrefix(ctx.Path(), []byte("/debug/pprof/symbol")): symbol(ctx) - } else if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/trace") { + case bytes.HasPrefix(ctx.Path(), []byte("/debug/pprof/trace")): trace(ctx) - } else { + default: for _, v := range rtp.Profiles() { ppName := v.Name() - if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/"+ppName) { + if bytes.HasPrefix(ctx.Path(), []byte("/debug/pprof/"+ppName)) { namedHandler := fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Handler(ppName).ServeHTTP) namedHandler(ctx) return