aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/RestStreamHandler.cs
blob: 64d6ea3f1dd82e0fc5872a15102c1fea9c7c1215 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace OpenSim.Framework.Servers
{
    public class RestStreamHandler : IStreamHandler
    {
        RestMethod m_restMethod;

        private string m_contentType;
        public string ContentType
        {
            get { return m_contentType; }
        }

        private string m_httpMethod;
        public string HttpMethod
        {
            get { return m_httpMethod; }
        }


        public byte[] Handle(string path, Stream request )
        {
            Encoding encoding = Encoding.UTF8;
            StreamReader reader = new StreamReader(request, encoding);

            string requestBody = reader.ReadToEnd();
            reader.Close();

            string responseString = m_restMethod(requestBody, path, m_httpMethod);

            return Encoding.UTF8.GetBytes(responseString);
        }

        public RestStreamHandler(RestMethod restMethod, string httpMethod, string contentType)
        {
            m_restMethod = restMethod;
            m_httpMethod = httpMethod;
            m_contentType = contentType;
        }
    }
}