OsSetContentType

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(Remove wrong script)
(Add new exemple)
 
Line 7: Line 7:
 
The threat level was upgraded to Severe as of commit #2c2b887c8a on December 11, 2018.
 
The threat level was upgraded to Severe as of commit #2c2b887c8a on December 11, 2018.
 
|ossl_example=<source lang="lsl">
 
|ossl_example=<source lang="lsl">
 +
//
 +
// osSetContentType Script Exemple
 +
// Author: djphil
 +
//
 +
 +
integer use_ossl = TRUE;
 +
integer use_html = TRUE;
 +
 +
string html = "<!DOCTYPE html>
 +
<html>
 +
<head>
 +
    <title>osSetContentType</title>
 +
</head>
 +
<body>
 +
    <h1>My first heading</h1>
 +
    <h2>My second heading</h2>
 +
    <h3>My third heading</h3>
 +
    <h4>My fourth heading</h4>
 +
    <h5>My fifth heading</h5>
 +
    <h6>My sixth heading</h6>
 +
    <p>My first paragraph.</p>
 +
    <p>My <b>second</b> paragraph.</p>
 +
    <p>My <i>third</i> paragraph.</p>
 +
</body>
 +
</html>";
 +
 +
key request;
 +
string url;
 +
 +
default
 +
{
 +
    state_entry()
 +
    {
 +
        llSay(PUBLIC_CHANNEL, "Touch to see osSetContentType usage.");
 +
    }
 +
 +
    touch_start(integer number)
 +
    {
 +
        llReleaseURL(url);
 +
        request = llRequestURL();
 +
    }
 +
 +
    http_request(key id, string method, string body)
 +
    {
 +
        request = "";
 +
        url = "";
 +
       
 +
        if (method == URL_REQUEST_DENIED)
 +
        {
 +
            llSay(PUBLIC_CHANNEL, "Request denied ...");
 +
        }
 +
       
 +
        else if (method == URL_REQUEST_GRANTED)
 +
        {
 +
            url = body;
 +
            llSay(PUBLIC_CHANNEL, "Your url is:\n" + body);
 +
        }
 +
 +
        else if (method == "GET")
 +
        {
 +
            if (use_html)
 +
            {
 +
                if (use_ossl) osSetContentType(id, "text/html");
 +
                else llSetContentType(id, CONTENT_TYPE_HTML);
 +
                llHTTPResponse(id, 200, html);
 +
            }
 +
 +
            else
 +
            {
 +
                if (use_ossl) osSetContentType(id, "text/plain");
 +
                else llSetContentType(id, CONTENT_TYPE_TEXT);
 +
                llHTTPResponse(id, 200, "Hello world!");
 +
            }
 +
        }
 +
    }
 +
}
 
</source>
 
</source>
 
|additional_info=This function was added in 0.7.5-post-fixes.
 
|additional_info=This function was added in 0.7.5-post-fixes.
 
}}
 
}}

Latest revision as of 18:34, 3 December 2020

osSetContentType(key id, string type)
Sets an arbitrary content return type for an llRequestUrl().

The threat level was upgraded to Severe as of commit #2c2b887c8a on December 11, 2018.

Threat Level Severe
Permissions ${OSSL|osslParcelO}ESTATE_MANAGER,ESTATE_OWNER
Extra Delay 0 seconds
Example(s)
//
// osSetContentType Script Exemple
// Author: djphil
//
 
integer use_ossl = TRUE;
integer use_html = TRUE;
 
string html = "<!DOCTYPE html>
<html>
<head>
    <title>osSetContentType</title>
</head>
<body>
    <h1>My first heading</h1>
    <h2>My second heading</h2>
    <h3>My third heading</h3>
    <h4>My fourth heading</h4>
    <h5>My fifth heading</h5>
    <h6>My sixth heading</h6>
    <p>My first paragraph.</p>
    <p>My <b>second</b> paragraph.</p>
    <p>My <i>third</i> paragraph.</p>
</body>
</html>";
 
key request;
string url;
 
default
{
    state_entry()
    {
        llSay(PUBLIC_CHANNEL, "Touch to see osSetContentType usage.");
    }
 
    touch_start(integer number)
    {
        llReleaseURL(url);
        request = llRequestURL();
    }
 
    http_request(key id, string method, string body)
    {
        request = "";
        url = "";
 
        if (method == URL_REQUEST_DENIED)
        {
            llSay(PUBLIC_CHANNEL, "Request denied ...");
        }
 
        else if (method == URL_REQUEST_GRANTED)
        {
            url = body;
            llSay(PUBLIC_CHANNEL, "Your url is:\n" + body);
        }
 
        else if (method == "GET")
        {
            if (use_html)
            {
                if (use_ossl) osSetContentType(id, "text/html");
                else llSetContentType(id, CONTENT_TYPE_HTML);
                llHTTPResponse(id, 200, html);
            }
 
            else
            {
                if (use_ossl) osSetContentType(id, "text/plain");
                else llSetContentType(id, CONTENT_TYPE_TEXT);
                llHTTPResponse(id, 200, "Hello world!");
            }
        }
    }
}
Notes
This function was added in 0.7.5-post-fixes.
Personal tools
General
About This Wiki