aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs
diff options
context:
space:
mode:
authorMelanie Thielker2009-05-04 20:19:21 +0000
committerMelanie Thielker2009-05-04 20:19:21 +0000
commitec0d2c28fa04102ecbad4c5660efecbb970201dd (patch)
tree388b41af36604b63a9cc3cd28b12b924fbd1f0e8 /OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs
parentIntermediate commit. WILL NOT COMPILE! (diff)
downloadopensim-SC_OLD-ec0d2c28fa04102ecbad4c5660efecbb970201dd.zip
opensim-SC_OLD-ec0d2c28fa04102ecbad4c5660efecbb970201dd.tar.gz
opensim-SC_OLD-ec0d2c28fa04102ecbad4c5660efecbb970201dd.tar.bz2
opensim-SC_OLD-ec0d2c28fa04102ecbad4c5660efecbb970201dd.tar.xz
Committing the changed tree
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs302
1 files changed, 302 insertions, 0 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs
new file mode 100644
index 0000000..210d122
--- /dev/null
+++ b/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs
@@ -0,0 +1,302 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.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
28using System.IO;
29using System.Net;
30using System.Text;
31using HttpServer;
32
33namespace OpenSim.Framework.Servers.HttpServer
34{
35 /// <summary>
36 /// OSHttpResponse is the OpenSim representation of an HTTP
37 /// response.
38 /// </summary>
39 public class OSHttpResponse
40 {
41 /// <summary>
42 /// Content type property.
43 /// </summary>
44 /// <remarks>
45 /// Setting this property will also set IsContentTypeSet to
46 /// true.
47 /// </remarks>
48 public string ContentType
49 {
50 get
51 {
52 return _httpResponse.ContentType;
53 }
54
55 set
56 {
57 _httpResponse.ContentType = value;
58 }
59 }
60
61 /// <summary>
62 /// Boolean property indicating whether the content type
63 /// property actively has been set.
64 /// </summary>
65 /// <remarks>
66 /// IsContentTypeSet will go away together with .NET base.
67 /// </remarks>
68 // public bool IsContentTypeSet
69 // {
70 // get { return _contentTypeSet; }
71 // }
72 // private bool _contentTypeSet;
73
74
75 /// <summary>
76 /// Length of the body content; 0 if there is no body.
77 /// </summary>
78 public long ContentLength
79 {
80 get
81 {
82 return _httpResponse.ContentLength;
83 }
84
85 set
86 {
87 _httpResponse.ContentLength = value;
88 }
89 }
90
91 /// <summary>
92 /// Alias for ContentLength.
93 /// </summary>
94 public long ContentLength64
95 {
96 get { return ContentLength; }
97 set { ContentLength = value; }
98 }
99
100 /// <summary>
101 /// Encoding of the body content.
102 /// </summary>
103 public Encoding ContentEncoding
104 {
105 get
106 {
107 return _httpResponse.Encoding;
108 }
109
110 set
111 {
112 _httpResponse.Encoding = value;
113 }
114 }
115
116 public bool KeepAlive
117 {
118 get
119 {
120 return _httpResponse.Connection == ConnectionType.KeepAlive;
121 }
122
123 set
124 {
125 if (value)
126 _httpResponse.Connection = ConnectionType.KeepAlive;
127 else
128 _httpResponse.Connection = ConnectionType.Close;
129 }
130 }
131
132 /// <summary>
133 /// Get or set the keep alive timeout property (default is
134 /// 20). Setting this to 0 also disables KeepAlive. Setting
135 /// this to something else but 0 also enable KeepAlive.
136 /// </summary>
137 public int KeepAliveTimeout
138 {
139 get
140 {
141 return _httpResponse.KeepAlive;
142 }
143
144 set
145 {
146 if (value == 0)
147 {
148 _httpResponse.Connection = ConnectionType.Close;
149 _httpResponse.KeepAlive = 0;
150 }
151 else
152 {
153 _httpResponse.Connection = ConnectionType.KeepAlive;
154 _httpResponse.KeepAlive = value;
155 }
156 }
157 }
158
159 /// <summary>
160 /// Return the output stream feeding the body.
161 /// </summary>
162 /// <remarks>
163 /// On its way out...
164 /// </remarks>
165 public Stream OutputStream
166 {
167 get
168 {
169 return _httpResponse.Body;
170 }
171 }
172
173 public string ProtocolVersion
174 {
175 get
176 {
177 return _httpResponse.ProtocolVersion;
178 }
179
180 set
181 {
182 _httpResponse.ProtocolVersion = value;
183 }
184 }
185
186 /// <summary>
187 /// Return the output stream feeding the body.
188 /// </summary>
189 public Stream Body
190 {
191 get
192 {
193 return _httpResponse.Body;
194 }
195 }
196
197 /// <summary>
198 /// Set a redirct location.
199 /// </summary>
200 public string RedirectLocation
201 {
202 // get { return _redirectLocation; }
203 set
204 {
205 _httpResponse.Redirect(value);
206 }
207 }
208
209
210 /// <summary>
211 /// Chunk transfers.
212 /// </summary>
213 public bool SendChunked
214 {
215 get
216 {
217 return _httpResponse.Chunked;
218 }
219
220 set
221 {
222 _httpResponse.Chunked = value;
223 }
224 }
225
226 /// <summary>
227 /// HTTP status code.
228 /// </summary>
229 public int StatusCode
230 {
231 get
232 {
233 return (int)_httpResponse.Status;
234 }
235
236 set
237 {
238 _httpResponse.Status = (HttpStatusCode)value;
239 }
240 }
241
242
243 /// <summary>
244 /// HTTP status description.
245 /// </summary>
246 public string StatusDescription
247 {
248 get
249 {
250 return _httpResponse.Reason;
251 }
252
253 set
254 {
255 _httpResponse.Reason = value;
256 }
257 }
258
259
260 protected IHttpResponse _httpResponse;
261
262 public OSHttpResponse() {}
263
264 public OSHttpResponse(IHttpResponse resp)
265 {
266 _httpResponse = resp;
267 }
268
269 /// <summary>
270 /// Instantiate an OSHttpResponse object from an OSHttpRequest
271 /// object.
272 /// </summary
273 /// <param name="req">Incoming OSHttpRequest to which we are
274 /// replying</param>
275 public OSHttpResponse(OSHttpRequest req)
276 {
277 _httpResponse = new HttpResponse(req.IHttpClientContext, req.IHttpRequest);
278 }
279
280 /// <summary>
281 /// Add a header field and content to the response.
282 /// </summary>
283 /// <param name="key">string containing the header field
284 /// name</param>
285 /// <param name="value">string containing the header field
286 /// value</param>
287 public void AddHeader(string key, string value)
288 {
289 _httpResponse.AddHeader(key, value);
290 }
291
292 /// <summary>
293 /// Send the response back to the remote client
294 /// </summary>
295 public void Send()
296 {
297 _httpResponse.Body.Flush();
298 _httpResponse.Send();
299
300 }
301 }
302}