IRequest.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Net;
  5. namespace MediaBrowser.Model.Services
  6. {
  7. public interface IRequest
  8. {
  9. /// <summary>
  10. /// The underlying ASP.NET or HttpListener HttpRequest
  11. /// </summary>
  12. object OriginalRequest { get; }
  13. IResponse Response { get; }
  14. /// <summary>
  15. /// The name of the service being called (e.g. Request DTO Name)
  16. /// </summary>
  17. string OperationName { get; set; }
  18. /// <summary>
  19. /// The Verb / HttpMethod or Action for this request
  20. /// </summary>
  21. string Verb { get; }
  22. /// <summary>
  23. /// The Request DTO, after it has been deserialized.
  24. /// </summary>
  25. object Dto { get; set; }
  26. /// <summary>
  27. /// The request ContentType
  28. /// </summary>
  29. string ContentType { get; }
  30. bool IsLocal { get; }
  31. string UserAgent { get; }
  32. IDictionary<string, Cookie> Cookies { get; }
  33. /// <summary>
  34. /// The expected Response ContentType for this request
  35. /// </summary>
  36. string ResponseContentType { get; set; }
  37. /// <summary>
  38. /// Whether the ResponseContentType has been explicitly overrided or whether it was just the default
  39. /// </summary>
  40. bool HasExplicitResponseContentType { get; }
  41. /// <summary>
  42. /// Attach any data to this request that all filters and services can access.
  43. /// </summary>
  44. Dictionary<string, object> Items { get; }
  45. QueryParamCollection Headers { get; }
  46. QueryParamCollection QueryString { get; }
  47. QueryParamCollection FormData { get; }
  48. string RawUrl { get; }
  49. string AbsoluteUri { get; }
  50. /// <summary>
  51. /// The Remote Ip as reported by Request.UserHostAddress
  52. /// </summary>
  53. string UserHostAddress { get; }
  54. /// <summary>
  55. /// The Remote Ip as reported by X-Forwarded-For, X-Real-IP or Request.UserHostAddress
  56. /// </summary>
  57. string RemoteIp { get; }
  58. /// <summary>
  59. /// The value of the Authorization Header used to send the Api Key, null if not available
  60. /// </summary>
  61. string Authorization { get; }
  62. /// <summary>
  63. /// e.g. is https or not
  64. /// </summary>
  65. bool IsSecureConnection { get; }
  66. string[] AcceptTypes { get; }
  67. string PathInfo { get; }
  68. Stream InputStream { get; }
  69. long ContentLength { get; }
  70. /// <summary>
  71. /// Access to the multi-part/formdata files posted on this request
  72. /// </summary>
  73. IHttpFile[] Files { get; }
  74. /// <summary>
  75. /// The value of the Referrer, null if not available
  76. /// </summary>
  77. Uri UrlReferrer { get; }
  78. }
  79. public interface IHttpFile
  80. {
  81. string Name { get; }
  82. string FileName { get; }
  83. long ContentLength { get; }
  84. string ContentType { get; }
  85. Stream InputStream { get; }
  86. }
  87. public interface IRequiresRequest
  88. {
  89. IRequest Request { get; set; }
  90. }
  91. public interface IResponse
  92. {
  93. /// <summary>
  94. /// The underlying ASP.NET or HttpListener HttpResponse
  95. /// </summary>
  96. object OriginalResponse { get; }
  97. IRequest Request { get; }
  98. int StatusCode { get; set; }
  99. string StatusDescription { get; set; }
  100. string ContentType { get; set; }
  101. void AddHeader(string name, string value);
  102. string GetHeader(string name);
  103. void Redirect(string url);
  104. Stream OutputStream { get; }
  105. /// <summary>
  106. /// The Response DTO
  107. /// </summary>
  108. object Dto { get; set; }
  109. /// <summary>
  110. /// Write once to the Response Stream then close it.
  111. /// </summary>
  112. /// <param name="text"></param>
  113. void Write(string text);
  114. /// <summary>
  115. /// Buffer the Response OutputStream so it can be written in 1 batch
  116. /// </summary>
  117. bool UseBufferedStream { get; set; }
  118. /// <summary>
  119. /// Signal that this response has been handled and no more processing should be done.
  120. /// When used in a request or response filter, no more filters or processing is done on this request.
  121. /// </summary>
  122. void Close();
  123. /// <summary>
  124. /// Calls Response.End() on ASP.NET HttpResponse otherwise is an alias for Close().
  125. /// Useful when you want to prevent ASP.NET to provide it's own custom error page.
  126. /// </summary>
  127. void End();
  128. /// <summary>
  129. /// Response.Flush() and OutputStream.Flush() seem to have different behaviour in ASP.NET
  130. /// </summary>
  131. void Flush();
  132. /// <summary>
  133. /// Gets a value indicating whether this instance is closed.
  134. /// </summary>
  135. bool IsClosed { get; }
  136. void SetContentLength(long contentLength);
  137. bool KeepAlive { get; set; }
  138. //Add Metadata to Response
  139. Dictionary<string, object> Items { get; }
  140. }
  141. }