Wed Feb 24 15:47:16 CET 2010 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / System.Net / System.Net / HttpWebRequest_2_1.cs
1 //
2 // System.Net.HttpWebRequest (for 2.1 profile)
3 //
4 // Authors:
5 //      Atsushi Enomoto  <atsushi@ximian.com>
6 //  Jb Evain  <jbevain@novell.com>
7 //
8 // Copyright (C) 2007, 2009-2010 Novell, Inc (http://www.novell.com)
9 //
10
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 #if NET_2_1
33
34 using System.IO;
35
36 namespace System.Net { 
37
38         // note: the NotImplementedException are needed to match MS implementation
39
40         // note: MS documents a lot of thing for this type but, in truth, all happens
41         // in a type that derive from HttpWebRequest. In Moonlight case this is either
42         // * BrowserHttpWebRequest (browser stack) located in System.Windows.Browser.dll; or
43         // * System.Net.Browser.ClientHttpWebRequest (client stack) located in System.Windows.dll
44
45         public abstract class HttpWebRequest : WebRequest {
46
47                 private WebHeaderCollection headers;
48
49                 protected HttpWebRequest ()
50                 {
51                 }
52
53                 public string Accept {
54                         get { return Headers [HttpRequestHeader.Accept]; }
55                         // this header cannot be set directly inside the collection (hence the helper)
56                         set {
57                                 if (value == null)
58                                         throw new ArgumentNullException ("Accept");
59                                 if (value.Length == 0)
60                                         throw new ArgumentException ("Accept");
61                                 Headers.SetHeader ("accept", value);
62                         }
63                 }
64
65                 public virtual bool AllowReadStreamBuffering {
66                         get { throw NotImplemented (); }
67                         set { throw NotImplemented (); }
68                 }
69
70                 public override string ContentType {
71                         get { return Headers [HttpRequestHeader.ContentType]; }
72                         // this header cannot be set directly inside the collection (hence the helper)
73                         set {
74                                 if (value == null)
75                                         throw new ArgumentNullException ("ContentType");
76                                 if (value.Length == 0)
77                                         throw new ArgumentException ("ContentType");
78                                 Headers.SetHeader ("content-type", value);
79                         }
80                 }
81
82                 public virtual bool HaveResponse {
83                         get { throw NotImplemented (); }
84                 }
85
86                 public override WebHeaderCollection Headers {
87                         get {
88                                 if (headers == null)
89                                         headers = new WebHeaderCollection (true);
90                                 return headers;
91                         }
92                         set {
93                                 // note: this is not a field assignment but a copy (see unit tests)
94                                 // make sure everything we're supplied is valid...
95                                 string[] keys = value.AllKeys;
96                                 foreach (string header in keys) {
97                                         // anything bad will throw
98                                         WebHeaderCollection.ValidateHeader (header);
99                                 }
100                                 // ... before making those values our own
101                                 Headers.headers.Clear ();
102                                 foreach (string header in keys) {
103                                         headers [header] = value [header];
104                                 }
105                         }
106                 }
107
108                 public virtual CookieContainer CookieContainer {
109                         get { throw NotImplemented (); }
110                         set { throw NotImplemented (); }
111                 }
112
113                 public override string Method {
114                         get { throw NotImplemented (); }
115                         set { throw NotImplemented (); }
116                 }
117
118                 public override Uri RequestUri {
119                         get { throw NotImplemented (); }
120                 }
121
122
123                 public override void Abort ()
124                 {
125                         throw NotImplemented ();
126                 }
127
128                 public override IAsyncResult BeginGetRequestStream (AsyncCallback callback, object state)
129                 {
130                         throw NotImplemented ();
131                 }
132
133                 public override IAsyncResult BeginGetResponse (AsyncCallback callback, object state)
134                 {
135                         throw NotImplemented ();
136                 }
137
138                 public override Stream EndGetRequestStream (IAsyncResult asyncResult)
139                 {
140                         throw NotImplemented ();
141                 }
142
143                 public override WebResponse EndGetResponse (IAsyncResult asyncResult)
144                 {
145                         throw NotImplemented ();
146                 }
147
148                 static Exception NotImplemented ()
149                 {
150                         // a bit less IL and hide the "normal" NotImplementedException from corcompare-like tools
151                         return new NotImplementedException ();
152                 }
153         }
154 }
155
156 #endif
157