-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
request.go
74 lines (61 loc) · 1.59 KB
/
request.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
package http_ns
import (
"github.com/inoxlang/inox/internal/core/symbolic"
"github.com/inoxlang/inox/internal/prettyprint"
pprint "github.com/inoxlang/inox/internal/prettyprint"
)
var (
HTTP_REQUEST_PROPNAMES = []string{"method", "url", "path", "body" /*"cookies"*/, "headers"}
ANY_HTTP_REQUEST = &Request{}
)
type Request struct {
symbolic.UnassignablePropsMixin
symbolic.SerializableMixin
symbolic.PotentiallySharable
}
func (r *Request) Test(v symbolic.Value, state symbolic.RecTestCallState) bool {
state.StartCall()
defer state.FinishCall()
_, ok := v.(*Request)
return ok
}
func (req *Request) IsSharable() (bool, string) {
return true, ""
}
func (req *Request) Share(originState *symbolic.State) symbolic.PotentiallySharable {
return req
}
func (req *Request) IsShared() bool {
return true
}
func (req *Request) GetGoMethod(name string) (*symbolic.GoFunction, bool) {
return nil, false
}
func (req *Request) Prop(name string) symbolic.Value {
switch name {
case "method":
return symbolic.ANY_STRING
case "url":
return &symbolic.URL{}
case "path":
return &symbolic.Path{}
case "body":
return &symbolic.Reader{}
case "headers":
return symbolic.NewAnyKeyRecord(symbolic.NewTupleOf(symbolic.ANY_STRING))
case "cookies":
//TODO
fallthrough
default:
return symbolic.GetGoMethodOrPanic(name, req)
}
}
func (Request) PropertyNames() []string {
return HTTP_REQUEST_PROPNAMES
}
func (r *Request) PrettyPrint(w prettyprint.PrettyPrintWriter, config *pprint.PrettyPrintConfig) {
w.WriteName("http.req")
}
func (r *Request) WidestOfType() symbolic.Value {
return &Request{}
}