Add content detector

Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
Evgeniy Kulikov 2020-11-27 15:33:31 +03:00
parent 1868034723
commit 31d3e55489

26
api/layer/detector.go Normal file
View file

@ -0,0 +1,26 @@
package layer
import (
"io"
"net/http"
"sync"
)
type detector struct {
io.Reader
sync.Once
contentType string
}
func newDetector(r io.Reader) *detector {
return &detector{Reader: r}
}
func (d *detector) Read(data []byte) (int, error) {
d.Do(func() {
d.contentType = http.DetectContentType(data)
})
return d.Reader.Read(data)
}