@@ -10,89 +10,125 @@ TODO:
1010- Add a Post-routing handler and function
1111
1212# Functions
13+
14+ ## Main Functions
15+
16+ #### HttpServer HttpServer: Create ()
17+ Creates a new HTTPServer.
18+
19+ #### HttpServer: Destroy (HttpServer server)
20+ Destroys the given http server.
21+
1322## Basic Functions
14- #### httpserver.Start(String IP, Number Port)
23+
24+ #### HttpServer: Start (String IP, Number Port)
1525This will start or restart the HTTP Server, and it will listen on the given address + port.
16- NOTE: If a Method function was called like httpserver. Get after httpserver. Start was called, you need to call httpserver. Start again!
17- #### httpserver. Stop()
26+ NOTE: If a Method function was called like HttpServer : Get after HttpServer : Start was called, you need to call HttpServer : Start again!
27+ #### HttpServer : Stop ()
1828This stops the HTTP Server.
19- #### (internal function!) httpserver. Think()
20- This is internally used to manage all requests and to call all functions needed. (Never call this yourself.)
29+ #### (internal function) HttpServer : Think ()
30+ This is internally used to manage all requests and to call all functions needed.
2131
2232## Method Functions
2333All Method functions add a listener for the given path and the given method, like this:
2434``` lua
25- httpserver . Get (" /public" , function (_ , response )
26- print (" Public GET request" )
35+ HttpServer : Get (" /public" , function (_ , response )
36+ print (" Public GET request" )
2737 response .SetContent (" You sent a GET request to a public site." , " text/plain" )
2838end , false )
2939
30- httpserver . Get (" /private" , function (_ , response )
31- print (" Private GET request" )
40+ HttpServer : Get (" /private" , function (_ , response )
41+ print (" Private GET request" )
3242 response .SetContent (" You sent a GET request to a private site." , " text/plain" )
3343end , true )
3444```
3545
3646If you enable the IP Whitelist, only requests sent by connected players are processed.
3747
38- #### httpserver. Get(String path, function (Request, Response), bool ipwhitelist)
39- #### httpserver. Put(String path, function (Request, Response), bool ipwhitelist)
40- #### httpserver. Post(String path, function (Request, Response), bool ipwhitelist)
41- #### httpserver. Patch(String path, function (Request, Response), bool ipwhitelist)
42- #### httpserver. Delete(String path, function (Request, Response), bool ipwhitelist)
43- #### httpserver. Options(String path, function (Request, Response), bool ipwhitelist)
48+ #### HttpServer : Get (String path, function (Request, Response), bool ipwhitelist)
49+ #### HttpServer : Put (String path, function (Request, Response), bool ipwhitelist)
50+ #### HttpServer : Post (String path, function (Request, Response), bool ipwhitelist)
51+ #### HttpServer : Patch (String path, function (Request, Response), bool ipwhitelist)
52+ #### HttpServer : Delete (String path, function (Request, Response), bool ipwhitelist)
53+ #### HttpServer : Options (String path, function (Request, Response), bool ipwhitelist)
4454
4555## Additional Functions
46- #### httpserver.IsRunning()
56+
57+ #### bool HttpServer: IsRunning ()
4758Returns true if the HTTPServer is running.
48- #### httpserver.SetTCPnodelay(bool nodelay)
59+
60+ #### HttpServer: SetTCPnodelay (bool nodelay)
4961Sets whether a delay should be added to tcp or not.
50- #### httpserver.SetReadTimeout(int sec, int usec)
62+
63+ #### HttpServer: SetReadTimeout (int sec, int usec)
5164Sets the maximum amount of time before a read times out.
52- #### httpserver.SetWriteTimeout(int sec, int usec)
65+
66+ #### HttpServer: SetWriteTimeout (int sec, int usec)
5367Sets the maximum amount of time before a write times out.
54- #### httpserver.SetPayloadMaxLength(int maxlength)
68+
69+ #### HttpServer: SetPayloadMaxLength (int maxlength)
5570Sets the maximum payload length.
56- #### httpserver.SetKeepAliveTimeout(int sec)
71+
72+ #### HttpServer: SetKeepAliveTimeout (int sec)
5773Sets the maximum time a connection is kept alive.
58- #### httpserver.SetKeepAliveMaxCount(int amount)
74+
75+ #### HttpServer: SetKeepAliveMaxCount (int amount)
5976Sets the maximum amount of connections that can be kept alive at the same time.
60- #### httpserver.SetMountPoint(string path, string folder)
77+
78+ #### HttpServer: SetMountPoint (string path, string folder)
6179This mounts the given folder to the given path.
6280(You can call this multiple times for the same path to mount multiple folders to it.)
63- #### httpserver.RemoveMountPoint(string path)
81+
82+ #### HttpServer: RemoveMountPoint (string path)
6483This removes all mounts for the given path.
6584
6685## Request
67- #### Request.body
86+
87+ #### bool Request.HasHeader(key)
88+ returns true if the client has the given key in the header.
89+
90+ #### bool Request.HasParam(key)
91+ returns true if the client has the given key in the parameters.
92+
93+ #### string Request.GetHeader(key)
94+ returns the value of the given key from the header.
95+
96+ #### string Request: GetParam (key)
97+ returns the value of the given key from the parameters.
98+
99+ #### string Request: GetBody ()
68100The body of the HTTP Request.
69- #### Request.remote_addr
101+
102+ #### string Request: GetRemoteAddr ()
70103the IP Address of the Person who sent the HTTP Request
71- #### Request.remote_port
104+
105+ #### number Request: GetRemotePort ()
72106The Port the HTTP request was received from.
73- #### Request.local_addr
74- #### Request.local_port
75- #### Request.method
107+
108+ #### string Request: GetLocalAddr ()
109+
110+ #### number Request: GetLocalPort ()
111+
112+ #### string Request: GetMethod ()
76113The HTTP Method that was used like GET or PUT.
77- #### Request.authorization_count
78- #### Request.content_length
114+
115+ #### number Request: GetAuthorizationCount ()
116+
117+ #### number Request: GetContentLength ()
79118The length of the HTTP Request content.
80- #### Request.HasHeader(key)
81- returns true if the client has the given key in the header.
82- #### Request.HasParam(key)
83- returns true if the client has the given key in the parameters.
84- #### Request.GetHeader(key)
85- returns the value of the given key from the header.
86- #### Request.GetParam(key)
87- returns the value of the given key from the parameters.
88119
89120## Response
90- #### Response.SetContent(content, content-type)
121+
122+ #### Response: SetContent (content, content-type)
91123Sets the content like this:
92124``` lua
93125Response .SetContent (" Hello World" , " text/plain" )
94126```
95- #### Response. SetRedirect(url, code)
127+ #### Response: SetRedirect (url, code)
96128Redirects one to the given URL and returns the given code.
97- #### Response.SetHeader(key, value)
129+
130+ #### Response: SetHeader (key, value)
98131Sets the given value for the given key in the header.
132+
133+ #### table Response: GetTable ()
134+ Returns the lua table.
0 commit comments