ServiceStackServiceRequest.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using ServiceStack.Web;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.Specialized;
  5. namespace MediaBrowser.Controller.Net
  6. {
  7. public class ServiceStackServiceRequest : IServiceRequest
  8. {
  9. private readonly IRequest _request;
  10. public ServiceStackServiceRequest(IRequest request)
  11. {
  12. _request = request;
  13. }
  14. public object OriginalRequest
  15. {
  16. get { return _request; }
  17. }
  18. public string RemoteIp
  19. {
  20. get { return _request.RemoteIp; }
  21. }
  22. private NameValueCollection _headers;
  23. public NameValueCollection Headers
  24. {
  25. get { return _headers ?? (_headers = Get(_request.Headers)); }
  26. }
  27. private NameValueCollection _query;
  28. public NameValueCollection QueryString
  29. {
  30. get { return _query ?? (_query = Get(_request.QueryString)); }
  31. }
  32. private NameValueCollection Get(INameValueCollection coll)
  33. {
  34. var nv = new NameValueCollection(StringComparer.OrdinalIgnoreCase);
  35. foreach (var key in coll.AllKeys)
  36. {
  37. nv[key] = coll[key];
  38. }
  39. return nv;
  40. //return coll.ToNameValueCollection();
  41. }
  42. public IDictionary<string, object> Items
  43. {
  44. get { return _request.Items; }
  45. }
  46. public void AddResponseHeader(string name, string value)
  47. {
  48. _request.Response.AddHeader(name, value);
  49. }
  50. }
  51. }