ParseBucketCorsConfig parses a CORS configuration in XML from an io.Reader.
(reader io.Reader)
| 59 | |
| 60 | // ParseBucketCorsConfig parses a CORS configuration in XML from an io.Reader. |
| 61 | func ParseBucketCorsConfig(reader io.Reader) (*Config, error) { |
| 62 | var c Config |
| 63 | |
| 64 | // Max size of cors document is 64KiB according to https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketCors.html |
| 65 | // This limiter is just for safety so has a max of 128KiB |
| 66 | err := xml.NewDecoder(io.LimitReader(reader, 128*humanize.KiByte)).Decode(&c) |
| 67 | if err != nil { |
| 68 | return nil, fmt.Errorf("decoding xml: %w", err) |
| 69 | } |
| 70 | if c.XMLNS == "" { |
| 71 | c.XMLNS = defaultXMLNS |
| 72 | } |
| 73 | for i, rule := range c.CORSRules { |
| 74 | for j, method := range rule.AllowedMethod { |
| 75 | c.CORSRules[i].AllowedMethod[j] = strings.ToUpper(method) |
| 76 | } |
| 77 | } |
| 78 | return &c, nil |
| 79 | } |
| 80 | |
| 81 | // ToXML marshals the CORS configuration to XML. |
| 82 | func (c Config) ToXML() ([]byte, error) { |
no outgoing calls