aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices.AssetServer/AssetHttpServer.cs
diff options
context:
space:
mode:
authorMW2007-05-15 17:51:13 +0000
committerMW2007-05-15 17:51:13 +0000
commit384293ac5676cf7ba1fbf77c182a117bd61822be (patch)
tree122b1ecab835ba2dca6383e5b33375be233821ba /OpenGridServices.AssetServer/AssetHttpServer.cs
parentAdded SimClientPacketHandlers.cs (moved the SimClient Packet handlers into it) (diff)
downloadopensim-SC_OLD-384293ac5676cf7ba1fbf77c182a117bd61822be.zip
opensim-SC_OLD-384293ac5676cf7ba1fbf77c182a117bd61822be.tar.gz
opensim-SC_OLD-384293ac5676cf7ba1fbf77c182a117bd61822be.tar.bz2
opensim-SC_OLD-384293ac5676cf7ba1fbf77c182a117bd61822be.tar.xz
Worked on Asset server, asset downloads (from server to sim) now work.
Asset uploads (from sim to server) may or may not work, needs more testing, if they don't work then it should be just a encoding problem and not hard to fix.
Diffstat (limited to '')
-rw-r--r--OpenGridServices.AssetServer/AssetHttpServer.cs92
1 files changed, 92 insertions, 0 deletions
diff --git a/OpenGridServices.AssetServer/AssetHttpServer.cs b/OpenGridServices.AssetServer/AssetHttpServer.cs
new file mode 100644
index 0000000..8439e92
--- /dev/null
+++ b/OpenGridServices.AssetServer/AssetHttpServer.cs
@@ -0,0 +1,92 @@
1using System;
2using System.Collections.Generic;
3using System.Net;
4using System.Text;
5using System.Text.RegularExpressions;
6using System.Threading;
7//using OpenSim.CAPS;
8using Nwc.XmlRpc;
9using System.Collections;
10using OpenSim.Framework.Console;
11using OpenSim.Servers;
12
13namespace OpenGridServices.AssetServer
14{
15 public class AssetHttpServer :BaseHttpServer
16 {
17 public AssetHttpServer(int port)
18 : base(port)
19 {
20 }
21
22 public override void HandleRequest(Object stateinfo)
23 {
24 try
25 {
26 HttpListenerContext context = (HttpListenerContext)stateinfo;
27
28 HttpListenerRequest request = context.Request;
29 HttpListenerResponse response = context.Response;
30
31 response.KeepAlive = false;
32 response.SendChunked = false;
33
34 System.IO.Stream body = request.InputStream;
35 System.Text.Encoding encoding = System.Text.Encoding.UTF8;
36 System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
37
38 string requestBody = reader.ReadToEnd();
39 body.Close();
40 reader.Close();
41
42 //Console.WriteLine(request.HttpMethod + " " + request.RawUrl + " Http/" + request.ProtocolVersion.ToString() + " content type: " + request.ContentType);
43 //Console.WriteLine(requestBody);
44
45 string responseString = "";
46 switch (request.ContentType)
47 {
48 case "text/xml":
49 // must be XML-RPC, so pass to the XML-RPC parser
50
51 responseString = ParseXMLRPC(requestBody);
52 responseString = Regex.Replace(responseString, "utf-16", "utf-8");
53
54 response.AddHeader("Content-type", "text/xml");
55 break;
56
57 case "application/xml":
58 // probably LLSD we hope, otherwise it should be ignored by the parser
59 responseString = ParseLLSDXML(requestBody);
60 response.AddHeader("Content-type", "application/xml");
61 break;
62
63 case "application/x-www-form-urlencoded":
64 // a form data POST so send to the REST parser
65 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
66 response.AddHeader("Content-type", "text/plain");
67 break;
68
69 case null:
70 // must be REST or invalid crap, so pass to the REST parser
71 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
72 response.AddHeader("Content-type", "text/plain");
73 break;
74
75 }
76
77 Encoding Windows1252Encoding = Encoding.GetEncoding(1252);
78 byte[] buffer = Windows1252Encoding.GetBytes(responseString);
79 System.IO.Stream output = response.OutputStream;
80 response.SendChunked = false;
81 response.ContentLength64 = buffer.Length;
82 output.Write(buffer, 0, buffer.Length);
83 output.Close();
84 }
85 catch (Exception e)
86 {
87 Console.WriteLine(e.ToString());
88 }
89 }
90
91 }
92}