HttpRequestStream.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. namespace SocketHttpListener.Net
  8. {
  9. // Licensed to the .NET Foundation under one or more agreements.
  10. // See the LICENSE file in the project root for more information.
  11. //
  12. // System.Net.ResponseStream
  13. //
  14. // Author:
  15. // Gonzalo Paniagua Javier (gonzalo@novell.com)
  16. //
  17. // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
  18. //
  19. // Permission is hereby granted, free of charge, to any person obtaining
  20. // a copy of this software and associated documentation files (the
  21. // "Software"), to deal in the Software without restriction, including
  22. // without limitation the rights to use, copy, modify, merge, publish,
  23. // distribute, sublicense, and/or sell copies of the Software, and to
  24. // permit persons to whom the Software is furnished to do so, subject to
  25. // the following conditions:
  26. //
  27. // The above copyright notice and this permission notice shall be
  28. // included in all copies or substantial portions of the Software.
  29. //
  30. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  31. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  32. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  33. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  34. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  35. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  36. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  37. //
  38. internal partial class HttpRequestStream : Stream
  39. {
  40. public override bool CanSeek => false;
  41. public override bool CanWrite => false;
  42. public override bool CanRead => true;
  43. public override int Read(byte[] buffer, int offset, int size)
  44. {
  45. if (buffer == null)
  46. {
  47. throw new ArgumentNullException(nameof(buffer));
  48. }
  49. if (offset < 0 || offset > buffer.Length)
  50. {
  51. throw new ArgumentOutOfRangeException(nameof(offset));
  52. }
  53. if (size < 0 || size > buffer.Length - offset)
  54. {
  55. throw new ArgumentOutOfRangeException(nameof(size));
  56. }
  57. if (size == 0 || _closed)
  58. {
  59. return 0;
  60. }
  61. return ReadCore(buffer, offset, size);
  62. }
  63. public override IAsyncResult BeginRead(byte[] buffer, int offset, int size, AsyncCallback callback, object state)
  64. {
  65. if (buffer == null)
  66. {
  67. throw new ArgumentNullException(nameof(buffer));
  68. }
  69. if (offset < 0 || offset > buffer.Length)
  70. {
  71. throw new ArgumentOutOfRangeException(nameof(offset));
  72. }
  73. if (size < 0 || size > buffer.Length - offset)
  74. {
  75. throw new ArgumentOutOfRangeException(nameof(size));
  76. }
  77. return BeginReadCore(buffer, offset, size, callback, state);
  78. }
  79. public override void Flush() { }
  80. public override Task FlushAsync(CancellationToken cancellationToken) => Task.CompletedTask;
  81. public override long Length
  82. {
  83. get
  84. {
  85. throw new NotImplementedException();
  86. }
  87. }
  88. public override long Position
  89. {
  90. get
  91. {
  92. throw new NotImplementedException();
  93. }
  94. set
  95. {
  96. throw new NotImplementedException();
  97. }
  98. }
  99. public override long Seek(long offset, SeekOrigin origin)
  100. {
  101. throw new NotImplementedException();
  102. }
  103. public override void SetLength(long value)
  104. {
  105. throw new NotImplementedException();
  106. }
  107. public override void Write(byte[] buffer, int offset, int count)
  108. {
  109. throw new NotImplementedException();
  110. }
  111. public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
  112. {
  113. return base.BeginWrite(buffer, offset, count, callback, state);
  114. }
  115. public override void EndWrite(IAsyncResult asyncResult)
  116. {
  117. base.EndWrite(asyncResult);
  118. }
  119. internal bool Closed => _closed;
  120. protected override void Dispose(bool disposing)
  121. {
  122. _closed = true;
  123. base.Dispose(disposing);
  124. }
  125. }
  126. }