-
Notifications
You must be signed in to change notification settings - Fork 3
/
Types.mo
106 lines (89 loc) · 2.29 KB
/
Types.mo
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
94
95
96
97
98
99
100
101
102
103
104
105
106
import TrieMap "mo:base/TrieMap";
import Buffer "mo:base/Buffer";
import JSON "mo:json/JSON";
module {
// incoming http request data types
public type HeaderField = (Text, Text);
public type HttpRequest = {
url : Text;
method : Text;
body : Blob;
headers : [HeaderField];
};
public type HttpResponse = {
body : Blob;
headers : [HeaderField];
status_code : Nat16;
};
// Data types used by this module
public type URL = {
original: Text;
protocol: Text ;
port: Nat16;
host: {
original: Text;
array: [Text];
};
path: {
original: Text;
array: [Text];
};
queryObj: {
original: Text;
get: (Text) -> ?Text;
trieMap: TrieMap.TrieMap<Text, Text>;
keys: [Text];
};
anchor: Text;
};
public type Form = {
get: (Text) -> ?[Text];
trieMap: TrieMap.TrieMap<Text, [Text]>;
keys: [Text];
fileKeys: [Text];
files: (Text) -> ?[File];
};
public type Headers = {
original: [(Text, Text)];
get: (Text) -> ?[Text];
trieMap: TrieMap.TrieMap<Text, [Text]>;
keys: [Text];
};
public type File = {
name: Text;
filename: Text;
mimeType: Text;
mimeSubType: Text;
start: Nat;
end: Nat;
bytes: Buffer.Buffer<Nat8>;
};
public type Body = {
original: Blob;
size: Nat;
form: Form;
text: () -> Text;
deserialize: () -> ?JSON.JSON;
file: () -> ?Buffer.Buffer<Nat8>;
bytes: (start: Nat, end: Nat) -> Buffer.Buffer<Nat8>;
};
public type FormObjType = {
get: (Text) -> ?[Text];
trieMap: TrieMap.TrieMap<Text, [Text]>;
keys: [Text];
fileKeys: [Text];
files: (Text) -> ?[File];
};
public type ParsedHttpRequest = {
method: Text;
url: URL;
headers: Headers;
body: ?Body;
};
// internal types
public type FormDataType = {
#urlencoded: ();
// takes the boundary as an optional parameter
#multipart: ?Text;
};
}