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