-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
comparison.go
93 lines (78 loc) · 2.75 KB
/
comparison.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package http_ns
import (
"slices"
"github.com/inoxlang/inox/internal/core"
)
func (s *HttpsServer) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool {
otherServer, ok := other.(*HttpsServer)
return ok && s == otherServer
}
func (r *Request) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool {
otherReq, ok := other.(*Request)
if !ok {
return false
}
return r.Request() == otherReq.Request()
}
func (rw *ResponseWriter) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool {
otherResp, ok := other.(*ResponseWriter)
return ok && rw == otherResp
}
func (r *Response) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool {
otherResp, ok := other.(*Response)
return ok && r == otherResp
}
func (r *Result) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool {
otherResult, ok := other.(*Result)
return ok && r == otherResult
}
func (s Status) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool {
otherStatus, ok := other.(Status)
if !ok {
return false
}
return s.code == otherStatus.code
}
func (c StatusCode) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool {
otherCode, ok := other.(StatusCode)
if !ok {
return false
}
return c == otherCode
}
func (c *Client) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool {
otherClient, ok := other.(*Client)
return ok && c == otherClient
}
func (evs *ServerSentEventSource) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool {
otherSource, ok := other.(*ServerSentEventSource)
return ok && evs == otherSource
}
func (c *ContentSecurityPolicy) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool {
otherCSP, ok := other.(*ContentSecurityPolicy)
if !ok {
return false
}
if len(c.directives) != len(otherCSP.directives) {
return false
}
for name, directive := range c.directives {
otherDirective, ok := otherCSP.directives[name]
if !ok || len(directive.values) != len(otherDirective.values) {
return false
}
for i, val := range directive.values {
if otherDirective.values[i].raw != val.raw {
return false
}
}
}
return true
}
func (p *RequestPattern) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool {
otherPattern, ok := other.(*RequestPattern)
if !ok || !slices.Equal(p.methods, otherPattern.methods) {
return false
}
return p.headers.Equal(ctx, otherPattern.headers, alreadyCompared, depth+1)
}