{"record":{"id":"2d02ff27a32f903b","repo":"Tencent/WeKnora","slug":"non-image-content-type-s","errorCode":null,"errorMessage":"non-image content type: %s","messagePattern":"non-image content type: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/docparser/image_resolver.go","lineNumber":1034,"sourceCode":"\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"HTTP GET: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, \"\", fmt.Errorf(\"unexpected status %d\", resp.StatusCode)\n\t}\n\n\t// Determine MIME type from Content-Type header.\n\tct := resp.Header.Get(\"Content-Type\")\n\tmimeType, _, _ = mime.ParseMediaType(ct)\n\tif mimeType == \"\" {\n\t\tmimeType = \"application/octet-stream\"\n\t}\n\n\t// Only allow image content types (or octet-stream which we sniff later).\n\tif !strings.HasPrefix(mimeType, \"image/\") && mimeType != \"application/octet-stream\" {\n\t\treturn nil, \"\", fmt.Errorf(\"non-image content type: %s\", mimeType)\n\t}\n\n\t// Read body with size limit.\n\tlimited := io.LimitReader(resp.Body, maxRemoteImageSize+1)\n\tbody, err := io.ReadAll(limited)\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"read body: %w\", err)\n\t}\n\tif len(body) > maxRemoteImageSize {\n\t\treturn nil, \"\", fmt.Errorf(\"image exceeds %d bytes limit\", maxRemoteImageSize)\n\t}\n\n\t// If MIME was octet-stream, sniff the real type from body.\n\tif mimeType == \"application/octet-stream\" {\n\t\tdetected := http.DetectContentType(body)\n\t\tif strings.HasPrefix(detected, \"image/\") {\n\t\t\tmimeType = detected\n\t\t} else {","sourceCodeStart":1016,"sourceCodeEnd":1052,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/docparser/image_resolver.go#L1016-L1052","documentation":"This error is returned when the remote image's Content-Type header is neither an image/* type nor application/octet-stream. It is a safety check preventing storage of HTML error pages, text, or other non-image payloads as images.","triggerScenarios":"downloadImage receives a response whose Content-Type is e.g. text/html (soft-404/error page), application/json, or text/plain.","commonSituations":"Dead image links returning HTML error pages with 200 status, CDNs serving JSON error bodies, misconfigured servers sending wrong Content-Type headers, authenticated pages redirecting to login HTML.","solutions":["Verify the URL actually serves an image (curl -I to inspect Content-Type)","Skip images whose host returns HTML error pages with 200 status","If the server sends a wrong-but-known type, fix the server's Content-Type header","Rely on octet-stream sniffing already implemented for servers omitting the type"],"exampleFix":"// before\nif !strings.HasPrefix(mimeType, \"image/\") && mimeType != \"application/octet-stream\" {\n    return nil, \"\", fmt.Errorf(\"non-image content type: %s\", mimeType)\n}\n// after\n// sniff first 512 bytes to rescue wrong headers\ncmp := http.DetectContentType(body[:minInt(512, len(body))])\nif !strings.HasPrefix(mimeType, \"image/\") && !strings.HasPrefix(cmp, \"image/\") {\n    return nil, \"\", fmt.Errorf(\"non-image content type: %s\", mimeType)\n}","handlingStrategy":"validation","validationCode":"// check Content-Type before downloading the full body\nresp, err := http.Head(imgURL)\nif err != nil { return err }\nct := resp.Header.Get(\"Content-Type\")\nif !strings.HasPrefix(ct, \"image/\") && ct != \"application/octet-stream\" {\n    return fmt.Errorf(\"skipping non-image resource: %s\", ct)\n}","typeGuard":null,"tryCatchPattern":"data, mimeType, err := downloadImage(ctx, client, remoteURL)\nif err != nil {\n    if strings.Contains(err.Error(), \"non-image content type\") {\n        log.Warn(\"skipping non-image response\", \"url\", remoteURL)\n        return nil, \"\", errRemoteImageSkipped\n    }\n    return nil, \"\", err\n}","preventionTips":["HEAD-preflight image URLs and check Content-Type before full download","Treat 200-with-HTML responses as dead links and skip them","Use content sniffing (http.DetectContentType) as a fallback for wrong headers","Keep the octet-stream allowance for servers that omit Content-Type"],"tags":["http","content-type","validation","image"],"backgroundTag":"invalid-content-type","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}