OsSetContentType: Difference between revisions

From OpenSimulator
Jump to navigationJump to search
imported>Manni
No edit summary
imported>Djphil
Add new exemple
 
(One intermediate revision by the same user not shown)
Line 5: Line 5:
|delay=0
|delay=0
|description=Sets an arbitrary content return type for an [http://wiki.secondlife.com/wiki/LlRequestURL llRequestUrl()].
|description=Sets an arbitrary content return type for an [http://wiki.secondlife.com/wiki/LlRequestURL llRequestUrl()].
|additional_info=This function was added in 0.7.5-post-fixes
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 Example
// osSetContentType Script Exemple
// Author: djphil
//
//


key url_request;
integer use_ossl = TRUE;
integer use_html = TRUE;
string HTML_BODY =
 
"<!DOCTYPE html>
string html = "<!DOCTYPE html>
<html>
<html>
<head>
    <title>osSetContentType</title>
</head>
<body>
<body>
    <h1>My first heading</h1>
<h1>My First Heading</h1>
    <h2>My second heading</h2>
    <h3>My third heading</h3>
<p>My first paragraph.</p>
    <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>
</body>
</html>";
</html>";
 
key request;
string url;
 
default
default
{
{
     state_entry()
     state_entry()
     {
     {
         url_request = llRequestURL();
         llSay(PUBLIC_CHANNEL, "Touch to see osSetContentType usage.");
    }
 
    touch_start(integer number)
    {
        llReleaseURL(url);
        request = llRequestURL();
     }
     }
 
     http_request(key id, string method, string body)
     http_request(key id, string method, string body)
     {
     {
         key owner = llGetOwner();
         request = "";
         vector ownerSize = llGetAgentSize(owner);
         url = "";
       
         if (url_request == id)
         if (method == URL_REQUEST_DENIED)
         {
         {
        //  if you're usually not resetting the query ID
             llSay(PUBLIC_CHANNEL, "Request denied ...");
        //  now is a good time to start!
             url_request = "";
            if (method == URL_REQUEST_GRANTED)
            {
                llOwnerSay("URL: " + body);
            //  if owner in sim
                if (ownerSize)//  != ZERO_VECTOR
                    llLoadURL(owner, "I got a new URL!", body);
            }
            else if (method == URL_REQUEST_DENIED)
                llOwnerSay("Something went wrong, no url:\n" + body);
         }
         }
       
         else
         else if (method == URL_REQUEST_GRANTED)
         {
         {
             llOwnerSay("request body:\n" + body);
             url = body;
            llSay(PUBLIC_CHANNEL, "Your url is:\n" + body);
         //  if owner in sim
        }
             if (ownerSize)//  != ZERO_VECTOR
 
         else if (method == "GET")
        {
             if (use_html)
             {
             {
                 osSetContentType(id, CONTENT_TYPE_HTML);
                 if (use_ossl) osSetContentType(id, "text/html");
                 llHTTPResponse(id, 200, HTML_BODY);
                else llSetContentType(id, CONTENT_TYPE_HTML);
                 llHTTPResponse(id, 200, html);
             }
             }
             else
             else
             {
             {
                 osSetContentType(id, CONTENT_TYPE_TEXT);
                 if (use_ossl) osSetContentType(id, "text/plain");
                 llHTTPResponse(id, 200, "OK");
                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.
}}
}}

Latest revision as of 02:34, 4 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.