{"record":{"id":"55009c6f2f1ff55c","repo":"GoogleContainerTools/jib","slug":"did-not-receive-content-length-header","errorCode":null,"errorMessage":"Did not receive Content-Length header","messagePattern":"Did not receive Content-Length header","errorType":"exception","errorClass":"RegistryErrorException","httpStatus":null,"severity":"error","filePath":"jib-core/src/main/java/com/google/cloud/tools/jib/registry/BlobChecker.java","lineNumber":54,"sourceCode":" */\nclass BlobChecker implements RegistryEndpointProvider<Optional<BlobDescriptor>> {\n\n  private final RegistryEndpointRequestProperties registryEndpointRequestProperties;\n  private final DescriptorDigest blobDigest;\n\n  BlobChecker(\n      RegistryEndpointRequestProperties registryEndpointRequestProperties,\n      DescriptorDigest blobDigest) {\n    this.registryEndpointRequestProperties = registryEndpointRequestProperties;\n    this.blobDigest = blobDigest;\n  }\n\n  /** Returns the BLOB's content descriptor. */\n  @Override\n  public Optional<BlobDescriptor> handleResponse(Response response) throws RegistryErrorException {\n    long contentLength = response.getContentLength();\n    if (contentLength < 0) {\n      throw new RegistryErrorExceptionBuilder(getActionDescription())\n          .addReason(\"Did not receive Content-Length header\")\n          .build();\n    }\n\n    return Optional.of(new BlobDescriptor(contentLength, blobDigest));\n  }\n\n  @Override\n  public Optional<BlobDescriptor> handleHttpResponseException(ResponseException responseException)\n      throws ResponseException {\n    if (responseException.getStatusCode() != HttpStatusCodes.STATUS_CODE_NOT_FOUND) {\n      throw responseException;\n    }\n\n    if (responseException.getContent() == null) {\n      // TODO: The Google HTTP client gives null content for HEAD requests. Make the content never\n      // be null, even for HEAD requests.\n      return Optional.empty();","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-core/src/main/java/com/google/cloud/tools/jib/registry/BlobChecker.java#L36-L72","documentation":"Thrown by BlobChecker.handleResponse when the registry's response to a blob existence/descriptor check (HEAD /v2/<name>/blobs/<digest>) has no Content-Length header. Jib builds the blob's descriptor (size + digest) from that header, so its absence fails the check. It surfaces as RegistryErrorException with this reason.","triggerScenarios":"Registry responds 200 to the blob HEAD request without a Content-Length header — e.g. chunked responses from proxies or nonconforming registry implementations.","commonSituations":"Registries behind proxies that strip headers, CDN/mirror layers removing Content-Length, or minimal custom registry implementations that skip the header on HEAD responses.","solutions":["Check with `curl -I` whether the blob URL returns Content-Length; if not, the registry/proxy is nonconforming.","Remove or fix any proxy/CDN layer that strips the Content-Length header from HEAD responses.","Verify the blob actually exists; some registries return odd responses for missing blobs.","Use a compliant registry implementation or upgrade its version if it's a known header bug."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// preflight: HEAD on a blob must return Content-Length\n// curl -sI https://registry.example.com/v2/<image>/blobs/<digest> | grep -i content-length","typeGuard":null,"tryCatchPattern":"// catch and diagnose header-stripping proxies\ntry {\n    jibContainerBuilder.containerize();\n} catch (RegistryErrorException e) {\n    if (e.getMessage().contains(\"Content-Length\")) {\n        throw new IllegalStateException(\"Registry/proxy omitted Content-Length on blob HEAD — check intermediary layers\", e);\n    }\n    throw e;\n}","preventionTips":["Ensure proxies/CDNs in front of the registry preserve Content-Length on HEAD responses.","Use a spec-compliant registry implementation and keep it up to date.","Verify blob existence and headers with `curl -I` before large build pipelines."],"tags":["docker-registry","blob","http-headers"],"backgroundTag":"missing-required-argument","analyzedSha":"fb949e2676afbbd7dd7a1ef61e20251931325654","analyzedAt":"2026-09-06T14:04:09.491Z","contentChangedAt":"2026-09-06T14:04:09.491Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}