-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathutil.go
More file actions
60 lines (50 loc) · 1020 Bytes
/
util.go
File metadata and controls
60 lines (50 loc) · 1020 Bytes
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
58
59
60
package imdb
import (
"errors"
"fmt"
"html"
"net/http"
"regexp"
"strings"
)
func decode(s string) string {
return strings.TrimSpace(html.UnescapeString(s))
}
var stripTagsRE = regexp.MustCompile(`<[^>]*>`)
func stripTags(s string) string {
return stripTagsRE.ReplaceAllString(s, "")
}
type nameSlice []Name
func (s nameSlice) Has(id string) bool {
for _, v := range s {
if v.ID == id {
return true
}
}
return false
}
type stringSlice []string
func (s stringSlice) Has(e string) bool {
for _, v := range s {
if v == e {
return true
}
}
return false
}
var (
errForbidden = errors.New("forbidden by AWS WAF")
errChallenged = errors.New("challenged by AWS WAF")
)
func checkResponse(resp *http.Response) error {
if resp.StatusCode == http.StatusOK {
return nil
}
if resp.StatusCode == http.StatusForbidden {
return errForbidden
}
if resp.Header.Get("X-Amzn-Waf-Action") == "challenge" {
return errChallenged
}
return fmt.Errorf("imdb: status not ok: %v", resp.Status)
}