1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Framework
.Adapters
20 using Castle
.MonoRail
.Framework
;
26 /// Adapts the <see cref="IResponse"/> to
27 /// an <see cref="HttpResponse"/> instance.
29 public class ResponseAdapter
: BaseResponse
31 private readonly HttpResponse response
;
34 /// Initializes a new instance of the <see cref="ResponseAdapter"/> class.
36 /// <param name="currentUrl">The current URL.</param>
37 /// <param name="urlBuilder">The URL builder.</param>
38 /// <param name="serverUtility">The server utility.</param>
39 /// <param name="routeMatch">The route match.</param>
40 /// <param name="response">The response.</param>
41 public ResponseAdapter(HttpResponse response
, UrlInfo currentUrl
,
42 IUrlBuilder urlBuilder
, IServerUtility serverUtility
,
43 RouteMatch routeMatch
) : base(currentUrl
, urlBuilder
, serverUtility
, routeMatch
)
45 this.response
= response
;
49 /// Gets the caching policy (expiration time, privacy,
50 /// vary clauses) of a Web page.
52 public override HttpCachePolicy CachePolicy
54 get { return response.Cache; }
55 set { throw new NotImplementedException(); }
59 /// Sets the Cache-Control HTTP header to Public or Private.
61 public override string CacheControlHeader
63 get { return response.CacheControl; }
64 set { response.CacheControl = value; }
68 /// Gets or sets the HTTP character set of the output stream.
70 public override string Charset
72 get { return response.Charset; }
73 set { response.Charset = value; }
77 /// Gets or sets the status code.
79 /// <value>The status code.</value>
80 public override int StatusCode
82 get { return response.StatusCode; }
83 set { response.StatusCode = value; }
87 /// Gets or sets the status code.
89 /// <value>The status code.</value>
90 public override string StatusDescription
92 get { return response.StatusDescription; }
93 set { response.StatusDescription = value; }
97 /// Gets or sets the content type.
99 /// <value>The type of the content.</value>
100 public override string ContentType
102 get { return response.ContentType; }
103 set { response.ContentType = value; }
107 /// Appends the header.
109 /// <param name="name">The name.</param>
110 /// <param name="headerValue">The header value.</param>
111 public override void AppendHeader(string name
, string headerValue
)
113 response
.AppendHeader(name
, headerValue
);
119 /// <value>The output.</value>
120 public override TextWriter Output
122 get { return response.Output; }
123 set { throw new NotImplementedException(); }
127 /// Gets the output stream.
129 /// <value>The output stream.</value>
130 public override Stream OutputStream
132 get { return response.OutputStream; }
136 /// Writes the buffer to the browser
138 /// <param name="buffer">The buffer.</param>
139 public override void BinaryWrite(byte[] buffer
)
141 response
.BinaryWrite(buffer
);
145 /// Writes the stream to the browser
147 /// <param name="stream">The stream.</param>
148 public override void BinaryWrite(Stream stream
)
150 byte[] buffer
= new byte[stream
.Length
];
152 stream
.Read(buffer
, 0, buffer
.Length
);
158 /// Clears the response (only works if buffered)
160 public override void Clear()
166 /// Clears the response content (only works if buffered).
168 public override void ClearContent()
170 response
.ClearContent();
174 /// Writes the specified string.
176 /// <param name="s">The string.</param>
177 public override void Write(string s
)
183 /// Writes the specified obj.
185 /// <param name="obj">The obj.</param>
186 public override void Write(object obj
)
192 /// Writes the specified char.
194 /// <param name="ch">The char.</param>
195 public override void Write(char ch
)
201 /// Writes the specified buffer.
203 /// <param name="buffer">The buffer.</param>
204 /// <param name="index">The index.</param>
205 /// <param name="count">The count.</param>
206 public override void Write(char[] buffer
, int index
, int count
)
208 response
.Write(buffer
, index
, count
);
214 /// <param name="fileName">Name of the file.</param>
215 public override void WriteFile(string fileName
)
217 response
.WriteFile(fileName
);
221 /// Gets a value indicating whether this instance is client connected.
224 /// <c>true</c> if this instance is client connected; otherwise, <c>false</c>.
226 public override bool IsClientConnected
228 get { return response.IsClientConnected; }
232 /// Gets a value indicating whether the response sent a redirect.
234 /// <value><c>true</c> if was redirected; otherwise, <c>false</c>.</value>
235 public override bool WasRedirected
237 get { return redirected; }
241 /// Redirects to the specified url
243 /// <param name="url">An relative or absolute URL to redirect the client to</param>
244 /// <param name="endProcess">if set to <c>true</c>, sends the redirect and
245 /// kills the current request process.</param>
246 public override void RedirectToUrl(string url
, bool endProcess
)
249 response
.Redirect(url
, endProcess
);
253 /// Creates the cookie.
255 /// <param name="cookie">The cookie.</param>
256 public override void CreateCookie(HttpCookie cookie
)
258 response
.Cookies
.Add(cookie
);