Denizen Script Events


Events are a way to listen to things that happened on your server and respond to them through a script. These usually pair with 'world' script containers.
Learn about how events work in The Beginner's Guide.


Showing 1 out of 382 events...
Namewebserver web request
Event Lines webserver web request
Triggerswhen a webserver opened by Command:webserver receives a connection request.
Example
# This example supplies a manual response to any of the "/", "/index", or "/index.html" paths.
my_world_script:
    type: world
    data:
        index:
        - <!DOCTYPE html>
        - <html><head><title>Welcome to my site</title></head>
        - <body><h1>Hi!</h1></body></html>
    events:
        on webserver web request port:8080 path:/|/index|/index.html method:get:
        - determine code:200 passively
        - determine headers:[Content-Type=text/html] passively
        - determine raw_text_content:<script.data_key[data.index].separated_by[<n>]>
Example
# This example gives a default response to any pages not handled on port 8080.
on webserver web request port:8080 priority:1000 has_response:false:
- determine code:404 passively
- determine headers:[Content-Type=text/plain] passively
- determine "raw_text_content:Invalid path"
Example
# This example serves a favicon from the local file path "plugins/Denizen/webroot/favicon.ico" with RAM caching to any open web ports.
on webserver web request path:/favicon.ico:
- determine code:200 passively
- determine cached_file:favicon.ico
Switchesport:<#> to only handle requests to a specific port.
path:<path> to only handle requests that match the given advanced-matcher for the path.
method:<method> to only handle requests with the specific method (such as GET or POST).
has_response:<true/false> to only handle requests that do or don't have a response already.
Contexts<context.method> returns the method that was used (such as GET or POST).
<context.path> returns the path requested (such as "/index.html").
<context.port> returns the port connected to.
<context.remote_address> returns the IP address that connected.
<context.query> returns a MapTag of the query data (if no query, returns empty map).
<context.raw_query> returns the raw query input (if no query, returns null).
<context.raw_user_info> returns the raw user info input (if any) (this is a historical HTTP system that allows sending username/password over query).
<context.headers> returns a MapTag of all input headers, where the key is the header name and the value is a ListTag of header values for that name.
<context.body> returns the text content of the body that was sent, if any. Particularly for POST requests.
<context.body_binary> returns the raw binary content body that was sent, if any. Particularly for POST requests.
<context.has_response> returns true if a response body determination (raw_text_content, file, or cached_file) was applied, or false if not.
Determine"CODE:<Element(Number)>" to set a standard web response code, such as 'code:200' for 'OK', or 'code:404' for 'File Not Found'
"HEADERS": + MapTag to set a map of headers, where map keys are the header name and map values are the text of the value, for example headers:[Content-Type=text/html] ... note that header are sometimes case-sensitive.
"RAW_TEXT_CONTENT:<ElementTag>" to set a raw text content body in response. You may determine only one response - raw text, raw binary, a file, or a cached file. You cannot use multiple.
"RAW_BINARY_CONTENT:<BinaryTag>" to set a raw binary content body in response.
"FILE:<ElementTag>" to set a path to a file to send in response. File path must be within the web-root path configured in Denizen/config.yml. Files will be read async.
"CACHED_FILE:<ElementTag>" to set a path to a file to send in response. The content of the file will be cached in RAM until the server restarts. This is useful for files that definitely won't change. First file read will be sync, all others are instant.
"PARSED_FILE:<ElementTag>" - like "FILE:", but this file will be parsed for tags using syntax like "<{util.pi}>" to separate tags from HTML entries.
"CACHED_PARSED_FILE:<ElementTag>" - like "PARSED_FILE" and "CACHED_FILE" combined. Note that the file will be cached, but the results of tags will be handled at runtime still.
GroupCore
Sourcehttps://github.com/DenizenScript/Denizen-Core/blob/master/src/main/java/com/denizenscript/denizencore/events/core/WebserverWebRequestScriptEvent.java#L29