[GH-ISSUE #1076] If-Generation-Match header not handled on object read. #163

Open
opened 2026-03-03 12:08:50 +03:00 by kerem · 4 comments
Owner

Originally created by @jklipp on GitHub (Feb 16, 2023).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/1076

fakestoragedoesn't handle x-goog-if-generation-match header that cloud.google.com/go/storage seems to be sending.

I was writing a test using fakestorage as a backend to validate that my system can handle generation mismatches, with code similar to:

    obj := bucket.Object("a-valid/object").ReadCompressed(true).If(storage.Conditions{GenerationMatch: 1234})

    r, err := obj.NewReader(ctx)
    if err != nil {
        // TODO: what type of error if metadata mismatch?  need to handle
        return nil, fmt.Errorf("reading object: %w", err)
    }

when I found that the GenerationMatch condition was being ignored (NewReader returns nil err).

I'm unclear under what condition cloud.google.com/go/storage sends the header rather than a json blob or form value with a generation key in it. I see a reference to it in the GCS XML API, specifically in the download an object call.

For now I've worked around this in our own repo by simply checking for the header as well during the downloadObject call: github.com/inflexiongames/fake-gcs-server@4365cf2a5c. If that seems like a reasonable approach I can look at doing a PR, but wanted to see if I'd overlooked something first.

Originally created by @jklipp on GitHub (Feb 16, 2023). Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/1076 `fakestorage`doesn't handle `x-goog-if-generation-match` header that `cloud.google.com/go/storage` seems to be sending. I was writing a test using fakestorage as a backend to validate that my system can handle generation mismatches, with code similar to: ``` obj := bucket.Object("a-valid/object").ReadCompressed(true).If(storage.Conditions{GenerationMatch: 1234}) r, err := obj.NewReader(ctx) if err != nil { // TODO: what type of error if metadata mismatch? need to handle return nil, fmt.Errorf("reading object: %w", err) } ``` when I found that the GenerationMatch condition was being ignored (NewReader returns nil err). I'm unclear under what condition `cloud.google.com/go/storage` sends the header rather than a json blob or form value with a `generation` key in it. I see a reference to it in the [GCS XML API](https://cloud.google.com/storage/docs/xml-api/reference-headers#xgoogifgenerationmatch), specifically in the [download an object](https://cloud.google.com/storage/docs/xml-api/get-object-download) call. For now I've worked around this in our own repo by simply checking for the header as well during the downloadObject call: https://github.com/inflexiongames/fake-gcs-server/commit/4365cf2a5c79b5ab838951ec2bdaee9142b51eb1. If that seems like a reasonable approach I can look at doing a PR, but wanted to see if I'd overlooked something first.
Author
Owner

@jklipp commented on GitHub (Feb 16, 2023):

Oh, looking at it some more I may have gone down the wrong path - it looks more like the generation specifier is for downloading a particular generation, rather than supporting the precondition.

In that case I guess my question is more are preconditions supported for downloads? I see support for preconditions on uploads went in last year https://github.com/fsouza/fake-gcs-server/pull/735 but there may not be support for downloads yet?

<!-- gh-comment-id:1433813495 --> @jklipp commented on GitHub (Feb 16, 2023): Oh, looking at it some more I may have gone down the wrong path - it looks more like the `generation` specifier is for downloading a particular generation, rather than supporting the precondition. In that case I guess my question is more are preconditions supported for downloads? I see support for preconditions on uploads went in last year https://github.com/fsouza/fake-gcs-server/pull/735 but there may not be support for downloads yet?
Author
Owner

@jklipp commented on GitHub (Feb 17, 2023):

I made an attempt at implementing if-generation-match preconditions for get and download in github.com/inflexiongames/fake-gcs-server@6ed1d78733, does this seem somewhat like a sensible approach?

<!-- gh-comment-id:1434097151 --> @jklipp commented on GitHub (Feb 17, 2023): I made an attempt at implementing if-generation-match preconditions for get and download in https://github.com/inflexiongames/fake-gcs-server/commit/6ed1d787333e31142d6e1a9ac0655d1bf6433b7a, does this seem somewhat like a sensible approach?
Author
Owner

@fsouza commented on GitHub (Feb 25, 2023):

I made an attempt at implementing if-generation-match preconditions for get and download in inflexiongames@6ed1d78, does this seem somewhat like a sensible approach?

Hey, sorry things have been slow on my end, but I'm planning to take a look at this during this weekend!

<!-- gh-comment-id:1444818338 --> @fsouza commented on GitHub (Feb 25, 2023): > I made an attempt at implementing if-generation-match preconditions for get and download in [inflexiongames@6ed1d78](https://github.com/inflexiongames/fake-gcs-server/commit/6ed1d787333e31142d6e1a9ac0655d1bf6433b7a), does this seem somewhat like a sensible approach? Hey, sorry things have been slow on my end, but I'm planning to take a look at this during this weekend!
Author
Owner

@fsouza commented on GitHub (May 3, 2023):

Hey @jklipp, sorry for the ridiculous turnaround on this. I've taken a look at the changes, it seems reasonable, perhaps if we can avoid breaking the library API, it should be perfect. Can you send a PR so we can have CI run on it? And also I can leave some inline comments in the PR.

<!-- gh-comment-id:1532401838 --> @fsouza commented on GitHub (May 3, 2023): Hey @jklipp, sorry for the ridiculous turnaround on this. I've taken a look at the changes, it seems reasonable, perhaps if we can avoid breaking the library API, it should be perfect. Can you send a PR so we can have CI run on it? And also I can leave some inline comments in the PR.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#163
No description provided.