{"record":{"id":"8ec68787afe16e6b","repo":"AlexxIT/go2rtc","slug":"multipart-no-content-length","errorCode":null,"errorMessage":"multipart: no content length","messagePattern":"multipart: no content length","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/mpjpeg/multipart.go","lineNumber":46,"sourceCode":"\n\t\t// Foscam G2 has a awful implementation of MJPEG\n\t\t// https://github.com/AlexxIT/go2rtc/issues/1258\n\t\tif b, _ := rd.Peek(2); string(b) == \"--\" {\n\t\t\tcontinue\n\t\t}\n\n\t\tbreak\n\t}\n\n\ttp := textproto.NewReader(rd)\n\theader, err := tp.ReadMIMEHeader()\n\tif err != nil {\n\t\treturn nil, nil, err\n\t}\n\n\ts := header.Get(\"Content-Length\")\n\tif s == \"\" {\n\t\treturn nil, nil, errors.New(\"multipart: no content length\")\n\t}\n\n\tsize, err := strconv.Atoi(s)\n\tif err != nil {\n\t\treturn nil, nil, err\n\t}\n\n\tbuf := make([]byte, size)\n\tif _, err = io.ReadFull(rd, buf); err != nil {\n\t\treturn nil, nil, err\n\t}\n\n\treturn http.Header(header), buf, nil\n}\n","sourceCodeStart":28,"sourceCodeEnd":61,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/mpjpeg/multipart.go#L28-L61","documentation":"Each part of an MJPEG multipart stream carries a MIME part header block; go2rtc requires the Content-Length header to know how many bytes of JPEG data to read for the frame. If the header is absent or empty, frame framing is impossible, so Next returns this error instead of guessing boundaries.","triggerScenarios":"mpjpeg Producer.Next reads a part whose header set has no Content-Length value (header.Get(\"Content-Length\") == \"\").","commonSituations":"Cameras or streaming servers that emit multipart parts without Content-Length (chunked or delimiter-only framing); custom streaming middlewares; misconfigured camera firmware that omits part headers.","solutions":["Use a camera/server firmware or configuration that includes Content-Length in each multipart part header.","Place go2rtc behind a transcoding step (e.g. restream through ffmpeg) if the source cannot be fixed: `ffmpeg -i http://cam -c copy -f mpjpeg -`.","Check whether an HTTP proxy or CDN is stripping part headers and bypass it.","Open/track an upstream issue with the vendor; this format cannot be parsed without part lengths."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Probe the stream and confirm part headers carry Content-Length\nrd := bufio.NewReader(resp.Body)\nline, _ := rd.ReadString('\\n')\nif !strings.Contains(strings.ToLower(line), \"content-length\") {\n    return errors.New(\"source multipart parts lack Content-Length; unsupported source\")\n}","typeGuard":null,"tryCatchPattern":"if err := producer.Start(); err != nil {\n    if strings.Contains(err.Error(), \"no content length\") {\n        return fmt.Errorf(\"camera sends multipart parts without Content-Length; remux via ffmpeg or update firmware: %w\", err)\n    }\n    return err\n}","preventionTips":["Test the source with curl -i and inspect part headers before integrating","Prefer cameras/servers known to emit Content-Length per part","Avoid proxies that rewrite or strip multipart headers","Route non-conformant sources through ffmpeg to normalize the mpjpeg output"],"tags":["multipart","mjpeg","http-headers"],"backgroundTag":"missing-required-argument","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}