Skip to content
lsl.devlsl.devLSL Dev

llSetContentType

function
Function syntax
llSetContentType(
  1. key request_id,// Unique key identifying the incoming HTTP request.
  2. integer content_type// CONTENT_TYPE_* constant representing the Internet media type to use. Values: HTTPContentType
);
Energy
10

Sets the 'Content-Type' header of subsequent HTTP server responses (via llHTTPResponse) for request_id using the specified content_type (a CONTENT_TYPE_* constant).

Sets the Internet media type "Content-Type" header of any subsequent LSL HTTP server response via llHTTPResponse.

How to use
llSetContentType(NULL_KEY, 0);
content_typeContent-Type
CONTENT_TYPE_TEXT0text/plain
CONTENT_TYPE_HTML1text/html
CONTENT_TYPE_XML2application/xml
CONTENT_TYPE_XHTML3application/xhtml+xml
CONTENT_TYPE_ATOM4application/atom+xml
CONTENT_TYPE_JSON5application/json
CONTENT_TYPE_LLSD6application/llsd+xml
CONTENT_TYPE_FORM7application/x-www-form-urlencoded
CONTENT_TYPE_RSS8application/rss+xml
  • When using CONTENT_TYPE_HTML, this setting will be ignored unless all of these conditions are met:
  • the web browser is the Second Life client
  • the user (logged into the SL client viewing the page) is the owner of the object.
  • the user (logged into the SL client viewing the page) is connected to the region the object is located in
  • : Obviously this is not compatible with group owned objects. One way around this limitation would be to temporarily attach a repeater.
Example 1
50 collapsed lines
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");
}
}
}
}
  • There is no way to set any other headers in an HTTP response.
  • A workaround for displaying HTML to non-owners inworld can be found here.

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

  • Released August 16, 2011.
  • SCR-394 - Documentation revised but no change in functionality.
Original wiki source

Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.