LlSetContentType

From Second Life Wiki

Jump to: navigation, search

Contents

Summary

Function: llSetContentType( key request_id, integer content_type );

Set the Internet media type of an LSL HTTP server response.[1]

• key request_id a valid http_request() key
• integer content_type Media type to use with any following llHTTPResponse(request_id, ...)
content_type Content-Type
CONTENT_TYPE_TEXT 0x0 text/plain
CONTENT_TYPE_HTML 0x1 text/html
CONTENT_TYPE_XML application/xml
CONTENT_TYPE_XHTML application/xhtml+xml
CONTENT_TYPE_ATOM application/atom+xml
CONTENT_TYPE_JSON application/json
CONTENT_TYPE_LLSD application/llsd+xml
CONTENT_TYPE_FORM application/x-www-form-urlencoded
CONTENT_TYPE_RSS application/rss+xml

Caveats

  • This setting will be ignored unless all of these conditions are met:
    1. the web browser is the Second Life client
    2. the user (logged into the SL client viewing the page) is the owner of the object.
    3. the user (logged into the SL client viewing the page) is connected to the region the object is located in
  • Not compatible with group owned objects.
All Issues ~ Search JIRA for related Bugs

Examples

key url_request;
 
string HTML_BODY =
"<!DOCTYPE html>
<html>
<body>
 
<h1>My First Heading</h1>
 
<p>My first paragraph.</p>
 
</body>
</html>";
 
default
{
    state_entry()
    {
        url_request = llRequestURL();
    }
 
    http_request(key id, string method, string body)
    {
        key owner = llGetOwner();
        vector ownerSize = llGetAgentSize(owner);
 
        if (url_request == id)
        {
        //  if you're usually not resetting the query ID
        //  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
        {
            llOwnerSay("request body:\n" + body);
 
        //  if owner in sim
            if (ownerSize)//  != ZERO_VECTOR
            {
                llSetContentType(id, CONTENT_TYPE_HTML);
                llHTTPResponse(id, 200, HTML_BODY);
            }
            else
            {
                llSetContentType(id, CONTENT_TYPE_TEXT);
                llHTTPResponse(id, 200, "OK");
            }
        }
    }
}

Notes

  • A workaround for displaying html to non-owners inworld can be found here.

See Also

Events

•  http_request

Functions

•  llHTTPResponse

Articles

•  LSL HTTP server

Deep Notes

History

  • Released August 16, 2011.
  • SCR-394[c] - Documentation revised but no change in functionality.
Search JIRA for related Issues

Footnotes

  1. ^ This function sets the "Content-Type" header in any subsequent llHTTPResponse responses.

Comments

The client and owner limitations are most likely to remove the possibility of running a website from a prim.

This article wasn't helpful for you? Maybe the related article at the LSL Wiki is able to bring enlightenment.
Personal tools
In other languages