IRequest.cs 4.2 KB

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