vvidic / mjpeg-proxy

Republish a MJPEG HTTP image stream using a server in Go
GNU General Public License v3.0
22 stars 15 forks source link

Some DLINK camera fail the content type check #12

Closed kand617 closed 3 years ago

kand617 commented 3 years ago

I came across a dlink camera who's content type is multipart/x-mixed-replace;boundary=video boundary--

This fails to parse as the -- is not valid unless its in quotes. Thus we need a way to sanitize the header to get `multipart/x-mixed-replace;boundary="video boundary--" (quotes added)

The following might be sufficient

func SanitizeContentType(s string) string {
    if strings.HasSuffix(s, "-") {
        // Boundary is not escaped
        segments:= strings.Split(s, "boundary=")
        formatted := segments[0] + "boundary=\"" + segments[1] + "\""
        return formatted
    }
    return s
}