1 // Copyright 2004-2007 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
18 using System
.Collections
;
19 using System
.Collections
.Specialized
;
23 /// This class adapts the <c>HttpRequest</c> to a MonoRail <c>IRequest</c>.
25 public class RequestAdapter
: IRequest
27 private HttpRequest request
;
28 private FileDictionaryAdapter files
;
31 /// Initializes a new instance of the <see cref="RequestAdapter"/> class.
33 /// <param name="request">The request.</param>
34 public RequestAdapter(HttpRequest request
)
36 this.request
= request
;
40 /// Gets the Http headers.
42 /// <value>The Http headers.</value>
43 public NameValueCollection Headers
45 get { return request.Headers; }
49 /// Gets a value indicating whether this requeest is from a local address.
51 /// <value><c>true</c> if this instance is local; otherwise, <c>false</c>.</value>
54 get { return request.Url.IsLoopback; }
58 /// Gets the HTTP method.
60 /// <value>The HTTP method.</value>
61 public string HttpMethod
63 get { return request.HttpMethod; }
69 /// <value>The URI.</value>
72 get { return request.Url; }
76 /// Gets additional path information for
77 /// a resource with a URL extension.
79 /// <value>The path info.</value>
80 public String PathInfo
82 get { return request.PathInfo; }
88 /// <value>The raw URL.</value>
91 get { return request.RawUrl; }
95 /// Gets the file path.
97 /// <value>The file path.</value>
98 public String FilePath
100 get { return request.FilePath; }
104 /// Gets the query string.
106 /// <value>The query string.</value>
107 public NameValueCollection QueryString
109 get { return request.QueryString; }
115 /// <value>The form.</value>
116 public NameValueCollection Form
118 get { return request.Form; }
122 /// Reads the request data as a byte array.
124 /// <param name="count">How many bytes.</param>
125 /// <returns></returns>
126 public byte[] BinaryRead(int count
)
128 return request
.BinaryRead(count
);
132 /// Gets the param with the specified key.
135 public String
this[String key
]
137 get { return request[key]; }
141 /// Gets the <see cref="HttpPostedFile"/> per key.
144 public IDictionary Files
150 files
= new FileDictionaryAdapter(request
.Files
);
157 /// Gets the params which accumulates headers, post, querystring and cookies.
159 /// <value>The params.</value>
160 public NameValueCollection Params
162 get { return request.Params; }
166 /// Gets the user languages.
168 /// <value>The user languages.</value>
169 public String
[] UserLanguages
171 get { return request.UserLanguages; }
175 /// Gets the IP host address of the remote client.
177 /// <value>The IP address of the remote client.</value>
178 public string UserHostAddress
180 get { return request.UserHostAddress; }
184 /// Reads the cookie.
186 /// <param name="name">The cookie name.</param>
187 /// <returns></returns>
188 public String
ReadCookie(String name
)
190 HttpCookie cookie
= request
.Cookies
[name
];
199 /// Validates the input.
201 public void ValidateInput()
203 request
.ValidateInput();