IHttpRequest.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. /// <summary>
  64. /// Gets parameter from <see cref="QueryString"/> or <see cref="Form"/>.
  65. /// </summary>
  66. HttpParam Param { get; }
  67. /// <summary>
  68. /// Gets variables sent in the query string
  69. /// </summary>
  70. NameValueCollection QueryString { get; }
  71. /// <summary>
  72. /// Gets or sets requested URI.
  73. /// </summary>
  74. Uri Uri { get; set; }
  75. /// <summary>
  76. /// Gets or sets path and query.
  77. /// </summary>
  78. /// <see cref="Uri"/>
  79. /// <remarks>
  80. /// Are only used during request parsing. Cannot be set after "Host" header have been
  81. /// added.
  82. /// </remarks>
  83. string UriPath { get; set; }
  84. /// <summary>
  85. /// Called during parsing of a <see cref="IHttpRequest"/>.
  86. /// </summary>
  87. /// <param name="name">Name of the header, should not be URL encoded</param>
  88. /// <param name="value">Value of the header, should not be URL encoded</param>
  89. /// <exception cref="BadRequestException">If a header is incorrect.</exception>
  90. void AddHeader(string name, string value);
  91. /// <summary>
  92. /// Add bytes to the body
  93. /// </summary>
  94. /// <param name="bytes">buffer to read bytes from</param>
  95. /// <param name="offset">where to start read</param>
  96. /// <param name="length">number of bytes to read</param>
  97. /// <returns>Number of bytes actually read (same as length unless we got all body bytes).</returns>
  98. /// <exception cref="InvalidOperationException">If body is not writable</exception>
  99. /// <exception cref="ArgumentNullException"><c>bytes</c> is null.</exception>
  100. /// <exception cref="ArgumentOutOfRangeException"><c>offset</c> is out of range.</exception>
  101. int AddToBody(byte[] bytes, int offset, int length);
  102. /// <summary>
  103. /// Clear everything in the request
  104. /// </summary>
  105. void Clear();
  106. /// <summary>
  107. /// Decode body into a form.
  108. /// </summary>
  109. /// <param name="providers">A list with form decoders.</param>
  110. /// <exception cref="InvalidDataException">If body contents is not valid for the chosen decoder.</exception>
  111. /// <exception cref="InvalidOperationException">If body is still being transferred.</exception>
  112. //void DecodeBody(FormDecoderProvider providers);
  113. /// <summary>
  114. /// Sets the cookies.
  115. /// </summary>
  116. /// <param name="cookies">The cookies.</param>
  117. void SetCookies(RequestCookies cookies);
  118. IPEndPoint LocalIPEndPoint { get; }
  119. IPEndPoint RemoteIPEndPoint { get; }
  120. double ArrivalTS { get; set; }
  121. }
  122. }