Response.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.Specialized;
  4. using System.IO;
  5. namespace MediaBrowser.Common.Net
  6. {
  7. public abstract class Response
  8. {
  9. protected RequestContext RequestContext { get; private set; }
  10. protected NameValueCollection QueryString
  11. {
  12. get
  13. {
  14. return RequestContext.Request.QueryString;
  15. }
  16. }
  17. public Response(RequestContext ctx)
  18. {
  19. RequestContext = ctx;
  20. WriteStream = s => { };
  21. Headers = new Dictionary<string, string>();
  22. }
  23. public abstract string ContentType { get; }
  24. public virtual int StatusCode
  25. {
  26. get
  27. {
  28. return 200;
  29. }
  30. }
  31. public virtual TimeSpan CacheDuration
  32. {
  33. get
  34. {
  35. return TimeSpan.FromTicks(0);
  36. }
  37. }
  38. public virtual DateTime? LastDateModified
  39. {
  40. get
  41. {
  42. return null;
  43. }
  44. }
  45. public IDictionary<string, string> Headers { get; set; }
  46. public Action<Stream> WriteStream { get; set; }
  47. }
  48. /*public class ByteResponse : Response
  49. {
  50. public ByteResponse(byte[] bytes)
  51. {
  52. WriteStream = async s =>
  53. {
  54. await s.WriteAsync(bytes, 0, bytes.Length);
  55. s.Close();
  56. };
  57. }
  58. }
  59. public class StringResponse : ByteResponse
  60. {
  61. public StringResponse(string message)
  62. : base(Encoding.UTF8.GetBytes(message))
  63. {
  64. }
  65. }*/
  66. }