ClientHttpWebRequest.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //Copyright 2010 Microsoft Corporation
  2. //
  3. //Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
  4. //You may obtain a copy of the License at
  5. //
  6. //http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. //Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
  9. //"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. //See the License for the specific language governing permissions and limitations under the License.
  11. namespace System.Data.Services.Http
  12. {
  13. #region Namespaces.
  14. using System;
  15. using System.Globalization;
  16. using System.IO;
  17. using System.Text;
  18. using System.Threading;
  19. using System.Windows.Browser;
  20. using System.Diagnostics;
  21. #endregion Namespaces.
  22. internal sealed class ClientHttpWebRequest : System.Data.Services.Http.HttpWebRequest
  23. {
  24. private readonly System.Net.HttpWebRequest innerRequest;
  25. private ClientWebHeaderCollection headerCollection;
  26. public ClientHttpWebRequest(Uri requestUri)
  27. {
  28. Debug.Assert(requestUri != null, "requestUri can't be null.");
  29. this.innerRequest = (System.Net.HttpWebRequest)System.Net.Browser.WebRequestCreator.ClientHttp.Create(requestUri);
  30. Debug.Assert(this.innerRequest != null, "ClientHttp.Create failed to create a new request without throwing exception.");
  31. }
  32. public override string Accept
  33. {
  34. get
  35. {
  36. return this.innerRequest.Accept;
  37. }
  38. set
  39. {
  40. this.innerRequest.Accept = value;
  41. }
  42. }
  43. public override long ContentLength
  44. {
  45. set
  46. {
  47. return;
  48. }
  49. }
  50. public override bool AllowReadStreamBuffering
  51. {
  52. get
  53. {
  54. return this.innerRequest.AllowReadStreamBuffering;
  55. }
  56. set
  57. {
  58. this.innerRequest.AllowReadStreamBuffering = value;
  59. }
  60. }
  61. public override string ContentType
  62. {
  63. get
  64. {
  65. return this.innerRequest.ContentType;
  66. }
  67. set
  68. {
  69. this.innerRequest.ContentType = value;
  70. }
  71. }
  72. public override System.Data.Services.Http.WebHeaderCollection Headers
  73. {
  74. get
  75. {
  76. if (this.headerCollection == null)
  77. {
  78. this.headerCollection = new ClientWebHeaderCollection(this.innerRequest.Headers, this.innerRequest);
  79. }
  80. return this.headerCollection;
  81. }
  82. }
  83. public override string Method
  84. {
  85. get
  86. {
  87. return this.innerRequest.Method;
  88. }
  89. set
  90. {
  91. this.innerRequest.Method = value;
  92. }
  93. }
  94. public override Uri RequestUri
  95. {
  96. get
  97. {
  98. return this.innerRequest.RequestUri;
  99. }
  100. }
  101. public override void Abort()
  102. {
  103. this.innerRequest.Abort();
  104. }
  105. public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state)
  106. {
  107. return this.innerRequest.BeginGetRequestStream(callback, state);
  108. }
  109. public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state)
  110. {
  111. return this.innerRequest.BeginGetResponse(callback, state);
  112. }
  113. public override Stream EndGetRequestStream(IAsyncResult asyncResult)
  114. {
  115. return this.innerRequest.EndGetRequestStream(asyncResult);
  116. }
  117. public override System.Data.Services.Http.WebResponse EndGetResponse(IAsyncResult asyncResult)
  118. {
  119. try
  120. {
  121. System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)this.innerRequest.EndGetResponse(asyncResult);
  122. return new ClientHttpWebResponse(response, this);
  123. }
  124. catch (System.Net.WebException exception)
  125. {
  126. ClientHttpWebResponse response = new ClientHttpWebResponse((System.Net.HttpWebResponse)exception.Response, this);
  127. throw new System.Data.Services.Http.WebException(exception.Message, exception, response);
  128. }
  129. }
  130. public override System.Net.WebHeaderCollection CreateEmptyWebHeaderCollection()
  131. {
  132. return new System.Net.WebHeaderCollection();
  133. }
  134. protected override void Dispose(bool disposing)
  135. {
  136. }
  137. }
  138. }