HttpRequestStream.cs 4.6 KB

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