OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
OSHttpResponse.cs
Go to the documentation of this file.
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 OpenSimulator 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.IO;
29 using System.Net;
30 using System.Text;
31 using HttpServer;
32 
33 namespace OpenSim.Framework.Servers.HttpServer
34 {
40  {
48  public virtual string ContentType
49  {
50  get
51  {
52  return _httpResponse.ContentType;
53  }
54 
55  set
56  {
57  _httpResponse.ContentType = value;
58  }
59  }
60 
68  // public bool IsContentTypeSet
69  // {
70  // get { return _contentTypeSet; }
71  // }
72  // private bool _contentTypeSet;
73 
74 
78  public long ContentLength
79  {
80  get
81  {
82  return _httpResponse.ContentLength;
83  }
84 
85  set
86  {
87  _httpResponse.ContentLength = value;
88  }
89  }
90 
94  public long ContentLength64
95  {
96  get { return ContentLength; }
97  set { ContentLength = value; }
98  }
99 
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 
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 
152  else
153  {
154  _httpResponse.Connection = ConnectionType.KeepAlive;
155  _httpResponse.KeepAlive = value;
156  }
157  }
158  }
159 
166  public Stream OutputStream
167  {
168  get
169  {
170  return _httpResponse.Body;
171  }
172  }
173 
174  public string ProtocolVersion
175  {
176  get
177  {
178  return _httpResponse.ProtocolVersion;
179  }
180 
181  set
182  {
183  _httpResponse.ProtocolVersion = value;
184  }
185  }
186 
190  public Stream Body
191  {
192  get
193  {
194  return _httpResponse.Body;
195  }
196  }
197 
201  public string RedirectLocation
202  {
203  // get { return _redirectLocation; }
204  set
205  {
206  _httpResponse.Redirect(value);
207  }
208  }
209 
210 
214  public bool SendChunked
215  {
216  get
217  {
218  return _httpResponse.Chunked;
219  }
220 
221  set
222  {
223  _httpResponse.Chunked = value;
224  }
225  }
226 
230  public virtual int StatusCode
231  {
232  get
233  {
234  return (int)_httpResponse.Status;
235  }
236 
237  set
238  {
239  _httpResponse.Status = (HttpStatusCode)value;
240  }
241  }
242 
243 
247  public string StatusDescription
248  {
249  get
250  {
251  return _httpResponse.Reason;
252  }
253 
254  set
255  {
256  _httpResponse.Reason = value;
257  }
258  }
259 
260  public bool ReuseContext
261  {
262  get
263  {
264  if (_httpClientContext != null)
265  {
266  return !_httpClientContext.EndWhenDone;
267  }
268  return true;
269  }
270  set
271  {
272  if (_httpClientContext != null)
273  {
274  _httpClientContext.EndWhenDone = !value;
275  }
276  }
277  }
278 
279  protected IHttpResponse _httpResponse;
280  private IHttpClientContext _httpClientContext;
281 
282  public OSHttpResponse() {}
283 
284  public OSHttpResponse(IHttpResponse resp)
285  {
286  _httpResponse = resp;
287  }
288 
296  {
297  _httpResponse = new HttpResponse(req.IHttpClientContext, req.IHttpRequest);
298  _httpClientContext = req.IHttpClientContext;
299  }
300  public OSHttpResponse(HttpResponse resp, IHttpClientContext clientContext)
301  {
302  _httpResponse = resp;
303  _httpClientContext = clientContext;
304  }
305 
313  public void AddHeader(string key, string value)
314  {
315  _httpResponse.AddHeader(key, value);
316  }
317 
321  public void Send()
322  {
323  _httpResponse.Body.Flush();
324 
325  // disable this till they are safe to use
326  _httpResponse.Connection = ConnectionType.Close;
327  _httpResponse.Chunked = false;
328 
329  _httpResponse.Send();
330  }
331 
332  public void FreeContext()
333  {
334  if (_httpClientContext != null)
335  _httpClientContext.Close();
336  }
337  }
338 }
OSHttpResponse is the OpenSim representation of an HTTP response.
OSHttpResponse(OSHttpRequest req)
Instantiate an OSHttpResponse object from an OSHttpRequest object. </summary Incoming OSHttpRequest t...
OSHttpResponse(HttpResponse resp, IHttpClientContext clientContext)
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString key
Definition: ICM_Api.cs:31
void AddHeader(string key, string value)
Add a header field and content to the response.
void Send()
Send the response back to the remote client