OsSetContentType

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(Created page with "{{osslfunc |function_syntax=void osSetContentType(LSL_Key id, string type) |threat_level=High |description=Sets the response type for an HTTP request/response. }}")
 
(Add new exemple)
 
(9 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
{{osslfunc
 
{{osslfunc
|function_syntax=void osSetContentType(LSL_Key id, string type)
+
|function_syntax= osSetContentType(key id, string type)
|threat_level=High
+
|threat_level=Severe
|description=Sets the response type for an HTTP request/response.
+
|permissions=${OSSL|osslParcelO}ESTATE_MANAGER,ESTATE_OWNER
 +
|delay=0
 +
|description=Sets an arbitrary content return type for an [http://wiki.secondlife.com/wiki/LlRequestURL llRequestUrl()].
 +
The threat level was upgraded to Severe as of commit #2c2b887c8a on December 11, 2018.
 +
|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>
 +
|additional_info=This function was added in 0.7.5-post-fixes.
 
}}
 
}}

Latest revision as of 19: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