HttpResponseStreamWrapper.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Net;
  4. using System.Text;
  5. using MediaBrowser.Model.Services;
  6. namespace ServiceStack.Host
  7. {
  8. public class HttpResponseStreamWrapper : IHttpResponse
  9. {
  10. private static readonly UTF8Encoding UTF8EncodingWithoutBom = new UTF8Encoding(false);
  11. public HttpResponseStreamWrapper(Stream stream, IRequest request)
  12. {
  13. this.OutputStream = stream;
  14. this.Request = request;
  15. this.Headers = new Dictionary<string, string>();
  16. this.Items = new Dictionary<string, object>();
  17. }
  18. public Dictionary<string, string> Headers { get; set; }
  19. public object OriginalResponse
  20. {
  21. get { return null; }
  22. }
  23. public IRequest Request { get; private set; }
  24. public int StatusCode { set; get; }
  25. public string StatusDescription { set; get; }
  26. public string ContentType { get; set; }
  27. public void AddHeader(string name, string value)
  28. {
  29. this.Headers[name] = value;
  30. }
  31. public string GetHeader(string name)
  32. {
  33. return this.Headers[name];
  34. }
  35. public void Redirect(string url)
  36. {
  37. this.Headers["Location"] = url;
  38. }
  39. public Stream OutputStream { get; private set; }
  40. public object Dto { get; set; }
  41. public void Write(string text)
  42. {
  43. var bytes = UTF8EncodingWithoutBom.GetBytes(text);
  44. OutputStream.Write(bytes, 0, bytes.Length);
  45. }
  46. public bool UseBufferedStream { get; set; }
  47. public void Close()
  48. {
  49. if (IsClosed) return;
  50. OutputStream.Dispose();
  51. IsClosed = true;
  52. }
  53. public void End()
  54. {
  55. Close();
  56. }
  57. public void Flush()
  58. {
  59. OutputStream.Flush();
  60. }
  61. public bool IsClosed { get; private set; }
  62. public void SetContentLength(long contentLength) {}
  63. public bool KeepAlive { get; set; }
  64. public Dictionary<string, object> Items { get; private set; }
  65. public void SetCookie(Cookie cookie)
  66. {
  67. }
  68. public void ClearCookies()
  69. {
  70. }
  71. }
  72. }