ClientHttpWebResponse.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. using System;
  14. using System.Diagnostics;
  15. using System.Globalization;
  16. using System.IO;
  17. internal sealed class ClientHttpWebResponse : System.Data.Services.Http.HttpWebResponse
  18. {
  19. private System.Net.HttpWebResponse innerResponse;
  20. private ClientWebHeaderCollection headerCollection;
  21. private ClientHttpWebRequest request;
  22. internal ClientHttpWebResponse(System.Net.HttpWebResponse innerResponse, ClientHttpWebRequest request)
  23. {
  24. Debug.Assert(innerResponse != null, "innerResponse can't be null.");
  25. this.innerResponse = innerResponse;
  26. this.request = request;
  27. int statusCode = (int)this.innerResponse.StatusCode;
  28. if (statusCode > (int)HttpStatusCodeRange.MaxValue || statusCode < (int)HttpStatusCodeRange.MinValue)
  29. {
  30. throw WebException.CreateInternal("HttpWebResponse.NormalizeResponseStatus");
  31. }
  32. }
  33. #region Properties.
  34. public override long ContentLength
  35. {
  36. get
  37. {
  38. return this.innerResponse.ContentLength;
  39. }
  40. }
  41. public override string ContentType
  42. {
  43. get
  44. {
  45. return this.innerResponse.ContentType;
  46. }
  47. }
  48. public override System.Data.Services.Http.WebHeaderCollection Headers
  49. {
  50. get
  51. {
  52. if (this.headerCollection == null)
  53. {
  54. this.headerCollection = new ClientWebHeaderCollection(this.innerResponse.Headers);
  55. }
  56. return this.headerCollection;
  57. }
  58. }
  59. public override System.Data.Services.Http.HttpWebRequest Request
  60. {
  61. get
  62. {
  63. return this.request;
  64. }
  65. }
  66. public override System.Data.Services.Http.HttpStatusCode StatusCode
  67. {
  68. get
  69. {
  70. return (System.Data.Services.Http.HttpStatusCode)(int)this.innerResponse.StatusCode;
  71. }
  72. }
  73. #endregion Properties.
  74. public override void Close()
  75. {
  76. this.innerResponse.Close();
  77. }
  78. public override string GetResponseHeader(string headerName)
  79. {
  80. return this.innerResponse.Headers[headerName];
  81. }
  82. public override Stream GetResponseStream()
  83. {
  84. return this.innerResponse.GetResponseStream();
  85. }
  86. protected override void Dispose(bool disposing)
  87. {
  88. ((IDisposable)this.innerResponse).Dispose();
  89. }
  90. }
  91. }