IHttpRequest.cs 4.7 KB

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