PutBucketWebsiteRequest.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using COSXML.Common;
  2. using COSXML.Model.Tag;
  3. using COSXML.Network;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. namespace COSXML.Model.Bucket
  7. {
  8. public sealed class PutBucketWebsiteRequest : BucketRequest
  9. {
  10. private WebsiteConfiguration websiteConfiguration;
  11. public PutBucketWebsiteRequest(string bucket) : base(bucket)
  12. {
  13. this.method = CosRequestMethod.PUT;
  14. this.queryParameters.Add("website", null);
  15. websiteConfiguration = new WebsiteConfiguration();
  16. }
  17. public void SetIndexDocument(string suffix)
  18. {
  19. if (suffix != null)
  20. {
  21. if (websiteConfiguration.indexDocument == null)
  22. {
  23. websiteConfiguration.indexDocument = new WebsiteConfiguration.IndexDocument();
  24. }
  25. websiteConfiguration.indexDocument.suffix = suffix;
  26. }
  27. }
  28. public void SetErrorDocument(string key)
  29. {
  30. if (key != null)
  31. {
  32. if (websiteConfiguration.errorDocument == null)
  33. {
  34. websiteConfiguration.errorDocument = new WebsiteConfiguration.ErrorDocument();
  35. }
  36. websiteConfiguration.errorDocument.key = key;
  37. }
  38. }
  39. public void SetRedirectAllRequestTo(string protocol)
  40. {
  41. if (protocol != null)
  42. {
  43. if (websiteConfiguration.redirectAllRequestTo == null)
  44. {
  45. websiteConfiguration.redirectAllRequestTo = new WebsiteConfiguration.RedirectAllRequestTo();
  46. }
  47. websiteConfiguration.redirectAllRequestTo.protocol = protocol;
  48. }
  49. }
  50. public void SetRoutingRules(List<WebsiteConfiguration.RoutingRule> rules)
  51. {
  52. if (rules != null && rules.Count > 0)
  53. {
  54. if (websiteConfiguration.routingRules == null)
  55. {
  56. websiteConfiguration.routingRules = new List<WebsiteConfiguration.RoutingRule>();
  57. }
  58. foreach (WebsiteConfiguration.RoutingRule rule in rules)
  59. {
  60. if (rule.contidion != null && rule.contidion.httpErrorCodeReturnedEquals == 0)
  61. {
  62. rule.contidion.httpErrorCodeReturnedEqualsStr = null;
  63. }
  64. else if (rule.contidion != null && rule.contidion.httpErrorCodeReturnedEquals != 0)
  65. {
  66. rule.contidion.httpErrorCodeReturnedEqualsStr = rule.contidion.httpErrorCodeReturnedEquals.ToString();
  67. }
  68. websiteConfiguration.routingRules.Add(rule);
  69. }
  70. }
  71. }
  72. public override Network.RequestBody GetRequestBody()
  73. {
  74. return GetXmlRequestBody(websiteConfiguration);
  75. }
  76. }
  77. }