forked from TrueCloudLab/frostfs-s3-gw
Add content detector
Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
parent
1868034723
commit
31d3e55489
1 changed files with 26 additions and 0 deletions
26
api/layer/detector.go
Normal file
26
api/layer/detector.go
Normal 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)
|
||||
}
|
Loading…
Reference in a new issue