IHttpRequest.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using System;
  2. using System.Collections.Specialized;
  3. using System.IO;
  4. using OSHttpServer.Exceptions;
  5. namespace OSHttpServer
  6. {
  7. /// <summary>
  8. /// Contains server side HTTP request information.
  9. /// </summary>
  10. public interface IHttpRequest : ICloneable
  11. {
  12. /// <summary>
  13. /// Gets kind of types accepted by the client.
  14. /// </summary>
  15. string[] AcceptTypes { get; }
  16. uint ID {get; }
  17. /// <summary>
  18. /// Gets or sets body stream.
  19. /// </summary>
  20. Stream Body { get; set; }
  21. /// <summary>
  22. /// Gets whether the body is complete.
  23. /// </summary>
  24. bool BodyIsComplete { get; }
  25. /// <summary>
  26. /// Gets or sets kind of connection used for the session.
  27. /// </summary>
  28. ConnectionType Connection { get; set; }
  29. IHttpClientContext Context { get; }
  30. /// <summary>
  31. /// Gets or sets number of bytes in the body.
  32. /// </summary>
  33. int ContentLength { get; set; }
  34. /// <summary>
  35. /// Gets cookies that was sent with the request.
  36. /// </summary>
  37. RequestCookies Cookies { get; }
  38. /// <summary>
  39. /// Gets form parameters.
  40. /// </summary>
  41. //HttpForm Form { get; }
  42. /// <summary>
  43. /// Gets headers sent by the client.
  44. /// </summary>
  45. NameValueCollection Headers { get; }
  46. /// <summary>
  47. /// Gets or sets version of HTTP protocol that's used.
  48. /// </summary>
  49. /// <remarks>
  50. /// Probably <see cref="HttpHelper.HTTP10"/> or <see cref="HttpHelper.HTTP11"/>.
  51. /// </remarks>
  52. /// <seealso cref="HttpHelper"/>
  53. string HttpVersion { get; set; }
  54. /// <summary>
  55. /// Gets whether the request was made by Ajax (Asynchronous JavaScript)
  56. /// </summary>
  57. bool IsAjax { get; }
  58. /// <summary>
  59. /// Gets or sets requested method.
  60. /// </summary>
  61. /// <remarks>
  62. /// Will always be in upper case.
  63. /// </remarks>
  64. /// <see cref="Method"/>
  65. string Method { get; set; }
  66. /// <summary>
  67. /// Gets parameter from <see cref="QueryString"/> or <see cref="Form"/>.
  68. /// </summary>
  69. HttpParam Param { get; }
  70. /// <summary>
  71. /// Gets variables sent in the query string
  72. /// </summary>
  73. HttpInput QueryString { get; }
  74. /// <summary>
  75. /// Gets or sets requested URI.
  76. /// </summary>
  77. Uri Uri { get; set; }
  78. /// <summary>
  79. /// Gets URI absolute path divided into parts.
  80. /// </summary>
  81. /// <example>
  82. /// // URI is: http://gauffin.com/code/tiny/
  83. /// Console.WriteLine(request.UriParts[0]); // result: code
  84. /// Console.WriteLine(request.UriParts[1]); // result: tiny
  85. /// </example>
  86. /// <remarks>
  87. /// If you're using controllers than the first part is controller name,
  88. /// the second part is method name and the third part is Id property.
  89. /// </remarks>
  90. /// <seealso cref="Uri"/>
  91. string[] UriParts { get; }
  92. /// <summary>
  93. /// Gets or sets path and query.
  94. /// </summary>
  95. /// <see cref="Uri"/>
  96. /// <remarks>
  97. /// Are only used during request parsing. Cannot be set after "Host" header have been
  98. /// added.
  99. /// </remarks>
  100. string UriPath { get; set; }
  101. /// <summary>
  102. /// Called during parsing of a <see cref="IHttpRequest"/>.
  103. /// </summary>
  104. /// <param name="name">Name of the header, should not be URL encoded</param>
  105. /// <param name="value">Value of the header, should not be URL encoded</param>
  106. /// <exception cref="BadRequestException">If a header is incorrect.</exception>
  107. void AddHeader(string name, string value);
  108. /// <summary>
  109. /// Add bytes to the body
  110. /// </summary>
  111. /// <param name="bytes">buffer to read bytes from</param>
  112. /// <param name="offset">where to start read</param>
  113. /// <param name="length">number of bytes to read</param>
  114. /// <returns>Number of bytes actually read (same as length unless we got all body bytes).</returns>
  115. /// <exception cref="InvalidOperationException">If body is not writable</exception>
  116. /// <exception cref="ArgumentNullException"><c>bytes</c> is null.</exception>
  117. /// <exception cref="ArgumentOutOfRangeException"><c>offset</c> is out of range.</exception>
  118. int AddToBody(byte[] bytes, int offset, int length);
  119. /// <summary>
  120. /// Clear everything in the request
  121. /// </summary>
  122. void Clear();
  123. /// <summary>
  124. /// Decode body into a form.
  125. /// </summary>
  126. /// <param name="providers">A list with form decoders.</param>
  127. /// <exception cref="InvalidDataException">If body contents is not valid for the chosen decoder.</exception>
  128. /// <exception cref="InvalidOperationException">If body is still being transferred.</exception>
  129. //void DecodeBody(FormDecoderProvider providers);
  130. /// <summary>
  131. /// Sets the cookies.
  132. /// </summary>
  133. /// <param name="cookies">The cookies.</param>
  134. void SetCookies(RequestCookies cookies);
  135. /// <summary>
  136. /// Create a response object.
  137. /// </summary>
  138. /// <param name="context">Context for the connected client.</param>
  139. /// <returns>A new <see cref="IHttpResponse"/>.</returns>
  140. //IHttpResponse CreateResponse(IHttpClientContext context);
  141. }
  142. }