You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.9 KiB

  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "net/http"
  6. )
  7. type BucketPutOriginOptions struct {
  8. XMLName xml.Name `xml:"OriginConfiguration"`
  9. Rule []BucketOriginRule `xml:"OriginRule"`
  10. }
  11. type BucketOriginRule struct {
  12. RulePriority int `xml:"RulePriority,omitempty"`
  13. OriginType string `xml:"OriginType,omitempty"`
  14. OriginCondition *BucketOriginCondition `xml:"OriginCondition,omitempty"`
  15. OriginParameter *BucketOriginParameter `xml:"OriginParameter,omitempty"`
  16. OriginInfo *BucketOriginInfo `xml:"OriginInfo,omitempty"`
  17. }
  18. type BucketOriginCondition struct {
  19. HTTPStatusCode string `xml:"HTTPStatusCode,omitempty"`
  20. Prefix string `xml:"Prefix,omitempty"`
  21. }
  22. type BucketOriginParameter struct {
  23. Protocol string `xml:"Protocol,omitempty"`
  24. FollowQueryString bool `xml:"FollowQueryString,omitempty"`
  25. HttpHeader *BucketOriginHttpHeader `xml:"HttpHeader,omitempty"`
  26. FollowRedirection bool `xml:"FollowRedirection,omitempty"`
  27. HttpRedirectCode string `xml:"HttpRedirectCode,omitempty"`
  28. CopyOriginData bool `xml:"CopyOriginData,omitempty"`
  29. }
  30. type BucketOriginHttpHeader struct {
  31. // 目前还不支持 FollowAllHeaders
  32. // FollowAllHeaders bool `xml:"FollowAllHeaders,omitempty"`
  33. NewHttpHeaders []OriginHttpHeader `xml:"NewHttpHeaders>Header,omitempty"`
  34. FollowHttpHeaders []OriginHttpHeader `xml:"FollowHttpHeaders>Header,omitempty"`
  35. }
  36. type OriginHttpHeader struct {
  37. Key string `xml:"Key,omitempty"`
  38. Value string `xml:"Value,omitempty"`
  39. }
  40. type BucketOriginInfo struct {
  41. HostInfo string `xml:"HostInfo>HostName,omitempty"`
  42. FileInfo *BucketOriginFileInfo `xml:"FileInfo,omitempty"`
  43. }
  44. type BucketOriginFileInfo struct {
  45. PrefixDirective bool `xml:"PrefixDirective,omitempty"`
  46. Prefix string `xml:"Prefix,omitempty"`
  47. Suffix string `xml:"Suffix,omitempty"`
  48. }
  49. type BucketGetOriginResult BucketPutOriginOptions
  50. func (s *BucketService) PutOrigin(ctx context.Context, opt *BucketPutOriginOptions) (*Response, error) {
  51. sendOpt := &sendOptions{
  52. baseURL: s.client.BaseURL.BucketURL,
  53. uri: "/?origin",
  54. method: http.MethodPut,
  55. body: opt,
  56. }
  57. resp, err := s.client.doRetry(ctx, sendOpt)
  58. return resp, err
  59. }
  60. func (s *BucketService) GetOrigin(ctx context.Context) (*BucketGetOriginResult, *Response, error) {
  61. var res BucketGetOriginResult
  62. sendOpt := &sendOptions{
  63. baseURL: s.client.BaseURL.BucketURL,
  64. uri: "/?origin",
  65. method: http.MethodGet,
  66. result: &res,
  67. }
  68. resp, err := s.client.doRetry(ctx, sendOpt)
  69. return &res, resp, err
  70. }
  71. func (s *BucketService) DeleteOrigin(ctx context.Context) (*Response, error) {
  72. sendOpt := &sendOptions{
  73. baseURL: s.client.BaseURL.BucketURL,
  74. uri: "/?origin",
  75. method: http.MethodDelete,
  76. }
  77. resp, err := s.client.doRetry(ctx, sendOpt)
  78. return resp, err
  79. }