Minor style changes
[castle.git] / MonoRail / Castle.MonoRail.Framework / Adapters / RequestAdapter.cs
blob80f772aa8132d9c443c8f566233775296452cff6
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 using System;
18 using System.Collections;
19 using System.Collections.Specialized;
20 using System.Web;
22 /// <summary>
23 /// This class adapts the <c>HttpRequest</c> to a MonoRail <c>IRequest</c>.
24 /// </summary>
25 public class RequestAdapter : IRequest
27 private HttpRequest request;
28 private FileDictionaryAdapter files;
30 /// <summary>
31 /// Initializes a new instance of the <see cref="RequestAdapter"/> class.
32 /// </summary>
33 /// <param name="request">The request.</param>
34 public RequestAdapter(HttpRequest request)
36 this.request = request;
39 /// <summary>
40 /// Gets the Http headers.
41 /// </summary>
42 /// <value>The Http headers.</value>
43 public NameValueCollection Headers
45 get { return request.Headers; }
48 /// <summary>
49 /// Gets a value indicating whether this requeest is from a local address.
50 /// </summary>
51 /// <value><c>true</c> if this instance is local; otherwise, <c>false</c>.</value>
52 public bool IsLocal
54 get { return request.Url.IsLoopback; }
57 /// <summary>
58 /// Gets the HTTP method.
59 /// </summary>
60 /// <value>The HTTP method.</value>
61 public string HttpMethod
63 get { return request.HttpMethod; }
66 /// <summary>
67 /// Gets the URI.
68 /// </summary>
69 /// <value>The URI.</value>
70 public Uri Uri
72 get { return request.Url; }
75 /// <summary>
76 /// Gets additional path information for
77 /// a resource with a URL extension.
78 /// </summary>
79 /// <value>The path info.</value>
80 public String PathInfo
82 get { return request.PathInfo; }
85 /// <summary>
86 /// Gets the raw URL.
87 /// </summary>
88 /// <value>The raw URL.</value>
89 public String RawUrl
91 get { return request.RawUrl; }
94 /// <summary>
95 /// Gets the file path.
96 /// </summary>
97 /// <value>The file path.</value>
98 public String FilePath
100 get { return request.FilePath; }
103 /// <summary>
104 /// Gets the query string.
105 /// </summary>
106 /// <value>The query string.</value>
107 public NameValueCollection QueryString
109 get { return request.QueryString; }
112 /// <summary>
113 /// Gets the form.
114 /// </summary>
115 /// <value>The form.</value>
116 public NameValueCollection Form
118 get { return request.Form; }
121 /// <summary>
122 /// Reads the request data as a byte array.
123 /// </summary>
124 /// <param name="count">How many bytes.</param>
125 /// <returns></returns>
126 public byte[] BinaryRead(int count)
128 return request.BinaryRead(count);
131 /// <summary>
132 /// Gets the param with the specified key.
133 /// </summary>
134 /// <value></value>
135 public String this[String key]
137 get { return request[key]; }
140 /// <summary>
141 /// Gets the <see cref="HttpPostedFile"/> per key.
142 /// </summary>
143 /// <value></value>
144 public IDictionary Files
148 if (files == null)
150 files = new FileDictionaryAdapter(request.Files);
152 return files;
156 /// <summary>
157 /// Gets the params which accumulates headers, post, querystring and cookies.
158 /// </summary>
159 /// <value>The params.</value>
160 public NameValueCollection Params
162 get { return request.Params; }
165 /// <summary>
166 /// Gets the user languages.
167 /// </summary>
168 /// <value>The user languages.</value>
169 public String[] UserLanguages
171 get { return request.UserLanguages; }
174 /// <summary>
175 /// Gets the IP host address of the remote client.
176 /// </summary>
177 /// <value>The IP address of the remote client.</value>
178 public string UserHostAddress
180 get { return request.UserHostAddress; }
183 /// <summary>
184 /// Reads the cookie.
185 /// </summary>
186 /// <param name="name">The cookie name.</param>
187 /// <returns></returns>
188 public String ReadCookie(String name)
190 HttpCookie cookie = request.Cookies[name];
191 if (cookie == null)
193 return null;
195 return cookie.Value;
198 /// <summary>
199 /// Validates the input.
200 /// </summary>
201 public void ValidateInput()
203 request.ValidateInput();