/
reqfilters.go
57 lines (49 loc) · 1.21 KB
/
reqfilters.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"crypto/md5"
"fmt"
"net/http"
"net/url"
"github.com/PuerkitoBio/purell"
)
func dummyFilter(req *http.Request) *http.Request {
return req
}
func normalizeURL(r *http.Request) *http.Request {
normalized := purell.NormalizeURL(r.URL, purell.FlagsSafe|purell.FlagRemoveDotSegments|purell.FlagRemoveDuplicateSlashes|purell.FlagSortQuery)
newurl, err := url.Parse(normalized)
if err != nil {
debug("Error parsing normalized URL", normalized)
newurl = nil
}
// if r.URL.String() != newurl.String() {
// debug("normalize:", r.URL.String(), "to", newurl.String())
// }
req, err := http.NewRequest("GET", newurl.String(), nil)
if err != nil {
return nil
}
return req
}
//var bfilter BloomFilter
//var bfilter *bloom.BloomFilter = bloom.New(80000000, 5)
func urlSeen(r *http.Request) *http.Request {
if bfilter.TestAndAddString(r.URL.String()) {
return nil
}
return r
/*
_, dup := seen[strings.TrimSpace(r.URL.String())]
if dup {
return nil
}
seen[strings.TrimSpace(r.URL.String())] = struct{}{}*/
}
func euclidean(r *http.Request) *http.Request {
return r
}
func MD5Prefix(s string, l int) string {
data := []byte(s)
res := fmt.Sprintf("%x", md5.Sum(data))
return res[:l]
}