[#369] Move playback source files
Move git.frostfs.info/TrueCloudLab/frostfs-s3-gw/cmd/frostfs-s3-playback/request package to git.frostfs.info/TrueCloudLab/frostfs-s3-gw/playback. Move playback.yaml example config to root config folder. Signed-off-by: Nikita Zinkevich <n.zinkevich@yadro.com>
This commit is contained in:
parent
d120b2b282
commit
f6a7beb2b5
5 changed files with 46 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
||||||
package request
|
package playback
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package request
|
package playback
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package request
|
package playback
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
43
playback/utils/utils.go
Normal file
43
playback/utils/utils.go
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/xml"
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
const BodyRecognizeLimit int64 = 128
|
||||||
|
|
||||||
|
func DetectXML(reader io.Reader) (bool, []byte, error) {
|
||||||
|
checkBuf := bytes.NewBuffer(nil)
|
||||||
|
token, err := xml.NewDecoder(io.TeeReader(io.LimitReader(reader, BodyRecognizeLimit), checkBuf)).RawToken()
|
||||||
|
if err != nil {
|
||||||
|
var xmlErr *xml.SyntaxError
|
||||||
|
if errors.Is(err, io.EOF) || errors.As(err, &xmlErr) {
|
||||||
|
return false, checkBuf.Bytes(), nil
|
||||||
|
}
|
||||||
|
return false, checkBuf.Bytes(), err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch token.(type) {
|
||||||
|
case xml.StartElement, xml.ProcInst:
|
||||||
|
return true, checkBuf.Bytes(), nil
|
||||||
|
}
|
||||||
|
return false, checkBuf.Bytes(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ChooseWriter(isXML bool, body *bytes.Buffer) io.Writer {
|
||||||
|
if !isXML {
|
||||||
|
return base64.NewEncoder(base64.StdEncoding, body)
|
||||||
|
}
|
||||||
|
return body
|
||||||
|
}
|
||||||
|
|
||||||
|
func ChooseReader(isXml bool, bodyReader io.Reader) io.Reader {
|
||||||
|
if !isXml {
|
||||||
|
return base64.NewDecoder(base64.StdEncoding, bodyReader)
|
||||||
|
}
|
||||||
|
return bodyReader
|
||||||
|
}
|
Loading…
Reference in a new issue