Return to index

web functions

local_name = download(url_string)

top

Downloads from URL url_string and stores the returned data in the file local_name. Includes console feedback.

Example:

# Example for download
try
    println download("https://example.com", "/tmp/example.html")
catch err
    println "Download failed"
endtry


string = html_escape(string)

top

Converts HTML special characters to ampersand values.

Example:

# Example for html_escape
println html_escape("<div>Hello & Welcome</div>")


string = html_unescape(string)

top

Converts a string containing ampersand values to include HTML special characters.

Example:

# Example for html_unescape
escaped = html_escape("<div>Hello & Welcome</div>")
println html_unescape(escaped)


device_string = net_interfaces()

top

newline separated list of device names.

Example:

# Example for net_interfaces
println net_interfaces()


bool = web_cache_cleanup_interval(int)

top

Set the number of requests between cache cleanups.

Example:

# Example for web_cache_cleanup_interval
web_cache_cleanup_interval(60)


bool = web_cache_enable(bool)

top

Enable or disable web caching globally.

Example:

# Example for web_cache_enable
web_cache_enable(true)


bool = web_cache_max_age(int)

top

Set the maximum age of cached entries in seconds.

Example:

# Example for web_cache_max_age
web_cache_max_age(3600)


bool = web_cache_max_memory(int)

top

Set the maximum memory usage for cache in MB.

Example:

# Example for web_cache_max_memory
web_cache_max_memory(1000000)


bool = web_cache_max_size(int)

top

Set the maximum number of cached entries.

Example:

# Example for web_cache_max_size
web_cache_max_size(1000000)


bool = web_cache_purge()

top

Manually purge all cached entries.

Example:

# Example for web_cache_purge
web_cache_purge()


map = web_cache_stats()

top

Return cache statistics: size, hits, misses, memory usage.

Example:

# Example for web_cache_stats
println web_cache_stats()


string = web_custom(method_string,loc_string[,[string]assoc_headers_strings])

top

Returns a string with content downloaded from loc_string.

Example:

# Example for web_custom
try
    println web_custom("GET", "https://example.com")
catch err
    println "Network error"
endtry


web_display()

top

Show configured request routing.

Example:

# Example for web_display
println web_display()


bool_okay = web_download(url_string,local_file)

top

Downloads from URL url_string and stores the returned data in the file local_file.

Example:

# Example for web_download
try
    println web_download("https://example.com", "/tmp/example.html")
catch err
    println "Network error"
endtry


structure = web_get(loc_string)

top

Returns a structure with content downloaded from loc_string. .result is the content string. .code is the status code.

Example:

# Example for web_get
try
    println web_get("https://example.com").result
catch err
    println "Network error"
endtry


bool = web_gzip_enable(bool)

top

Enable or disable gzip compression for responses.

Example:

# Example for web_gzip_enable
web_gzip_enable(true)


bool = web_head(loc_string)

top

Makes a HEAD request of the given loc_string. Returns true if retrieved successfully.

Example:

# Example for web_head
try
    println web_head("https://example.com")
catch err
    println "Network error"
endtry


int = web_max_clients()

top

(read-only) returns the maximum permitted client count for a web server.

Example:

# Example for web_max_clients
println web_max_clients()


result_string = web_post(loc_string,[]key_value_list)

top

Perform a HTTP POST.

Example:

# Example for web_post
try
    println web_post("https://example.com", ["key", "value"])
catch err
    println "Network error"
endtry


[]any = web_raw_send(method_string,url_string,headers_map,body_string)

top

Send HTTP request with custom method, headers, and raw body. Returns [body, headers, status_code].

Example:

# Example for web_raw_send
try
    println web_raw_send("example.com", 80, "GET / HTTP/1.0\r\n\r\n")
catch err
    println "Network error"
endtry


call_details = web_serve_decode(webcallstruct)

top

Returns a struct representing details of an inbound web request.


web_serve_decode() returns the following member fields:


.host (host:port), .method, .path, .remote (remote_ip:port) and .data (POST data).

Example:

# Example for web_serve_decode
var w={"host":"localhost:80","path":"/","data":"hi"}
println web_serve_decode(w)  # struct fields


web_serve_log(args)

top

Write arguments to the web log file, if available.

Example:

# Example for web_serve_log
println web_serve_log()


web_serve_log_throttle(start,freq)

top

Set the throttle controls for web server logging.

Example:

# Example for web_serve_log_throttle
web_serve_log_throttle(10, 20)


string = web_serve_path(handle,action_type,request_regex,new_path)

top

Provides a traffic routing instruction to a web server.

Example:

# Example for web_serve_path
try
    id = web_serve_start("/tmp", 18080)
    web_serve_path(id, "S", "/.*", "/index.html")
    web_serve_stop(id)
catch err
    println "Web server error"
endtry


handle = web_serve_start(docroot,port[,vhost])

top

Returns an identifier for a new http server.

Example:

# Example for web_serve_start
try
    id = web_serve_start("/tmp", 18080)
    println web_serve_up(id)
    web_serve_stop(id)
catch err
    println "Web server error"
endtry


success_flag = web_serve_stop(handle)

top

Stops and discards a running http server.

Example:

# Example for web_serve_stop
try
    id = web_serve_start("/tmp", 18080)
    web_serve_stop(id)
catch err
    println "Web server error"
endtry


bool = web_serve_up(handle)

top

Checks if a web server is still running.

Example:

# Example for web_serve_up
try
    id = web_serve_start("/tmp", 18080)
    println web_serve_up(id)
    web_serve_stop(id)
catch err
    println "Web server error"
endtry


web_template()

top