So where I'm trying to get to here is to be able to collect all the X-SecondLife headers from within Ruby. I've attempted with both Ruby and PHP and seem to only be able to get X-SecondLife-Owner-Name and X-SecondLife-Shard. I suspect I'm just looking in the wrong places for the info because before now I've never tried to do this in either PHP or Ruby so it's all new to me.
So first off, the php stuff. As Velox mentioned on the wiki this is only working in Cayman and Darkwood in 1.9.1 (13). In Morris a call to a php script returns a status of 415. I had already discovered the apache_request_headers() variable, but I don't have php installed as an apache module so unfortunately that doesn't work for me. I've been using phpinfo(INFO_VARIABLES) which probably wouldn't be any good for a real application but from my understand of that function it should still prove the point for the purposes of testing. In a test using that today I have managed to get the first 5 SL headers, but still can't find X-SecondLife-Local-Rotation, X-SecondLife-Local-Velocity, X-SecondLife-Owner-Name or X-SecondLife-Owner-Key. Possibly I'm hitting a limit on the return data here?
Because the return data in this case is HTML I'm just using a simple function like this to test if the headers were returned...
CODE
findHeader(string body, string header) {
integer i = llSubStringIndex(body, header);
if (i != -1)
llWhisper(0, llGetSubString(body, i, i + 50));
}
So if body is the data returned in the body param of the http_response event, and I pass that "HTTP_X_SECONDLIFE" for header it returns...
CODE
HTTP_X_SECONDLIFE_SHARD"]</b></td><td>TestingĀ
If I pass it "HTTP_X_SECONDLIFE_L" I get...
CODE
HTTP_X_SECONDLIFE_LOCAL_POSITION"]</b></td><td>(113
But passing it "HTTP_X_SECONDLIFE_OW" returns nothing.
Now for the Ruby stuff I'm just outputting the contents of the request.env hash. (BTW... llHTTPRequest still seems to work fine in Morris when calling Ruby instead of PHP) I've seen some Ruby sites referring to a variable called header (or maybe it was headers) that is supposed to have this info too, but that always seems to be empty for me. I think maybe request.env is the incoming headers, and the header var is outgoing headers for the response. So atm my Ruby code is a helper function that looks like this...
CODE
def llHTTPRequestTest
returning html = '' do
@request.env.each do |header|
html << header[0] + "|"
html << header[1] + "|" if not header[1].nil?
end
end
end
This is resembling something that would be much more useful in a real app. It should return all the headers separated by pipes. At the LSL end I'm parsing that into a list and just dumping the whole lot to chat.
CODE
headers = llParseString2List(body, ["|"], []);
integer headersLength = llGetListLength(headers);
integer i;
for (i = 0; i < headersLength; i += 2) {
string name = llList2String(headers, i);
llWhisper(0, name + " = " + llList2String(headers, i + 1));
}
The output I get from this combination is...
OK..... I've just answered my own question. I already had it further up the post in fact. The return data is indeed being truncated. The body is never longer than 512 bytes. I changed my Ruby code to the following and got the whole lot back (although I still hit the 512 char limit so I think it's still dropping a handful of chars at the end)
CODE
def llHTTPRequestTest
returning html = '' do
@request.env.each do |header|
if header[0].include? "HTTP_X_SECONDLIFE"
html << header[0] + "|"
html << header[1] + "|" if not header[1].nil?
end
end
end
end
So I guess this raises a new question. Is this a limit of llHTTPRequest, or is it something to do with HTTP in general? Would there be any way to get the rest of the data?
Sorry bout the mammoth post, but I'm sure this will be useful for others, so I'll post the whole thing anyway. Thanx again to Velox Severine for your help with this so far.