Skip to content

blob_writer.go does not handle Range header properly #1240

Open

Description

@allbinmani

According to the "Docker Registry HTTP API V2" document at https://docs.docker.com/registry/spec/api/, the proper response to a blob upload request to /v2/<name>/blobs/uploads/<uuid> is 202 No Content, including a Range header, like so:

202 Accepted
Location: /v2//blobs/uploads/
Range: bytes=0-
Docker-Upload-UUID:
Content-Length: 0

However, blob_writer.go does not handle the "bytes=" part of the Range-header, but assumes the header only contain <int>-<int>

rng := resp.Header.Get("Range")
var start, end int64
if n, err := fmt.Sscanf(rng, "%d-%d", &start, &end); err != nil {
return 0, err
} else if n != 2 || end < start {
return 0, fmt.Errorf("bad range format: %s", rng)
}

Similarily, docker registry most likely does not include a "bytes=" prefix in it's Reange header response either..

RFC2616 section 14.35.1 Byte Ranges specifies bytes= as required.

My GO skills are limited, so cannot provide patch, but not sure this should be patched, as it might be intentional behaviour (the documentation does state the API uses the Range header in a non-standard way) ?

Activity

  1. stevvooe commented on Dec 8, 2015

    @stevvooe
    Collaborator

    It sounds like you're expecting this header to be present on the initial request. This isn't really necessary, since the initial size of a new upload should always be zero. Please read the specification carefully, as it covers this, in detail. From that point, the registry will populate the Range header on get to the upload location (this is filled in here) or after each chunk post (which isn't implemented).

    We also use the Range syntax as part of requests to communicate the chunking of an upload in the registry. This is non-standard, in that the client sets the Content-Range header and issues PUT requests. We haven't had needed to implement this (Chunking), as it turns out to be less than useful, until other optimization have been implemented.

    If you want to use Range requests on get, they are already full supported.

    My suggestion would be to read over the specification more carefully and dump the flow of the client. If you are accessing Range headers, you're likely not implementing the protocol correctly.

  2. allbinmani commented on Dec 8, 2015

    @allbinmani
    Author

    @stevvooe Appreciate the response, but the "issue" was not really about if the Range header is there at any given time or not, but about how it's value is being formatted/interpreted. The spec (Registry HTTP API V2, aswell as the RFC) states that it should include a "bytes=" prefix, but it does not in Docker's case.
    However, as the documentation for the Registry HTTP API V2 also states that the Range header is used in a non-standard fashion, I'm inclined to believe that this is simply a documentation issue, as the code works just fine using the official repository image.

  3. stevvooe commented on Dec 8, 2015

    @stevvooe
    Collaborator

    @allbinmani Ah, I see. While this is a non-standard use of Range, the field should match the request header, even if it is on a request. Looks like we are using it here, so no going back.

    We'll have to make the client accept both. May need to modify the specification to clarify that parsing the Range header should allow for missing "bytes=", which is mostly redundant anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions