Fix Kasa KC200 cameras

This commit is contained in:
Alex X
2024-05-10 21:55:47 +03:00
parent ee387b79e1
commit f7b98044e6
2 changed files with 27 additions and 2 deletions
+21 -1
View File
@@ -37,14 +37,34 @@ func Dial(url string) (*Producer, error) {
return nil, err
}
// KC200
// HTTP/1.0 200 OK
// Content-Type: multipart/x-mixed-replace;boundary=data-boundary--
// KD110, KC401, KC420WS:
// HTTP/1.0 200 OK
// Content-Type: multipart/x-mixed-replace;boundary=data-boundary--
// Transfer-Encoding: chunked
// HTTP/1.0 + chunked = out of standard, so golang remove this header
// and we need to check first two bytes
buf := bufio.NewReader(res.Body)
b, err := buf.Peek(2)
if err != nil {
return nil, err
}
rd := struct {
io.Reader
io.Closer
}{
httputil.NewChunkedReader(res.Body),
buf,
res.Body,
}
if string(b) != "--" {
rd.Reader = httputil.NewChunkedReader(buf)
}
prod := &Producer{rd: core.NewReadBuffer(rd)}
if err = prod.probe(); err != nil {
return nil, err