Difference between revisions of "LlSetContentType"

From Second Life Wiki
Jump to: navigation, search
m
m
Line 1: Line 1:
 
{{LSL_Function
 
{{LSL_Function
 
|signature=
 
|signature=
{{LSL Const/Signature|CONTENT_TYPE_TEXT|integer|0|nolink=*|c=text/plain}}
+
{{LSL Const/Signature|CONTENT_TYPE_TEXT|integer|0|c=text/plain}}
{{LSL Const/Signature|CONTENT_TYPE_HTML|integer|1|nolink=*|c=text/html}}
+
{{LSL Const/Signature|CONTENT_TYPE_HTML|integer|1|c=text/html}}
{{LSL Const/Signature|CONTENT_TYPE_XML|integer|2|nolink=*|c=application/xml}}
+
{{LSL Const/Signature|CONTENT_TYPE_XML|integer|2|c=application/xml}}
{{LSL Const/Signature|CONTENT_TYPE_XHTML|integer|3|nolink=*|c=application/xhtml+xml}}
+
{{LSL Const/Signature|CONTENT_TYPE_XHTML|integer|3|c=application/xhtml+xml}}
{{LSL Const/Signature|CONTENT_TYPE_ATOM|integer|4|nolink=*|c=application/atom+xml}}
+
{{LSL Const/Signature|CONTENT_TYPE_ATOM|integer|4|c=application/atom+xml}}
{{LSL Const/Signature|CONTENT_TYPE_JSON|integer|5|nolink=*|c=application/json}}
+
{{LSL Const/Signature|CONTENT_TYPE_JSON|integer|5|c=application/json}}
{{LSL Const/Signature|CONTENT_TYPE_LLSD|integer|6|nolink=*|c=application/llsd+xml}}
+
{{LSL Const/Signature|CONTENT_TYPE_LLSD|integer|6|c=application/llsd+xml}}
{{LSL Const/Signature|CONTENT_TYPE_FORM|integer|7|nolink=*|c=application/x-www-form-urlencoded}}
+
{{LSL Const/Signature|CONTENT_TYPE_FORM|integer|7|c=application/x-www-form-urlencoded}}
{{LSL Const/Signature|CONTENT_TYPE_RSS|integer|8|nolink=*|c=application/rss+xml}}
+
{{LSL Const/Signature|CONTENT_TYPE_RSS|integer|8|c=application/rss+xml}}
 
|func=llSetContentType
 
|func=llSetContentType
 
|func_id=?
 
|func_id=?
Line 28: Line 28:
 
! Content-Type
 
! Content-Type
 
{{!}}-
 
{{!}}-
{{!}} {{LSL Const|CONTENT_TYPE_TEXT|integer|0|nolink=*|c=text/plain}}
+
{{!}} {{LSL Const|CONTENT_TYPE_TEXT|integer|0|c=text/plain}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:comment}}
 
{{!}} {{#var:comment}}
 
{{!}}-
 
{{!}}-
{{!}} {{LSL Const|CONTENT_TYPE_HTML|integer|1|nolink=*|c=text/html}}
+
{{!}} {{LSL Const|CONTENT_TYPE_HTML|integer|1|c=text/html}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:comment}}
 
{{!}} {{#var:comment}}
 
{{!}}-
 
{{!}}-
{{!}} {{LSL Const|CONTENT_TYPE_XML|integer|2|nolink=*|c=application/xml}}
+
{{!}} {{LSL Const|CONTENT_TYPE_XML|integer|2|c=application/xml}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:comment}}
 
{{!}} {{#var:comment}}
 
{{!}}-
 
{{!}}-
{{!}} {{LSL Const|CONTENT_TYPE_XHTML|integer|3|nolink=*|c=application/xhtml+xml}}
+
{{!}} {{LSL Const|CONTENT_TYPE_XHTML|integer|3|c=application/xhtml+xml}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:comment}}
 
{{!}} {{#var:comment}}
 
{{!}}-
 
{{!}}-
{{!}} {{LSL Const|CONTENT_TYPE_ATOM|integer|4|nolink=*|c=application/atom+xml}}
+
{{!}} {{LSL Const|CONTENT_TYPE_ATOM|integer|4|c=application/atom+xml}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:comment}}
 
{{!}} {{#var:comment}}
 
{{!}}-
 
{{!}}-
{{!}} {{LSL Const|CONTENT_TYPE_JSON|integer|5|nolink=*|c=application/json}}
+
{{!}} {{LSL Const|CONTENT_TYPE_JSON|integer|5|c=application/json}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:comment}}
 
{{!}} {{#var:comment}}
 
{{!}}-
 
{{!}}-
{{!}} {{LSL Const|CONTENT_TYPE_LLSD|integer|6|nolink=*|c=application/llsd+xml}}
+
{{!}} {{LSL Const|CONTENT_TYPE_LLSD|integer|6|c=application/llsd+xml}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:comment}}
 
{{!}} {{#var:comment}}
 
{{!}}-
 
{{!}}-
{{!}} {{LSL Const|CONTENT_TYPE_FORM|integer|7|nolink=*|c=application/x-www-form-urlencoded}}
+
{{!}} {{LSL Const|CONTENT_TYPE_FORM|integer|7|c=application/x-www-form-urlencoded}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:comment}}
 
{{!}} {{#var:comment}}
 
{{!}}-
 
{{!}}-
{{!}} {{LSL Const|CONTENT_TYPE_RSS|integer|8|nolink=*|c=application/rss+xml}}
+
{{!}} {{LSL Const|CONTENT_TYPE_RSS|integer|8|c=application/rss+xml}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:value}}
 
{{!}} {{#var:comment}}
 
{{!}} {{#var:comment}}
Line 66: Line 66:
 
|spec
 
|spec
 
|caveats=
 
|caveats=
* When using <code>CONTENT_TYPE_HTML</code>, this setting will be ignored unless all of these conditions are met:  
+
* 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 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 the owner of the object.
Line 139: Line 139:
 
|helpers
 
|helpers
 
|also_header
 
|also_header
 +
|also_constants=
 +
{{LSL DefineRow|[[CONTENT_TYPE_ATOM]]}}
 +
{{LSL DefineRow|[[CONTENT_TYPE_FORM]]}}
 +
{{LSL DefineRow|[[CONTENT_TYPE_HTML]]}}
 +
{{LSL DefineRow|[[CONTENT_TYPE_JSON]]}}
 +
{{LSL DefineRow|[[CONTENT_TYPE_LLSD]]}}
 +
{{LSL DefineRow|[[CONTENT_TYPE_RSS]]}}
 +
{{LSL DefineRow|[[CONTENT_TYPE_TEXT]]}}
 +
{{LSL DefineRow|[[CONTENT_TYPE_XHTML]]}}
 +
{{LSL DefineRow|[[CONTENT_TYPE_XML]]}}
 
|also_events={{LSL DefineRow||[[http_request]]}}
 
|also_events={{LSL DefineRow||[[http_request]]}}
 
|also_functions={{LSL DefineRow||[[llHTTPResponse]]}}
 
|also_functions={{LSL DefineRow||[[llHTTPResponse]]}}

Revision as of 09:28, 31 December 2013

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 0 text/plain
CONTENT_TYPE_HTML 1 text/html
CONTENT_TYPE_XML 2 application/xml
CONTENT_TYPE_XHTML 3 application/xhtml+xml
CONTENT_TYPE_ATOM 4 application/atom+xml
CONTENT_TYPE_JSON 5 application/json
CONTENT_TYPE_LLSD 6 application/llsd+xml
CONTENT_TYPE_FORM 7 application/x-www-form-urlencoded
CONTENT_TYPE_RSS 8 application/rss+xml

Caveats

  • When using CONTENT_TYPE_HTML, 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
    Obviously this is not compatible with group owned objects.
All Issues ~ Search JIRA for related Bugs

Examples

<lsl> key url_request;

string HTML_BODY = "<!DOCTYPE html> <html> <body>

My First Heading

My first paragraph.

</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");
           }
       }
   }

}

</lsl>

Notes

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

Deep Notes

History

  • Released August 16, 2011.
  • SCR-394 - 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.

Signature

function void llSetContentType( key request_id, integer content_type );
integer CONTENT_TYPE_TEXT = 0;//text/plain
integer CONTENT_TYPE_HTML = 1;//text/html
integer CONTENT_TYPE_XML = 2;//application/xml
integer CONTENT_TYPE_XHTML = 3;//application/xhtml+xml
integer CONTENT_TYPE_ATOM = 4;//application/atom+xml
integer CONTENT_TYPE_JSON = 5;//application/json
integer CONTENT_TYPE_LLSD = 6;//application/llsd+xml
integer CONTENT_TYPE_FORM = 7;//application/x-www-form-urlencoded
integer CONTENT_TYPE_RSS = 8;//application/rss+xml

Comments

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