This Project aims to add a HTTPServer to Gmod.
This project uses the cpp-httplib as the HTTPServer.
TODO:
- Move IP Whitelist check to a Pre-routing handler
- Add a Error handler and function
- Add a Exception handler and function
- Add a Pre-routing handler and function
- Add a Post-routing handler and function
This will start or restart the HTTP Server, and it will listen on the given address + port.
NOTE: If a Method function was called like httpserver.Get after httpserver.Start was called, you need to call httpserver.Start again!
This stops the HTTP Server.
This is internally used to manage all requests and to call all functions needed. (Never call this yourself.)
All Method functions add a listener for the given path and the given method, like this:
httpserver.Get("/public", function(_, response)
print("Public GET request")
response.SetContent("You sent a GET request to a public site.", "text/plain")
end, false)
httpserver.Get("/private", function(_, response)
print("Private GET request")
response.SetContent("You sent a GET request to a private site.", "text/plain")
end, true)
If you enable the IP Whitelist, only requests sent by connected players are processed.
Returns true if the HTTPServer is running.
Sets whether a delay should be added to tcp or not.
Sets the maximum amount of time before a read times out.
Sets the maximum amount of time before a write times out.
Sets the maximum payload length.
Sets the maximum time a connection is kept alive.
Sets the maximum amount of connections that can be kept alive at the same time.
This mounts the given folder to the given path. (You can call this multiple times for the same path to mount multiple folders to it.)
This removes all mounts for the given path.
The body of the HTTP Request.
the IP Address of the Person who sent the HTTP Request
The Port the HTTP request was received from.
The HTTP Method that was used like GET or PUT.
The length of the HTTP Request content.
returns true if the client has the given key in the header.
returns true if the client has the given key in the parameters.
returns the value of the given key from the header.
returns the value of the given key from the parameters.
Sets the content like this:
Response.SetContent("Hello World", "text/plain")
Redirects one to the given URL and returns the given code.
Sets the given value for the given key in the header.