OsSetContentType
From OpenSimulator
(Difference between revisions)
(Add new exemple) |
|||
| (One intermediate revision by one 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()]. | ||
| − | |||
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 | + | // osSetContentType Script Exemple |
| + | // Author: djphil | ||
// | // | ||
| − | + | integer use_ossl = TRUE; | |
| − | + | integer use_html = TRUE; | |
| − | string | + | |
| − | "<!DOCTYPE html> | + | string html = "<!DOCTYPE html> |
<html> | <html> | ||
| + | <head> | ||
| + | <title>osSetContentType</title> | ||
| + | </head> | ||
<body> | <body> | ||
| − | + | <h1>My first heading</h1> | |
| − | <h1>My | + | <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() | ||
{ | { | ||
| − | + | 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) | ||
{ | { | ||
| − | + | request = ""; | |
| − | + | url = ""; | |
| − | + | ||
| − | if ( | + | if (method == URL_REQUEST_DENIED) |
{ | { | ||
| − | + | llSay(PUBLIC_CHANNEL, "Request denied ..."); | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
} | } | ||
| − | + | ||
| − | else | + | else if (method == URL_REQUEST_GRANTED) |
{ | { | ||
| − | + | url = body; | |
| − | + | llSay(PUBLIC_CHANNEL, "Your url is:\n" + body); | |
| − | + | } | |
| − | if ( | + | |
| + | else if (method == "GET") | ||
| + | { | ||
| + | if (use_html) | ||
{ | { | ||
| − | osSetContentType(id, CONTENT_TYPE_HTML); | + | if (use_ossl) osSetContentType(id, "text/html"); |
| − | llHTTPResponse(id, 200, | + | 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, " | + | 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 18:34, 3 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. | |