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
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 Returns the URI of the request.
---@field queries fun(request: HTTPServerRequest): table Returns the query list.
---@field headers fun(request: HTTPServerRequest): table Returns a table containing the headers of the request.
---@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 Returns a multipart if available.
---@field get_cookie fun(request: HTTPServerRequest, name: string): Cookie Returns a cookie
---@field new_cookie fun(request: HTTPServerRequest, name: string, value: string): Cookie Returns a cookie
---@class HTTPServerResponse
---@field set_status_code fun(response: HTTPServerResponse, new_status_code: number) Sets the HTTP status code of the response
---@field set_header fun(response: HTTPServerResponse, key: string, value: string) Sets a header
---@field get_headers fun(response: HTTPServerResponse): table|nil Returns the entire headers list that so far has been set for the response
---@field remove_header fun(response: HTTPServerResponse, key: string) Removes a header from the headers list
---@field set_cookie fun(response: HTTPServerResponse, cookie: Cookie) Sets a cookie
---@field remove_cookie fun(response: HTTPServerResponse, cookie: Cookie) Removes a cookie from the list
---@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 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?
---Runs the server