-
Notifications
You must be signed in to change notification settings - Fork 56
/
util.go
38 lines (31 loc) · 819 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package serverHandler
import (
"net/http"
"os"
"path"
"strings"
)
func needResponseBody(method string) bool {
return method != http.MethodHead &&
method != http.MethodOptions &&
method != http.MethodConnect &&
method != http.MethodTrace
}
func containsItem(infos []os.FileInfo, name string) bool {
for i := range infos {
if infos[i].Name() == name {
return true
}
}
return false
}
func getCleanFilePath(requestPath string) (filePath string, ok bool) {
filePath = path.Clean(requestPath)
ok = filePath == path.Base(filePath)
return
}
func getCleanDirFilePath(requestPath string) (filePath string, ok bool) {
filePath = path.Clean(strings.Replace(requestPath, "\\", "/", -1))
ok = filePath[0] != '/' && filePath != "." && filePath != ".." && !strings.HasPrefix(filePath, "../")
return
}