The [WebServerRequest] class represents one incoming HTTP request. It also contains the proper helper methods for sending a response.
Since HTML documents has a relatively fixed structure, this class contains head, body, footer properties, the response HTML can be added to these, and then these can be compiled and sent using [code]compile_body()[/code] or the [code]compile_and_send_body()[/code] helpers into the [code]compiled_body[/code] property. This adds an html5 type declaration then the opening [code]html[/code] tag, then the contents of the head variable to the [code]head[/code] section of the response, and then the contents of the body then footer variable into the [code]body[/code] section of the response, then it closes the main [code]html[/code] tag. It also contains helper methods for sending files, handling cookies, storing sessions, storing custom data etc.
CSRF tokens are also supported. These are generated string tokens that are stored in HTTPSessions, but since they are universally needed, helper methods were added directly into [WebServerRequest]. They can be used to validate that a form was actually submitted by the user from a page rendered by the application's server itself, in order to mitigate attacks that use the technique called [C]ross [S]ite [R]equest [F]orgery.
This framework uses a stack like url routing model, where the http path is split along forward slashes, and then these get handled going deeper into the given [WebServer]'s [WebNode] hierarchy, effectively using the node structure as a pseudo filesystem. Of course [WebNode]s can decide on handling the request's parameters themselves instead of letting the default hierarchy based routing to take place. For example [BrowsableFolderServeWebPage] uses this to implement a web based file browser. The currently handled segment can be queried using the [code]get_current_path_segment()[/code]. The [code]pop_path()[/code] and [code]push_path()[/code] helper methods can be used to switch segments.
Returns true if the active [WebPermission] has create permission for this session. It you don't have a [WebPermission] set, all perissions are enabled for every user.
Returns true if the active [WebPermission] has delete permission for this session. It you don't have a [WebPermission] set, all perissions are enabled for every user.
Returns true if the active [WebPermission] has edit permission for this session. It you don't have a [WebPermission] set, all perissions are enabled for every user.
Returns true if the active [WebPermission] has view permission for this session. It you don't have a [WebPermission] set, all perissions are enabled for every user.
Takes the head, body and footer properties, and merges them into the [code]compiled_body[/code] property. It adds an html5 type declaration, then the opening [code]html[/code] tag, then the contents of the [code]head[/code] property to the [code]head[/code] section of the response, and then the contents of the [code]body[/code] then footer property into the [code]body[/code] section of the response, then it closes the main [code]html[/code] tag.
Note: You can override the default doctype declaration by setting the [code]"compiled_body_doctype_override"[/code] meta, the [code]html[/code] tag by setting the [code]"compiled_body_html_tag_override"[/code] meta, and the [code]body[/code] tag by setting the [code]"compiled_body_body_tag_override"[/code] meta using [code]set_meta()[/code].
Returns the currently active path segment. For example if you have [code]http://127.0.0.1/a/b/c[/code], and the current path segment is [code]b[/code], then this will return [code]b[/code].
If you reach the end, it will return an empty String! For example if you have [code]http://127.0.0.1/a/b/c[/code], and the current path segment reached beyond [code]c[/code] (we are at the [WebNode] that has it's [code]uri_segment[/code] set to [code]c[/code]), then this will return empty String. Actually this is how [WebNode]s check whether they need to handle a request themselves or not ([code]if request.get_current_path_segment() == "/": handle_request(request)[/code]).
Returns the index of the currently active path segment. For example if you have [code]http://127.0.0.1/a/b/c[/code], and the current path segment is [code]b[/code], then this will return 1.
Returns the next path segment. For example if you have [code]http://127.0.0.1/a/b/c[/code], and the current path segment is [code]b[/code], then this will return [code]c[/code].
Returns the path of the request, from the current path segment to the end. For example if you have [code]http://127.0.0.1/a/b/c[/code], and the current segment is [code]b[/code], this will return "b/c/" using the it's default arguments.
Returns the url up to the current segment prefixed with [code]/[/code]. For example if you have [code]http://127.0.0.1/a/b/c[/code], and the current segment is [code]b[/code], this will return [code]/a/[/code].
Returns the url up to, including the current segment prefixed with [code]/[/code]. For example if you have [code]http://127.0.0.1/a/b/c[/code], and the current segment is [code]b[/code], this will return [code]/a/b/[/code].
Returns the url up to, including the current segment - parent, prefixed and postfixed with [code]/[/code]. For example if you have [code]http://127.0.0.1/a/b/c[/code], and the current segment is [code]b[/code], this will return [code]/a/[/code] using it's default arguments.
Returns the url up to, including the current segment prefixed with the host, with a [code]/[/code] at the end. For example if you have [code]http://127.0.0.1/a/b/c[/code], and the current segment is [code]b[/code], this will return [code]http://127.0.0.1/a/b/[/code].
Moves the path stack pointer backward once. For example if you have [code]http://127.0.0.1/a/b/c[/code], and the current segment is [code]b[/code], the current segment will become [code]a[/code].
Moves the path stack pointer forward once. For example if you have [code]http://127.0.0.1/a/b/c[/code], and the current segment is [code]b[/code], the current segment will become [code]c[/code]. Note that if you have [code]http://127.0.0.1/a/b/c[/code], and the current segment is [code]c[/code], the current segment will become empty String.
When you eventually send the response, the [WebServerCookie] added here will be added to the message header. If you want to get the receiver to delete a particular cookie, create a [WebServerCookie], add it, and use it's helper deletion related methods, which will end up adding commands to the header when the request is sent that that should (normally) cause the client to delete cookies.
Returns a previously added [WebServerCookie]. If you want to access cookie strings that you previously sent to the client, use [code]get_cookie()[/code], this method is so that you can edit cookies before being sent further.
Removes a previously added [WebServerCookie]. If you want to remove a cookie from the client, see [code]response_add_cookie()[/code] and/or [code]response_remove_cookie_simple()[/code].
The [WebServer] needs to call this when it finished parsing a http request header and setting up a [WebServerRequest]. It parses and sets up inbternals for the easy handling of http paths.
When you call [code]compile_body()[/code] or [code]compile_and_send_body()[/code], the contents of this property will end up in the [code]body[/code] portion of the resulting HTML.
The contents of this property will be sent as response when you call send(). Normally you should use the [code]head[/code], [code]body[/code], and [code]footer[/code] properties along with [code]compile_body()[/code] or [code]compile_and_send_body()[/code], however you can use this directly when needed.
When you call [code]compile_body()[/code] or [code]compile_and_send_body()[/code], the contents of this property will end up in the bottom of the [code]body[/code] portion of the resulting HTML.
When you call [code]compile_body()[/code] or [code]compile_and_send_body()[/code], the contents of this property will end up in the [code]head[/code] portion of the resulting HTML.
Use this to access the active session for this [WebServerRequest].
If you want the session property to have a value, it has to be set manually somewhere along the line. Adding a [HTTPSessionManager] as a direct child of your [WebServer] and adding [SessionSetupWebServerMiddleware] to your [WebRoot] can do this for you automatically.