Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions middleware/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,13 @@ type compressResponseWriter struct {
func (cw *compressResponseWriter) isCompressible() bool {
// Parse the first part of the Content-Type response header.
contentType := cw.Header().Get("Content-Type")
if idx := strings.Index(contentType, ";"); idx >= 0 {
contentType = contentType[0:idx]
}
contentType, _, _ = strings.Cut(contentType, ";")

// Is the content type compressible?
if _, ok := cw.contentTypes[contentType]; ok {
return true
}
if idx := strings.Index(contentType, "/"); idx > 0 {
contentType = contentType[0:idx]
if contentType, _, hadSlash := strings.Cut(contentType, "/"); hadSlash {
_, ok := cw.contentWildcards[contentType]
return ok
}
Expand Down
6 changes: 1 addition & 5 deletions middleware/realip.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ func realIP(r *http.Request) string {
} else if xrip := r.Header.Get(xRealIP); xrip != "" {
ip = xrip
} else if xff := r.Header.Get(xForwardedFor); xff != "" {
i := strings.Index(xff, ",")
if i == -1 {
i = len(xff)
}
ip = xff[:i]
ip, _, _ = strings.Cut(xff, ",")
}
if ip == "" || net.ParseIP(ip) == nil {
return ""
Expand Down
8 changes: 1 addition & 7 deletions middleware/route_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,7 @@ type Pattern struct {

func NewPattern(value string) Pattern {
p := Pattern{}
if i := strings.IndexByte(value, '*'); i >= 0 {
p.wildcard = true
p.prefix = value[0:i]
p.suffix = value[i+1:]
} else {
p.prefix = value
}
p.prefix, p.suffix, p.wildcard = strings.Cut(value, "*")
return p
}

Expand Down
6 changes: 2 additions & 4 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,11 +730,9 @@ func patNextSegment(pattern string) (nodeTyp, string, string, byte, int, int) {
tail = pattern[pe]
}

var rexpat string
if idx := strings.Index(key, ":"); idx >= 0 {
key, rexpat, isRegexp := strings.Cut(key, ":")
if isRegexp {
nt = ntRegexp
rexpat = key[idx+1:]
key = key[:idx]
}

if len(rexpat) > 0 {
Expand Down