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="response">The response.</param>
37 /// <param name="currentUrl">The current URL.</param>
38 /// <param name="urlBuilder">The URL builder.</param>
39 /// <param name="serverUtility">The server utility.</param>
40 /// <param name="routeMatch">The route match.</param>
41 /// <param name="referrer">The referrer.</param>
42 public ResponseAdapter(HttpResponse response
, UrlInfo currentUrl
,
43 IUrlBuilder urlBuilder
, IServerUtility serverUtility
,
44 RouteMatch routeMatch
, string referrer
)
45 : base(currentUrl
, urlBuilder
, serverUtility
, routeMatch
, referrer
)
47 this.response
= response
;
51 /// Gets the caching policy (expiration time, privacy,
52 /// vary clauses) of a Web page.
54 public override HttpCachePolicy CachePolicy
56 get { return response.Cache; }
57 set { throw new NotImplementedException(); }
61 /// Sets the Cache-Control HTTP header to Public or Private.
63 public override string CacheControlHeader
65 get { return response.CacheControl; }
66 set { response.CacheControl = value; }
70 /// Gets or sets the HTTP character set of the output stream.
72 public override string Charset
74 get { return response.Charset; }
75 set { response.Charset = value; }
79 /// Gets or sets the status code.
81 /// <value>The status code.</value>
82 public override int StatusCode
84 get { return response.StatusCode; }
85 set { response.StatusCode = value; }
89 /// Gets or sets the status code.
91 /// <value>The status code.</value>
92 public override string StatusDescription
94 get { return response.StatusDescription; }
95 set { response.StatusDescription = value; }
99 /// Gets or sets the content type.
101 /// <value>The type of the content.</value>
102 public override string ContentType
104 get { return response.ContentType; }
105 set { response.ContentType = value; }
109 /// Appends the header.
111 /// <param name="name">The name.</param>
112 /// <param name="headerValue">The header value.</param>
113 public override void AppendHeader(string name
, string headerValue
)
115 response
.AppendHeader(name
, headerValue
);
121 /// <value>The output.</value>
122 public override TextWriter Output
124 get { return response.Output; }
125 set { throw new NotImplementedException(); }
129 /// Gets the output stream.
131 /// <value>The output stream.</value>
132 public override Stream OutputStream
134 get { return response.OutputStream; }
138 /// Writes the buffer to the browser
140 /// <param name="buffer">The buffer.</param>
141 public override void BinaryWrite(byte[] buffer
)
143 response
.BinaryWrite(buffer
);
147 /// Writes the stream to the browser
149 /// <param name="stream">The stream.</param>
150 public override void BinaryWrite(Stream stream
)
152 byte[] buffer
= new byte[stream
.Length
];
154 stream
.Read(buffer
, 0, buffer
.Length
);
160 /// Clears the response (only works if buffered)
162 public override void Clear()
168 /// Clears the response content (only works if buffered).
170 public override void ClearContent()
172 response
.ClearContent();
176 /// Writes the specified string.
178 /// <param name="s">The string.</param>
179 public override void Write(string s
)
185 /// Writes the specified obj.
187 /// <param name="obj">The obj.</param>
188 public override void Write(object obj
)
194 /// Writes the specified char.
196 /// <param name="ch">The char.</param>
197 public override void Write(char ch
)
203 /// Writes the specified buffer.
205 /// <param name="buffer">The buffer.</param>
206 /// <param name="index">The index.</param>
207 /// <param name="count">The count.</param>
208 public override void Write(char[] buffer
, int index
, int count
)
210 response
.Write(buffer
, index
, count
);
216 /// <param name="fileName">Name of the file.</param>
217 public override void WriteFile(string fileName
)
219 response
.WriteFile(fileName
);
223 /// Gets a value indicating whether this instance is client connected.
226 /// <c>true</c> if this instance is client connected; otherwise, <c>false</c>.
228 public override bool IsClientConnected
230 get { return response.IsClientConnected; }
234 /// Gets a value indicating whether the response sent a redirect.
236 /// <value><c>true</c> if was redirected; otherwise, <c>false</c>.</value>
237 public override bool WasRedirected
239 get { return redirected; }
243 /// Redirects to the specified url
245 /// <param name="url">An relative or absolute URL to redirect the client to</param>
246 /// <param name="endProcess">if set to <c>true</c>, sends the redirect and
247 /// kills the current request process.</param>
248 public override void RedirectToUrl(string url
, bool endProcess
)
251 response
.Redirect(url
, endProcess
);
255 /// Creates the cookie.
257 /// <param name="cookie">The cookie.</param>
258 public override void CreateCookie(HttpCookie cookie
)
260 response
.Cookies
.Add(cookie
);