diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs index 87f4798..401d65f 100644 --- a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs +++ b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs | |||
@@ -190,7 +190,15 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
190 | 190 | ||
191 | case (int)HttpRequestConstants.HTTP_BODY_MAXLENGTH: | 191 | case (int)HttpRequestConstants.HTTP_BODY_MAXLENGTH: |
192 | 192 | ||
193 | // TODO implement me | 193 | int len; |
194 | if(int.TryParse(parms[i + 1], out len)) | ||
195 | { | ||
196 | if(len > HttpRequestClass.HttpBodyMaxLenMAX) | ||
197 | len = HttpRequestClass.HttpBodyMaxLenMAX; | ||
198 | else if(len < 64) //??? | ||
199 | len = 64; | ||
200 | htc.HttpBodyMaxLen = len; | ||
201 | } | ||
194 | break; | 202 | break; |
195 | 203 | ||
196 | case (int)HttpRequestConstants.HTTP_VERIFY_CERT: | 204 | case (int)HttpRequestConstants.HTTP_VERIFY_CERT: |
@@ -445,9 +453,11 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
445 | { | 453 | { |
446 | get { return _finished; } | 454 | get { return _finished; } |
447 | } | 455 | } |
448 | // public int HttpBodyMaxLen = 2048; // not implemented | 456 | |
457 | public const int HttpBodyMaxLenMAX = 16384; | ||
449 | 458 | ||
450 | // Parameter members and default values | 459 | // Parameter members and default values |
460 | public int HttpBodyMaxLen = 2048; | ||
451 | public string HttpMethod = "GET"; | 461 | public string HttpMethod = "GET"; |
452 | public string HttpMIMEType = "text/plain;charset=utf-8"; | 462 | public string HttpMIMEType = "text/plain;charset=utf-8"; |
453 | public int HttpTimeout; | 463 | public int HttpTimeout; |
@@ -523,7 +533,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
523 | HttpWebResponse response = null; | 533 | HttpWebResponse response = null; |
524 | Stream resStream = null; | 534 | Stream resStream = null; |
525 | StringBuilder sb = new StringBuilder(); | 535 | StringBuilder sb = new StringBuilder(); |
526 | byte[] buf = new byte[8192]; | 536 | byte[] buf = new byte[HttpBodyMaxLenMAX + 16]; |
527 | string tempString = null; | 537 | string tempString = null; |
528 | int count = 0; | 538 | int count = 0; |
529 | 539 | ||
@@ -608,26 +618,32 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
608 | Status = (int)response.StatusCode; | 618 | Status = (int)response.StatusCode; |
609 | 619 | ||
610 | resStream = response.GetResponseStream(); | 620 | resStream = response.GetResponseStream(); |
621 | int totalBodyBytes = 0; | ||
622 | int maxBytes = HttpBodyMaxLen; | ||
623 | if(maxBytes > buf.Length) | ||
624 | maxBytes = buf.Length; | ||
611 | 625 | ||
626 | // we need to read all allowed or UFT8 conversion may fail | ||
612 | do | 627 | do |
613 | { | 628 | { |
614 | // fill the buffer with data | 629 | // fill the buffer with data |
615 | count = resStream.Read(buf, 0, buf.Length); | 630 | count = resStream.Read(buf, totalBodyBytes, maxBytes - totalBodyBytes); |
616 | 631 | totalBodyBytes += count; | |
617 | // make sure we read some data | 632 | if (totalBodyBytes >= maxBytes) |
618 | if (count != 0) | 633 | break; |
619 | { | ||
620 | // translate from bytes to ASCII text | ||
621 | tempString = Util.UTF8.GetString(buf, 0, count); | ||
622 | 634 | ||
623 | // continue building the string | ||
624 | sb.Append(tempString); | ||
625 | if (sb.Length > 2048) | ||
626 | break; | ||
627 | } | ||
628 | } while (count > 0); // any more data to read? | 635 | } while (count > 0); // any more data to read? |
629 | 636 | ||
630 | ResponseBody = sb.ToString().Replace("\r", ""); | 637 | if(totalBodyBytes > 0) |
638 | { | ||
639 | tempString = Util.UTF8.GetString(buf, 0, totalBodyBytes); | ||
640 | sb.Append(tempString); | ||
641 | sb.Replace("\r", ""); | ||
642 | ResponseBody = sb.ToString(); | ||
643 | sb.Clear(); | ||
644 | } | ||
645 | else | ||
646 | ResponseBody = ""; | ||
631 | } | 647 | } |
632 | catch (WebException e) | 648 | catch (WebException e) |
633 | { | 649 | { |
@@ -670,6 +686,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
670 | resStream.Close(); | 686 | resStream.Close(); |
671 | if (response != null) | 687 | if (response != null) |
672 | response.Close(); | 688 | response.Close(); |
689 | |||
673 | 690 | ||
674 | // We need to resubmit | 691 | // We need to resubmit |
675 | if ( | 692 | if ( |