From ec923036e4259203d514b6ccc0db613df34907f4 Mon Sep 17 00:00:00 2001 From: Alex X Date: Fri, 10 May 2024 21:55:47 +0300 Subject: [PATCH] Fix Kasa KC200 cameras --- pkg/kasa/producer.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/pkg/kasa/producer.go b/pkg/kasa/producer.go index bcca1678..0f66f946 100644 --- a/pkg/kasa/producer.go +++ b/pkg/kasa/producer.go @@ -37,12 +37,25 @@ func Dial(url string) (*Producer, error) { return nil, err } - rd := struct { - io.Reader - io.Closer - }{ - httputil.NewChunkedReader(res.Body), - res.Body, + // KC200 + // HTTP/1.0 200 OK + // Server: Streamd, + // Content-Type: multipart/x-mixed-replace;boundary=data-boundary-- + rd := res.Body + + // KD110, KC401, KC420WS: + // HTTP/1.0 200 OK + // Content-Type: multipart/x-mixed-replace;boundary=data-boundary-- + // Transfer-Encoding: chunked + if res.Header.Get("Transfer-Encoding") == "chunked" { + // HTTP/1.0 + chunked = out of standard, so need to use this construction: + rd = struct { + io.Reader + io.Closer + }{ + httputil.NewChunkedReader(res.Body), + res.Body, + } } prod := &Producer{rd: core.NewReadBuffer(rd)}