OptionObjectResult.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace COSXML.Model.Object
  5. {
  6. /// <summary>
  7. /// 实现 Object 跨域访问配置的预请求
  8. /// <see href="https://cloud.tencent.com/document/product/436/8288"/>
  9. /// </summary>
  10. public sealed class OptionObjectResult : CosResult
  11. {
  12. /// <summary>
  13. /// 跨域访问的请求来源域名
  14. /// </summary>
  15. public string accessControlAllowOrigin;
  16. /// <summary>
  17. /// OPTIONS 请求得到结果的有效期
  18. /// </summary>
  19. public long accessControlMaxAge;
  20. /// <summary>
  21. /// 跨域访问的允许请求头部
  22. /// </summary>
  23. public List<string> accessControlAllowHeaders;
  24. /// <summary>
  25. /// 跨域访问的允许请求 HTTP 方法
  26. /// </summary>
  27. public List<string> accessControlAllowMethods;
  28. /// <summary>
  29. /// 跨域访问的允许请求自定义头部
  30. /// </summary>
  31. public List<string> accessControlAllowExposeHeaders;
  32. internal override void InternalParseResponseHeaders()
  33. {
  34. List<string> values;
  35. this.responseHeaders.TryGetValue("Access-Control-Allow-Origin", out values);
  36. if (values != null && values.Count > 0)
  37. {
  38. accessControlAllowOrigin = values[0];
  39. }
  40. this.responseHeaders.TryGetValue("Access-Control-Max-Age", out values);
  41. if (values != null && values.Count > 0)
  42. {
  43. long.TryParse(values[0], out accessControlMaxAge);
  44. }
  45. this.responseHeaders.TryGetValue("Access-Control-Allow-Methods", out values);
  46. if (values != null && values.Count > 0)
  47. {
  48. accessControlAllowMethods = new List<string>(values[0].Split(','));
  49. }
  50. this.responseHeaders.TryGetValue("Access-Control-Allow-Headers", out values);
  51. if (values != null && values.Count > 0)
  52. {
  53. accessControlAllowHeaders = new List<string>(values[0].Split(','));
  54. }
  55. this.responseHeaders.TryGetValue("Access-Control-Expose-Headers", out values);
  56. if (values != null && values.Count > 0)
  57. {
  58. accessControlAllowExposeHeaders = new List<string>(values[0].Split(','));
  59. }
  60. }
  61. public override string GetResultInfo()
  62. {
  63. return base.GetResultInfo() + "\n" + accessControlAllowOrigin;
  64. }
  65. }
  66. }