aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Servers')
-rw-r--r--OpenSim/Framework/Servers/BinaryStreamHandler.cs44
-rw-r--r--OpenSim/Framework/Servers/RestMethod.cs1
2 files changed, 45 insertions, 0 deletions
diff --git a/OpenSim/Framework/Servers/BinaryStreamHandler.cs b/OpenSim/Framework/Servers/BinaryStreamHandler.cs
new file mode 100644
index 0000000..302dbff
--- /dev/null
+++ b/OpenSim/Framework/Servers/BinaryStreamHandler.cs
@@ -0,0 +1,44 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5
6namespace OpenSim.Framework.Servers
7{
8
9 public class BinaryStreamHandler : BaseStreamHandler
10 {
11 BinaryMethod m_restMethod;
12
13 override public byte[] Handle(string path, Stream request)
14 {
15 byte[] data = ReadFully(request);
16 string param = GetParam(path);
17 string responseString = m_restMethod(data, path, param);
18
19 return Encoding.UTF8.GetBytes(responseString);
20 }
21
22 public BinaryStreamHandler(string httpMethod, string path, BinaryMethod restMethod)
23 : base(httpMethod, path)
24 {
25 m_restMethod = restMethod;
26 }
27
28 public byte[] ReadFully(Stream stream)
29 {
30 byte[] buffer = new byte[32768];
31 using (MemoryStream ms = new MemoryStream())
32 {
33 while (true)
34 {
35 int read = stream.Read(buffer, 0, buffer.Length);
36 if (read <= 0)
37 return ms.ToArray();
38 ms.Write(buffer, 0, read);
39 }
40 }
41 }
42 }
43
44}
diff --git a/OpenSim/Framework/Servers/RestMethod.cs b/OpenSim/Framework/Servers/RestMethod.cs
index c6cb230..2a92fc1 100644
--- a/OpenSim/Framework/Servers/RestMethod.cs
+++ b/OpenSim/Framework/Servers/RestMethod.cs
@@ -28,4 +28,5 @@
28namespace OpenSim.Framework.Servers 28namespace OpenSim.Framework.Servers
29{ 29{
30 public delegate string RestMethod( string request, string path, string param ); 30 public delegate string RestMethod( string request, string path, string param );
31 public delegate string BinaryMethod(byte[] data, string path, string param);
31} 32}