diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Grid/AssetServer/AssetHttpServer.cs | 125 |
1 files changed, 0 insertions, 125 deletions
diff --git a/OpenSim/Grid/AssetServer/AssetHttpServer.cs b/OpenSim/Grid/AssetServer/AssetHttpServer.cs deleted file mode 100644 index 9546891..0000000 --- a/OpenSim/Grid/AssetServer/AssetHttpServer.cs +++ /dev/null | |||
@@ -1,125 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.IO; | ||
30 | using System.Net; | ||
31 | using System.Text; | ||
32 | using System.Text.RegularExpressions; | ||
33 | using OpenSim.Framework.Servers; | ||
34 | |||
35 | namespace OpenSim.Grid.AssetServer | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// An HTTP server for sending assets | ||
39 | /// </summary> | ||
40 | public class AssetHttpServer :BaseHttpServer | ||
41 | { | ||
42 | /// <summary> | ||
43 | /// Creates the new asset server | ||
44 | /// </summary> | ||
45 | /// <param name="port">Port to initalise on</param> | ||
46 | public AssetHttpServer(int port) | ||
47 | : base(port) | ||
48 | { | ||
49 | } | ||
50 | |||
51 | /// <summary> | ||
52 | /// Handles an HTTP request | ||
53 | /// </summary> | ||
54 | /// <param name="stateinfo">HTTP State Info</param> | ||
55 | public override void HandleRequest(Object stateinfo) | ||
56 | { | ||
57 | try | ||
58 | { | ||
59 | HttpListenerContext context = (HttpListenerContext)stateinfo; | ||
60 | |||
61 | HttpListenerRequest request = context.Request; | ||
62 | HttpListenerResponse response = context.Response; | ||
63 | |||
64 | response.KeepAlive = false; | ||
65 | response.SendChunked = false; | ||
66 | |||
67 | Stream body = request.InputStream; | ||
68 | Encoding encoding = Encoding.UTF8; | ||
69 | StreamReader reader = new StreamReader(body, encoding); | ||
70 | |||
71 | string requestBody = reader.ReadToEnd(); | ||
72 | body.Close(); | ||
73 | reader.Close(); | ||
74 | |||
75 | //Console.WriteLine(request.HttpMethod + " " + request.RawUrl + " Http/" + request.ProtocolVersion.ToString() + " content type: " + request.ContentType); | ||
76 | //Console.WriteLine(requestBody); | ||
77 | |||
78 | string responseString = ""; | ||
79 | switch (request.ContentType) | ||
80 | { | ||
81 | case "text/xml": | ||
82 | // must be XML-RPC, so pass to the XML-RPC parser | ||
83 | |||
84 | responseString = ParseXMLRPC(requestBody); | ||
85 | responseString = Regex.Replace(responseString, "utf-16", "utf-8"); | ||
86 | |||
87 | response.AddHeader("Content-type", "text/xml"); | ||
88 | break; | ||
89 | |||
90 | case "application/xml": | ||
91 | // probably LLSD we hope, otherwise it should be ignored by the parser | ||
92 | responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); | ||
93 | response.AddHeader("Content-type", "application/xml"); | ||
94 | break; | ||
95 | |||
96 | case "application/x-www-form-urlencoded": | ||
97 | // a form data POST so send to the REST parser | ||
98 | responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); | ||
99 | response.AddHeader("Content-type", "text/plain"); | ||
100 | break; | ||
101 | |||
102 | case null: | ||
103 | // must be REST or invalid crap, so pass to the REST parser | ||
104 | responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); | ||
105 | response.AddHeader("Content-type", "text/plain"); | ||
106 | break; | ||
107 | |||
108 | } | ||
109 | |||
110 | Encoding Windows1252Encoding = Encoding.GetEncoding(1252); | ||
111 | byte[] buffer = Windows1252Encoding.GetBytes(responseString); | ||
112 | Stream output = response.OutputStream; | ||
113 | response.SendChunked = false; | ||
114 | response.ContentLength64 = buffer.Length; | ||
115 | output.Write(buffer, 0, buffer.Length); | ||
116 | output.Close(); | ||
117 | } | ||
118 | catch (Exception e) | ||
119 | { | ||
120 | Console.WriteLine(e.ToString()); | ||
121 | } | ||
122 | } | ||
123 | |||
124 | } | ||
125 | } | ||