Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 01:00 UTC
| 1 | package metrics |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "strconv" |
| 6 | ) |
| 7 | |
| 8 | func SanitizeCode(s int) string { |
| 9 | switch s { |
| 10 | case 0, 200: |
| 11 | return "200" |
| 12 | default: |
| 13 | return strconv.Itoa(s) |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | // Only support the list of "regular" HTTP methods, see |
| 18 | // https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods |
| 19 | var methodMap = map[string]string{ |
| 20 | "GET": http.MethodGet, "get": http.MethodGet, |
| 21 | "HEAD": http.MethodHead, "head": http.MethodHead, |
| 22 | "PUT": http.MethodPut, "put": http.MethodPut, |
| 23 | "POST": http.MethodPost, "post": http.MethodPost, |
| 24 | "DELETE": http.MethodDelete, "delete": http.MethodDelete, |
| 25 | "CONNECT": http.MethodConnect, "connect": http.MethodConnect, |
| 26 | "OPTIONS": http.MethodOptions, "options": http.MethodOptions, |
| 27 | "TRACE": http.MethodTrace, "trace": http.MethodTrace, |
| 28 | "PATCH": http.MethodPatch, "patch": http.MethodPatch, |
| 29 | } |
| 30 | |
| 31 | // SanitizeMethod sanitizes the method for use as a metric label. This helps |
| 32 | // prevent high cardinality on the method label. The name is always upper case. |
| 33 | func SanitizeMethod(m string) string { |
| 34 | if m, ok := methodMap[m]; ok { |
| 35 | return m |
| 36 | } |
| 37 | |
| 38 | return "OTHER" |
| 39 | } |