IRequest.cs 4.3 KB

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