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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
Astra.. =
---@diagnostic disable-next-line: duplicate-doc-alias
---@alias callback fun(request: HTTPServerRequest, response: HTTPServerResponse): any
---@class HTTPRouteConfiguration
---@field body_limit? number
---@class HTTPRoute
---@field path string
---@field method string
---@field func function
---@field static_dir string?
---@field static_file string?
---@field config HTTPRouteConfiguration?
---@class HTTPMultipart
---@field save_file fun(multipart: HTTPMultipart, file_path: string | nil): string | nil Saves the multipart into disk
---@class HTTPServerRequest
---@field method fun(request: HTTPServerRequest): string Returns the HTTP method (e.g., "GET", "POST").
---@field uri fun(request: HTTPServerRequest): string
---@field queries fun(request: HTTPServerRequest): table
---@field params fun(request: HTTPServerRequest): table
---@field headers fun(request: HTTPServerRequest): table
---@field body fun(request: HTTPServerRequest): HTTPBody|nil Returns the body of the request, which can be a table or a string.
---@field multipart fun(request: HTTPServerRequest): HTTPMultipart|nil
---@field get_cookie fun(request: HTTPServerRequest, name: string): Cookie
---@field new_cookie fun(request: HTTPServerRequest, name: string, value: string): Cookie
---@class HTTPServerResponse
---Sets the HTTP status code of the response
---@field set_status_code fun(response: HTTPServerResponse, new_status_code: number)
---@field set_header fun(response: HTTPServerResponse, key: string, value: string)
---Returns the entire headers list that so far has been set for the response
---@field get_headers fun(response: HTTPServerResponse): table|nil
---@field remove_header fun(response: HTTPServerResponse, key: string)
---@field set_cookie fun(response: HTTPServerResponse, cookie: Cookie)
---@field remove_cookie fun(response: HTTPServerResponse, cookie: Cookie)
---@class Cookie
---@field set_name fun(cookie: Cookie, name: string)
---@field set_value fun(cookie: Cookie, value: string)
---@field set_domain fun(cookie: Cookie, domain: string)
---@field set_path fun(cookie: Cookie, path: string)
---@field set_expiration fun(cookie: Cookie, expiration: number)
---@field set_http_only fun(cookie: Cookie, http_only: boolean)
---@field set_max_age fun(cookie: Cookie, max_age: number)
---@field set_permanent fun(cookie: Cookie)
---@field get_name fun(cookie: Cookie): string?
---@field get_value fun(cookie: Cookie): string?
---@field get_domain fun(cookie: Cookie): string?
---@field get_path fun(cookie: Cookie): string?
---@field get_expiration fun(cookie: Cookie): number?
---@field get_http_only fun(cookie: Cookie): boolean?
---@field get_max_age fun(cookie: Cookie): number?
---@class CloseFrame
---@field code integer
---@field reason string
---@alias WebSocketMessageType "text" | "bytes" | "ping" | "pong" | "close"
---@class WebSocketMessage
---@field type WebSocketMessageType
---@field data string
---@class WebSocket
---Receive another message. Returns `nil` if the stream has closed.
---@field recv fun(socket: WebSocket): WebSocketMessage|nil
---
---A flexible WebSocket message
---@field send fun(socket: WebSocket, message_type: WebSocketMessageType, message: any)
---
---A text WebSocket message
---@field send_text fun(socket: WebSocket, message: string)
---
---A binary WebSocket message
---@field send_bytes fun(socket: WebSocket, bytes: table)
---
---A ping message with the specified payload
---
---The payload here must have a length less than 125 bytes.
---
---Ping messages will be automatically responded to by the server,
---so you do not have to worry about dealing with them yourself.
---@field send_ping fun(socket: WebSocket, bytes: string)
---
---A pong message with the specified payload
---
---The payload here must have a length less than 125 bytes.
---
---Pong messages will be automatically sent to the client if a ping message is received,
---so you do not have to worry about constructing them yourself unless you want to implement a unidirectional heartbeat.
---@field send_pong fun(socket: WebSocket, bytes: string)
---
---@field send_close fun(socket: WebSocket, close_frame: CloseFrame?)
---@alias wscallback fun(socket: WebSocket): any
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------
---@class HTTPServer
---@diagnostic disable-next-line: missing-fields
local HTTPServer =
---@return HTTPServer
local
---@param path string
---@param callback callback
---@param config HTTPRouteConfiguration?
---@param path string
---@param callback callback
---@param config HTTPRouteConfiguration?
---@param path string
---@param callback callback
---@param config HTTPRouteConfiguration?
---@param path string
---@param callback callback
---@param config HTTPRouteConfiguration?
---@param path string
---@param callback callback
---@param config HTTPRouteConfiguration?
---@param path string
---@param callback callback
---@param config HTTPRouteConfiguration?
---@param path string
---@param callback callback
---@param config HTTPRouteConfiguration?
---@param path string
---@param serve_path string
---@param config HTTPRouteConfiguration?
---@param path string
---@param serve_path string
---@param config HTTPRouteConfiguration?
---@param path string
---@param wscallback wscallback
---@param config HTTPRouteConfiguration?
---Runs the server