diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Scripting')
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs | 16 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs | 152 |
2 files changed, 117 insertions, 51 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs index 43672d1..5e28ee1 100644 --- a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs +++ b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs | |||
@@ -366,6 +366,10 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
366 | try | 366 | try |
367 | { | 367 | { |
368 | Request = (HttpWebRequest) WebRequest.Create(Url); | 368 | Request = (HttpWebRequest) WebRequest.Create(Url); |
369 | |||
370 | //This works around some buggy HTTP Servers like Lighttpd | ||
371 | Request.ServicePoint.Expect100Continue = false; | ||
372 | |||
369 | Request.Method = HttpMethod; | 373 | Request.Method = HttpMethod; |
370 | Request.ContentType = HttpMIMEType; | 374 | Request.ContentType = HttpMIMEType; |
371 | 375 | ||
@@ -440,7 +444,17 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
440 | { | 444 | { |
441 | HttpWebResponse webRsp = (HttpWebResponse)((WebException)e).Response; | 445 | HttpWebResponse webRsp = (HttpWebResponse)((WebException)e).Response; |
442 | Status = (int)webRsp.StatusCode; | 446 | Status = (int)webRsp.StatusCode; |
443 | ResponseBody = webRsp.StatusDescription; | 447 | try |
448 | { | ||
449 | using (Stream responseStream = webRsp.GetResponseStream()) | ||
450 | { | ||
451 | ResponseBody = responseStream.GetStreamString(); | ||
452 | } | ||
453 | } | ||
454 | catch | ||
455 | { | ||
456 | ResponseBody = webRsp.StatusDescription; | ||
457 | } | ||
444 | } | 458 | } |
445 | else | 459 | else |
446 | { | 460 | { |
diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs index a552a28..b6af1f2 100644 --- a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs | |||
@@ -60,6 +60,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
60 | //public ManualResetEvent ev; | 60 | //public ManualResetEvent ev; |
61 | public bool requestDone; | 61 | public bool requestDone; |
62 | public int startTime; | 62 | public int startTime; |
63 | public bool responseSent; | ||
63 | public string uri; | 64 | public string uri; |
64 | } | 65 | } |
65 | 66 | ||
@@ -76,7 +77,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
76 | new Dictionary<string, UrlData>(); | 77 | new Dictionary<string, UrlData>(); |
77 | 78 | ||
78 | 79 | ||
79 | private int m_TotalUrls = 100; | 80 | private int m_TotalUrls = 5000; |
80 | 81 | ||
81 | private uint https_port = 0; | 82 | private uint https_port = 0; |
82 | private IHttpServer m_HttpServer = null; | 83 | private IHttpServer m_HttpServer = null; |
@@ -155,7 +156,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
155 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); | 156 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); |
156 | return urlcode; | 157 | return urlcode; |
157 | } | 158 | } |
158 | string url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/"; | 159 | string url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString(); |
159 | 160 | ||
160 | UrlData urlData = new UrlData(); | 161 | UrlData urlData = new UrlData(); |
161 | urlData.hostID = host.UUID; | 162 | urlData.hostID = host.UUID; |
@@ -165,10 +166,9 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
165 | urlData.urlcode = urlcode; | 166 | urlData.urlcode = urlcode; |
166 | urlData.requests = new Dictionary<UUID, RequestData>(); | 167 | urlData.requests = new Dictionary<UUID, RequestData>(); |
167 | 168 | ||
168 | |||
169 | m_UrlMap[url] = urlData; | 169 | m_UrlMap[url] = urlData; |
170 | 170 | ||
171 | string uri = "/lslhttp/" + urlcode.ToString() + "/"; | 171 | string uri = "/lslhttp/" + urlcode.ToString(); |
172 | 172 | ||
173 | m_HttpServer.AddPollServiceHTTPHandler(uri,HandleHttpPoll, | 173 | m_HttpServer.AddPollServiceHTTPHandler(uri,HandleHttpPoll, |
174 | new PollServiceEventArgs(HttpRequestHandler,HasEvents, GetEvents, NoEvents, | 174 | new PollServiceEventArgs(HttpRequestHandler,HasEvents, GetEvents, NoEvents, |
@@ -233,9 +233,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
233 | return; | 233 | return; |
234 | } | 234 | } |
235 | 235 | ||
236 | foreach (UUID req in data.requests.Keys) | 236 | lock (m_RequestMap) |
237 | m_RequestMap.Remove(req); | 237 | { |
238 | 238 | foreach (UUID req in data.requests.Keys) | |
239 | m_RequestMap.Remove(req); | ||
240 | } | ||
241 | |||
239 | RemoveUrl(data); | 242 | RemoveUrl(data); |
240 | m_UrlMap.Remove(url); | 243 | m_UrlMap.Remove(url); |
241 | } | 244 | } |
@@ -243,32 +246,42 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
243 | 246 | ||
244 | public void HttpResponse(UUID request, int status, string body) | 247 | public void HttpResponse(UUID request, int status, string body) |
245 | { | 248 | { |
246 | if (m_RequestMap.ContainsKey(request)) | 249 | lock (m_RequestMap) |
247 | { | ||
248 | UrlData urlData = m_RequestMap[request]; | ||
249 | urlData.requests[request].responseCode = status; | ||
250 | urlData.requests[request].responseBody = body; | ||
251 | //urlData.requests[request].ev.Set(); | ||
252 | urlData.requests[request].requestDone =true; | ||
253 | } | ||
254 | else | ||
255 | { | 250 | { |
256 | m_log.Info("[HttpRequestHandler] There is no http-in request with id " + request.ToString()); | 251 | if (m_RequestMap.ContainsKey(request)) |
252 | { | ||
253 | UrlData urlData = m_RequestMap[request]; | ||
254 | if (!urlData.requests[request].responseSent) | ||
255 | { | ||
256 | urlData.requests[request].responseCode = status; | ||
257 | urlData.requests[request].responseBody = body; | ||
258 | //urlData.requests[request].ev.Set(); | ||
259 | urlData.requests[request].requestDone = true; | ||
260 | urlData.requests[request].responseSent = true; | ||
261 | } | ||
262 | } | ||
263 | else | ||
264 | { | ||
265 | m_log.Info("[HttpRequestHandler] There is no http-in request with id " + request.ToString()); | ||
266 | } | ||
257 | } | 267 | } |
258 | } | 268 | } |
259 | 269 | ||
260 | public string GetHttpHeader(UUID requestId, string header) | 270 | public string GetHttpHeader(UUID requestId, string header) |
261 | { | 271 | { |
262 | if (m_RequestMap.ContainsKey(requestId)) | 272 | lock (m_RequestMap) |
263 | { | ||
264 | UrlData urlData=m_RequestMap[requestId]; | ||
265 | string value; | ||
266 | if (urlData.requests[requestId].headers.TryGetValue(header,out value)) | ||
267 | return value; | ||
268 | } | ||
269 | else | ||
270 | { | 273 | { |
271 | m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId); | 274 | if (m_RequestMap.ContainsKey(requestId)) |
275 | { | ||
276 | UrlData urlData = m_RequestMap[requestId]; | ||
277 | string value; | ||
278 | if (urlData.requests[requestId].headers.TryGetValue(header, out value)) | ||
279 | return value; | ||
280 | } | ||
281 | else | ||
282 | { | ||
283 | m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId); | ||
284 | } | ||
272 | } | 285 | } |
273 | return String.Empty; | 286 | return String.Empty; |
274 | } | 287 | } |
@@ -290,8 +303,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
290 | { | 303 | { |
291 | RemoveUrl(url.Value); | 304 | RemoveUrl(url.Value); |
292 | removeURLs.Add(url.Key); | 305 | removeURLs.Add(url.Key); |
293 | foreach (UUID req in url.Value.requests.Keys) | 306 | lock (m_RequestMap) |
294 | m_RequestMap.Remove(req); | 307 | { |
308 | foreach (UUID req in url.Value.requests.Keys) | ||
309 | m_RequestMap.Remove(req); | ||
310 | } | ||
295 | } | 311 | } |
296 | } | 312 | } |
297 | 313 | ||
@@ -312,8 +328,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
312 | { | 328 | { |
313 | RemoveUrl(url.Value); | 329 | RemoveUrl(url.Value); |
314 | removeURLs.Add(url.Key); | 330 | removeURLs.Add(url.Key); |
315 | foreach (UUID req in url.Value.requests.Keys) | 331 | lock (m_RequestMap) |
316 | m_RequestMap.Remove(req); | 332 | { |
333 | foreach (UUID req in url.Value.requests.Keys) | ||
334 | m_RequestMap.Remove(req); | ||
335 | } | ||
317 | } | 336 | } |
318 | } | 337 | } |
319 | 338 | ||
@@ -332,14 +351,16 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
332 | { | 351 | { |
333 | Hashtable response = new Hashtable(); | 352 | Hashtable response = new Hashtable(); |
334 | UrlData url; | 353 | UrlData url; |
354 | int startTime = 0; | ||
335 | lock (m_RequestMap) | 355 | lock (m_RequestMap) |
336 | { | 356 | { |
337 | if (!m_RequestMap.ContainsKey(requestID)) | 357 | if (!m_RequestMap.ContainsKey(requestID)) |
338 | return response; | 358 | return response; |
339 | url = m_RequestMap[requestID]; | 359 | url = m_RequestMap[requestID]; |
360 | startTime = url.requests[requestID].startTime; | ||
340 | } | 361 | } |
341 | 362 | ||
342 | if (System.Environment.TickCount - url.requests[requestID].startTime > 25000) | 363 | if (System.Environment.TickCount - startTime > 25000) |
343 | { | 364 | { |
344 | response["int_response_code"] = 500; | 365 | response["int_response_code"] = 500; |
345 | response["str_response_string"] = "Script timeout"; | 366 | response["str_response_string"] = "Script timeout"; |
@@ -348,9 +369,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
348 | response["reusecontext"] = false; | 369 | response["reusecontext"] = false; |
349 | 370 | ||
350 | //remove from map | 371 | //remove from map |
351 | lock (url) | 372 | lock (url.requests) |
352 | { | 373 | { |
353 | url.requests.Remove(requestID); | 374 | url.requests.Remove(requestID); |
375 | } | ||
376 | lock (m_RequestMap) | ||
377 | { | ||
354 | m_RequestMap.Remove(requestID); | 378 | m_RequestMap.Remove(requestID); |
355 | } | 379 | } |
356 | 380 | ||
@@ -372,22 +396,25 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
372 | return false; | 396 | return false; |
373 | } | 397 | } |
374 | url = m_RequestMap[requestID]; | 398 | url = m_RequestMap[requestID]; |
399 | } | ||
400 | lock (url.requests) | ||
401 | { | ||
375 | if (!url.requests.ContainsKey(requestID)) | 402 | if (!url.requests.ContainsKey(requestID)) |
376 | { | 403 | { |
377 | return false; | 404 | return false; |
378 | } | 405 | } |
406 | else | ||
407 | { | ||
408 | if (System.Environment.TickCount - url.requests[requestID].startTime > 25000) | ||
409 | { | ||
410 | return true; | ||
411 | } | ||
412 | if (url.requests[requestID].requestDone) | ||
413 | return true; | ||
414 | else | ||
415 | return false; | ||
416 | } | ||
379 | } | 417 | } |
380 | |||
381 | if (System.Environment.TickCount-url.requests[requestID].startTime>25000) | ||
382 | { | ||
383 | return true; | ||
384 | } | ||
385 | |||
386 | if (url.requests[requestID].requestDone) | ||
387 | return true; | ||
388 | else | ||
389 | return false; | ||
390 | |||
391 | } | 418 | } |
392 | private Hashtable GetEvents(UUID requestID, UUID sessionID, string request) | 419 | private Hashtable GetEvents(UUID requestID, UUID sessionID, string request) |
393 | { | 420 | { |
@@ -399,9 +426,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
399 | if (!m_RequestMap.ContainsKey(requestID)) | 426 | if (!m_RequestMap.ContainsKey(requestID)) |
400 | return NoEvents(requestID,sessionID); | 427 | return NoEvents(requestID,sessionID); |
401 | url = m_RequestMap[requestID]; | 428 | url = m_RequestMap[requestID]; |
429 | } | ||
430 | lock (url.requests) | ||
431 | { | ||
402 | requestData = url.requests[requestID]; | 432 | requestData = url.requests[requestID]; |
403 | } | 433 | } |
404 | 434 | ||
405 | if (!requestData.requestDone) | 435 | if (!requestData.requestDone) |
406 | return NoEvents(requestID,sessionID); | 436 | return NoEvents(requestID,sessionID); |
407 | 437 | ||
@@ -424,14 +454,18 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
424 | response["reusecontext"] = false; | 454 | response["reusecontext"] = false; |
425 | 455 | ||
426 | //remove from map | 456 | //remove from map |
427 | lock (url) | 457 | lock (url.requests) |
428 | { | 458 | { |
429 | url.requests.Remove(requestID); | 459 | url.requests.Remove(requestID); |
460 | } | ||
461 | lock (m_RequestMap) | ||
462 | { | ||
430 | m_RequestMap.Remove(requestID); | 463 | m_RequestMap.Remove(requestID); |
431 | } | 464 | } |
432 | 465 | ||
433 | return response; | 466 | return response; |
434 | } | 467 | } |
468 | |||
435 | public void HttpRequestHandler(UUID requestID, Hashtable request) | 469 | public void HttpRequestHandler(UUID requestID, Hashtable request) |
436 | { | 470 | { |
437 | lock (request) | 471 | lock (request) |
@@ -447,8 +481,8 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
447 | 481 | ||
448 | int pos1 = uri.IndexOf("/");// /lslhttp | 482 | int pos1 = uri.IndexOf("/");// /lslhttp |
449 | int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/ | 483 | int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/ |
450 | int pos3 = uri.IndexOf("/", pos2 + 1);// /lslhttp/<UUID>/ | 484 | int pos3 = pos2 + 37; // /lslhttp/urlcode |
451 | string uri_tmp = uri.Substring(0, pos3 + 1); | 485 | string uri_tmp = uri.Substring(0, pos3); |
452 | //HTTP server code doesn't provide us with QueryStrings | 486 | //HTTP server code doesn't provide us with QueryStrings |
453 | string pathInfo; | 487 | string pathInfo; |
454 | string queryString; | 488 | string queryString; |
@@ -457,10 +491,21 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
457 | pathInfo = uri.Substring(pos3); | 491 | pathInfo = uri.Substring(pos3); |
458 | 492 | ||
459 | UrlData url = null; | 493 | UrlData url = null; |
494 | string urlkey; | ||
460 | if (!is_ssl) | 495 | if (!is_ssl) |
461 | url = m_UrlMap["http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp]; | 496 | urlkey = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp; |
497 | //m_UrlMap[]; | ||
462 | else | 498 | else |
463 | url = m_UrlMap["https://" + m_ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp]; | 499 | urlkey = "https://" + m_ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp; |
500 | |||
501 | if (m_UrlMap.ContainsKey(urlkey)) | ||
502 | { | ||
503 | url = m_UrlMap[urlkey]; | ||
504 | } | ||
505 | else | ||
506 | { | ||
507 | m_log.Warn("[HttpRequestHandler]: http-in request failed; no such url: "+urlkey.ToString()); | ||
508 | } | ||
464 | 509 | ||
465 | //for llGetHttpHeader support we need to store original URI here | 510 | //for llGetHttpHeader support we need to store original URI here |
466 | //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers | 511 | //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers |
@@ -490,7 +535,14 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
490 | if (request.ContainsKey(key)) | 535 | if (request.ContainsKey(key)) |
491 | { | 536 | { |
492 | string val = (String)request[key]; | 537 | string val = (String)request[key]; |
493 | queryString = queryString + key + "=" + val + "&"; | 538 | if (key != "") |
539 | { | ||
540 | queryString = queryString + key + "=" + val + "&"; | ||
541 | } | ||
542 | else | ||
543 | { | ||
544 | queryString = queryString + val + "&"; | ||
545 | } | ||
494 | } | 546 | } |
495 | } | 547 | } |
496 | if (queryString.Length > 1) | 548 | if (queryString.Length > 1) |