Difference between revisions of "LlSetContentType"

From Second Life Wiki
Jump to: navigation, search
(added example script)
m (spelling error)
 
(19 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{{LSL_Function
 
{{LSL_Function
|signature=
 
{{LSL Const/Signature|CONTENT_TYPE_TEXT|integer|hex=0x0|c=text/plain}}
 
{{LSL Const/Signature|CONTENT_TYPE_HTML|integer|hex=0x1|c=text/html}}
 
 
|func=llSetContentType
 
|func=llSetContentType
 
|func_id=?
 
|func_id=?
 
|func_energy=?
 
|func_energy=?
 
|func_sleep
 
|func_sleep
|func_desc=Set the {{Wikipedia|Internet media type|Internet media type}} of an [[LSL HTTP server]] response.{{Footnote|This function sets the "Content-Type" header in any subsequent [[llHTTPResponse]] responses.}}
+
|func_desc=Sets the {{Wikipedia|Internet media type|Internet media type}} <code>{{String|Content-Type}}</code> header of any subsequent [[LSL HTTP server]] response via [[llHTTPResponse]].
 
|sort
 
|sort
 
|func_footnote
 
|func_footnote
 
|return_type
 
|return_type
 
|return_text
 
|return_text
|p1_type=key|p1_name=request_id|p1_desc=a valid [[http_request]]() key
+
|p1_type=key|p1_subtype=handle|p1_name=request_id|p1_desc=a valid [[http_request]]() key|p1_hover=a valid http_request() key
|p2_type=integer|p2_name=content_type|p2_desc=Media type to use with any following [[llHTTPResponse]]('''request_id''', ...)  
+
|p2_type=integer|p2_name=content_type|p2_desc=Media type to use with any following [[llHTTPResponse]]({{LSLP|request_id}}, ...)
|constants={{{!}} class="sortable" {{Prettytable|style=margin-top:0;margin-bottom:0;}}
+
|p2_hover=Media type to use with any following llHTTPResponse(request_id, ...)
{{!}}-{{Hl2}}
+
|constants={{LSL Constants/Content Type}}
! {{!}} content_type
+
! title="Value" {{!}}
+
! Content-Type
+
{{!}}-
+
{{!}} {{LSL Const|CONTENT_TYPE_TEXT|integer|hex=0x0|c=text/plain}}
+
{{!}} {{#var:value}}
+
{{!}} {{#var:comment}}
+
{{!}}-
+
{{!}} {{LSL Const|CONTENT_TYPE_HTML|integer|hex=0x1|c=text/html}}
+
{{!}} {{#var:value}}
+
{{!}} {{#var:comment}}
+
{{!}}}
+
 
|spec
 
|spec
 
|caveats=
 
|caveats=
* 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.
 
*# the user (logged into the SL client viewing the page) is connected to the region the object is located in
 
*# 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.
+
*: Obviously this is not compatible with group owned objects. One way around this limitation would be to [[llAttachToAvatarTemp|temporarily attach]] a repeater.
 
|examples=
 
|examples=
<lsl>
+
<source lang="lsl2">
 
key url_request;
 
key url_request;
  
Line 100: Line 85:
 
     }
 
     }
 
}
 
}
</lsl>
+
</source>
 
|helpers
 
|helpers
 
|also_header
 
|also_header
|also_events={{LSL DefineRow||[[http_request]]}}
+
|also_constants
 +
|also_events=
 +
{{LSL DefineRow||[[http_request]]}}
 +
{{LSL DefineRow||[[http_response]]}}
 
|also_functions={{LSL DefineRow||[[llHTTPResponse]]}}
 
|also_functions={{LSL DefineRow||[[llHTTPResponse]]}}
|also_articles={{LSL DefineRow||[[LSL HTTP server]]}}
+
|also_articles=
 +
{{LSL DefineRow||[[LSL HTTP server]]}}
 +
{{LSL DefineRow||[[HTML HUD Demo]]}}
 
|also_footer
 
|also_footer
 
|notes=
 
|notes=

Latest revision as of 23:05, 15 January 2019

Summary

Function: llSetContentType( key request_id, integer content_type );

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

• 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. One way around this limitation would be to temporarily attach a repeater.
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
•  http_response

Functions

•  llHTTPResponse

Articles

•  LSL HTTP server
•  HTML HUD Demo

Deep Notes

History

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

Search JIRA for related Issues

Signature

function void llSetContentType( key request_id, integer content_type );

Comments

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