llHTTPRespondWithNotecard use notecard to reply to a http_request
tracked
WolfGang Senizen
Suggested a method to reply to a http_request with the contents of a notecard with some simple templating options.
llHTTPRespondWithNotecard(request_id, notecard_id_or_name, list_of_tokens_and_substitutions);
request_id
being the key of the requestnotecard_id_or_name
being a natecard key or name of one in the objects inventorylist_of_tokens_and_substitutions
being a strided key value pair list of tokens to substitute in the notecards contente.g A script doing
http_request( key request_id, string method, string body )
{
llHTTPRespondWithNotecard(
request_id,
"content",
[
"%%A%%", "Hello",
"%%B%%", "World"
]
);
}
With a notecard in it's object inventory called "content" containing
%%A%% %%B%%!!!
%%A%% %%B%%!!!
%%A%% %%B%%!!!
Would serve the http content of
Hello World!!!
Hello World!!!
Hello World!!!
To the request.
This sort of feature was discussed a few times a Simulator User Groups
Log In
WolfGang Senizen
The example left out status by mistake, it should probably look something like
llHTTPRespondWithNotecard(request_id, integer_status, notecard_id_or_name, list_of_tokens_and_substitutions);
WolfGang Senizen
Just incase to avoid possible confusion, the use of
%%
to wrap the "tokens" wasnt some suggestion of markup, it was just an example of how a user could use this.I would say that the if the substitutions were to be a feature, that they just remain a simple string replace, and not try to be some formal templating system.
Maestro Linden
tracked
Bleuhazenfurfle Resident
I was going to mention this has been brought up a couple times.
I do like the substitutions list, that would be insanely useful, especially since the point is not dragging the notecard through script memory (not just laziness — script memory is woefully insufficient for the purpose). Without it, it's rather limited to dumping out static resources (still useful for CSS or JS content, for example).
Personally, I think an even better idea is to allow streamed HTTP; then we could just read the notecard ourselves (or several) and send it out line by line with whatever edits we want (also, streamed reading would allow LSL to process larger pages, which is sorely lacking; the largest pages LSL can handle, sometimes barely fit the page header, let alone it's body). But, that would likely be a deep and complex change — this covers the majority use cases just fine, and allows the system to do the sending in whatever way is most efficient.