Skip to content

[all] IsEmpty to check for HTTP status 204#2540

Merged
mandre merged 1 commit intogophercloud:masterfrom
shiftstack:204_nocontent
Mar 8, 2023
Merged

[all] IsEmpty to check for HTTP status 204#2540
mandre merged 1 commit intogophercloud:masterfrom
shiftstack:204_nocontent

Conversation

@pierreprinetti
Copy link
Copy Markdown
Member

With this commit, all IsEmpty() (bool, error) functions now check the status code of the result. If it's 204, they immediately confirm that the page is empty.

This change was introduced in commit 64ed1bc in objectstorage to support Swift instances running behind a reverse proxy that was truncating content-type headers from 204 Empty responses. With this change, the same check is applied to all services.

While no functional impact is expected on non-proxied OpenStack modules, this patch will prevent issues on proxied clouds. In general, it also seems reasonable to expect 204 Empty responses to be empty.


This change is the result of running:

find -name 'results.go' -exec sed -i 's|^\(func (\(.\+\) .\+) IsEmpty() (bool, error) {\)$|\1\nif \2.StatusCode==204 {\nreturn true,nil\n}\n|' {} \;
go fmt ./...

@pierreprinetti pierreprinetti added this to the v1.2.1 milestone Jan 26, 2023
@coveralls
Copy link
Copy Markdown

coveralls commented Jan 26, 2023

Coverage Status

Coverage: 79.151% (-1.09%) from 80.237% when pulling 974f426 on shiftstack:204_nocontent into 7edb0d0 on gophercloud:master.

@mandre mandre modified the milestones: v1.2.1, v1.3.0 Feb 2, 2023
@pierreprinetti
Copy link
Copy Markdown
Member Author

@mandre you modified the milestone to a minor bump. Is that because you think this PR needs a semver:minor label?

@mandre
Copy link
Copy Markdown
Contributor

mandre commented Feb 6, 2023

@mandre you modified the milestone to a minor bump. Is that because you think this PR needs a semver:minor label?

Not at all, it's because I've merge a couple of PRs in main last week that requires a minor bump. Because we don't maintain stable branches yet, this supposed the next version is going to be 1.3.0.

With this commit, all `IsEmpty() (bool, error)` functions now check the
status code of the result. If it's `204`, they immediately confirm that
the page is empty.

This change was introduced in commit 64ed1bc in `objectstorage` to
support Swift instances running behind a reverse proxy that was
truncating `content-type` headers from `204 Empty` responses. With this
change, the same check is applied to all services.

While no functional impact is expected on non-proxied OpenStack modules,
this patch will prevent issues on proxied clouds. In general, it also
seems reasonable to expect `204 Empty` responses to be empty.

---

This change is the result of running:

```shell
find -name 'results.go' -exec sed -i 's|^\(func (\(.\+\) .\+) IsEmpty() (bool, error) {\)$|\1\nif \2.StatusCode==204 {\nreturn true,nil\n}\n|' {} \;
go fmt ./...
```
Copy link
Copy Markdown
Contributor

@mandre mandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mandre mandre merged commit 9ed19a8 into gophercloud:master Mar 8, 2023
@mandre mandre deleted the 204_nocontent branch March 8, 2023 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants