Denis Kirillov
0af06c3bd9
This parameter enables parsing xml body without xmlns="http://s3.amazonaws.com/doc/2006-03-01/" attribute for CompleteMultipartUpload requests Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
38 lines
819 B
Go
38 lines
819 B
Go
package xml
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"io"
|
|
"sync"
|
|
)
|
|
|
|
const awsDefaultNamespace = "http://s3.amazonaws.com/doc/2006-03-01/"
|
|
|
|
type DecoderProvider struct {
|
|
mu sync.RWMutex
|
|
defaultXMLNSForCompleteMultipart bool
|
|
}
|
|
|
|
func NewDecoderProvider(defaultNamespace bool) *DecoderProvider {
|
|
return &DecoderProvider{
|
|
defaultXMLNSForCompleteMultipart: defaultNamespace,
|
|
}
|
|
}
|
|
|
|
func (d *DecoderProvider) NewCompleteMultipartDecoder(r io.Reader) *xml.Decoder {
|
|
dec := xml.NewDecoder(r)
|
|
|
|
d.mu.RLock()
|
|
if d.defaultXMLNSForCompleteMultipart {
|
|
dec.DefaultSpace = awsDefaultNamespace
|
|
}
|
|
d.mu.RUnlock()
|
|
|
|
return dec
|
|
}
|
|
|
|
func (d *DecoderProvider) UseDefaultNamespaceForCompleteMultipart(useDefaultNamespace bool) {
|
|
d.mu.Lock()
|
|
d.defaultXMLNSForCompleteMultipart = useDefaultNamespace
|
|
d.mu.Unlock()
|
|
}
|