OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
TestHttpResponse.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;
29 using System.IO;
30 using System.Net;
31 using System.Text;
32 using HttpServer;
33 
34 namespace OpenSim.Tests.Common
35 {
36  public class TestHttpResponse: IHttpResponse
37  {
38  public Stream Body
39  {
40  get { return _body; }
41 
42  set { _body = value; }
43  }
44  private Stream _body;
45 
46  public string ProtocolVersion
47  {
48  get { return _protocolVersion; }
49  set { _protocolVersion = value; }
50  }
51  private string _protocolVersion;
52 
53  public bool Chunked
54  {
55  get { return _chunked; }
56 
57  set { _chunked = value; }
58  }
59  private bool _chunked;
60 
61  public ConnectionType Connection
62  {
63  get { return _connection; }
64 
65  set { _connection = value; }
66  }
67  private ConnectionType _connection;
68 
69  public Encoding Encoding
70  {
71  get { return _encoding; }
72 
73  set { _encoding = value; }
74  }
75  private Encoding _encoding;
76 
77  public int KeepAlive
78  {
79  get { return _keepAlive; }
80 
81  set { _keepAlive = value; }
82  }
83  private int _keepAlive;
84 
85  public HttpStatusCode Status
86  {
87  get { return _status; }
88 
89  set { _status = value; }
90  }
91  private HttpStatusCode _status;
92 
93  public string Reason
94  {
95  get { return _reason; }
96 
97  set { _reason = value; }
98  }
99  private string _reason;
100 
101  public long ContentLength
102  {
103  get { return _contentLength; }
104 
105  set { _contentLength = value; }
106  }
107  private long _contentLength;
108 
109  public string ContentType
110  {
111  get { return _contentType; }
112 
113  set { _contentType = value; }
114  }
115  private string _contentType;
116 
117  public bool HeadersSent
118  {
119  get { return _headersSent; }
120  }
121  private bool _headersSent;
122 
123  public bool Sent
124  {
125  get { return _sent; }
126  }
127  private bool _sent;
128 
129  public ResponseCookies Cookies
130  {
131  get { return _cookies; }
132  }
133  private ResponseCookies _cookies = null;
134 
136  {
137  _headersSent = false;
138  _sent = false;
139  }
140 
141  public void AddHeader(string name, string value) {}
142 
143  public void Send()
144  {
145  if (!_headersSent) SendHeaders();
146  if (_sent) throw new InvalidOperationException("stuff already sent");
147  _sent = true;
148  }
149 
150  public void SendBody(byte[] buffer, int offset, int count)
151  {
152  if (!_headersSent) SendHeaders();
153  _sent = true;
154  }
155 
156  public void SendBody(byte[] buffer)
157  {
158  if (!_headersSent) SendHeaders();
159  _sent = true;
160  }
161 
162  public void SendHeaders()
163  {
164  if (_headersSent) throw new InvalidOperationException("headers already sent");
165  _headersSent = true;
166  }
167 
168  public void Redirect(Uri uri) {}
169  public void Redirect(string url) {}
170  }
171 }
void AddHeader(string name, string value)
void SendBody(byte[] buffer, int offset, int count)