Skip to content

Fixes server ignores request to gzip data #14982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from

Conversation

rose2221
Copy link
Contributor

What type of PR is this?

Bug fix

What does this PR do? Why is it needed?

This PR fixes an issue where the Prysm beacon chain server ignores the Accept-Encoding: gzip header in HTTP requests and always returns uncompressed JSON responses.

Fix Details:

  • Updated middleware to properly respect the Accept-Encoding header.
  • Ensured that responses are compressed when requested.
  • Added error handling to prevent silent failures.

Which issue(s) does this PR fix?

Fixes #14593

Other Notes for Review

Acknowledgements

  • [✅] I have read CONTRIBUTING.md.
  • [✅] I have included a uniquely named changelog fragment file.
  • [✅] I have added a description to this PR with sufficient context for reviewers to understand this PR.

@rose2221 rose2221 requested a review from a team as a code owner February 24, 2025 10:11
@CLAassistant
Copy link

CLAassistant commented Feb 24, 2025

CLA assistant check
All committers have signed the CLA.

@rose2221 rose2221 changed the title Fixes #14593 Fixes server ignores request to gzip data Feb 24, 2025
@rkapka
Copy link
Contributor

rkapka commented Feb 24, 2025

Hey @rose2221 , thanks for the contribution! This PR only adds gzip to the blobs endpoint, but it would make much more sense to have support on all endpoints that return data. Which means all endpoint that use middleware.AcceptHeaderHandler.

Before merging the PR you will also have to sign the Contributor License Agreement and add a changelog file.

@rose2221
Copy link
Contributor Author

rose2221 commented Feb 25, 2025

Thank you, @rkapka, for your suggestions! I've implemented the requested changes. Let me know if there's anything else that needs adjustment. Also, should I add tests for this as well?

@rkapka
Copy link
Contributor

rkapka commented Feb 25, 2025

Also, should I add tests for this as well?

That would be very helpful. Perhaps you could write a unit test where you:

  • have a dummy handler that returns some value
  • register the gzip middleware for this handler
  • execute the handler and check that the returned data is NOT equal to the value that the handler returns (meaning that it got zipped - this is to prevent a scenario where nothing gets zipped and the next step does nothing, but the whole test passes)
  • unzip the returned data and see that it's equal to the value returned from the handler

@rose2221
Copy link
Contributor Author

rose2221 commented Feb 26, 2025

Also, should I add tests for this as well?

That would be very helpful. Perhaps you could write a unit test where you:

  • have a dummy handler that returns some value
  • register the gzip middleware for this handler
  • execute the handler and check that the returned data is NOT equal to the value that the handler returns (meaning that it got zipped - this is to prevent a scenario where nothing gets zipped and the next step does nothing, but the whole test passes)
  • unzip the returned data and see that it's equal to the value returned from the handler

Thank you, I've implemented the test as suggested and I'm open to any further feedback. @rkapka

@rose2221 rose2221 requested a review from rkapka March 5, 2025 09:29
@james-prysm
Copy link
Contributor

please fix linting bazel run //:gazelle -- fix

if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
next.ServeHTTP(w, r)
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There's something wrong with this formatting when I first read it I thought it was on the return above


w.Header().Set("Content-Encoding", "gzip")

gz := gzip.NewWriter(w)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little worried about the usage of this will need to read up more on this

@rkapka
Copy link
Contributor

rkapka commented Mar 14, 2025

@rose2221 Thanks for the test. I would like to approve the PR, but you need to run bazel run //:gazelle -- fix to fix dependencies before this can be merged.

rkapka
rkapka previously approved these changes Mar 18, 2025
@rkapka
Copy link
Contributor

rkapka commented Mar 18, 2025

Merging the PR @rose2221 , thanks a lot for the contribution!

@rkapka
Copy link
Contributor

rkapka commented Mar 24, 2025

@rose2221 For some reason our end-to-end tests fail with this PR. I can debug this myself but if you'd like to do it yourself you can run

bazel test //testing/endtoend:go_default_test --test_filter=TestEndToEnd_MinimalConfig --test_env=E2E_EPOCHS=4 --test_timeout=10000 --test_output=streamed --sandbox_debug

@rose2221
Copy link
Contributor Author

@rose2221 For some reason our end-to-end tests fail with this PR. I can debug this myself but if you'd like to do it yourself you can run

bazel test //testing/endtoend:go_default_test --test_filter=TestEndToEnd_MinimalConfig --test_env=E2E_EPOCHS=4 --test_timeout=10000 --test_output=streamed --sandbox_debug

hey yes i would like to work on it

@rkapka
Copy link
Contributor

rkapka commented Mar 24, 2025

Great! When the test fails, it outputs a path where all logs are stored. These are logs from the e2e run as well as beacon node logs (and some other as well but looking at beacon node logs should be enough)

@rose2221 rose2221 requested a review from rkapka May 7, 2025 21:44
@rose2221
Copy link
Contributor Author

rose2221 commented May 30, 2025

Great! When the test fails, it outputs a path where all logs are stored. These are logs from the e2e run as well as beacon node logs (and some other as well but looking at beacon node logs should be enough)

Hey @rkapka @james-prysm , sorry for the delay — I've fixed it now. Thanks for pointing out the log path.

@rose2221 rose2221 requested a review from james-prysm June 9, 2025 08:14
Copy link
Contributor

@rkapka rkapka left a comment

Choose a reason for hiding this comment

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

Simply ignoring SSZ is not correct

Ignoring SSZ is fine, but we should do it in a more reliable way. The user can specify two values in the Accept header, in which case even though application/octet-stream is a part of the header, the type of the response can still be application/json

@rkapka
Copy link
Contributor

rkapka commented Jul 7, 2025

@rose2221 Do you mind cherry-picking 5dcbb52 into your branch? I believe this is the correct way to ignore SSZ responses

@rose2221
Copy link
Contributor Author

rose2221 commented Jul 9, 2025

@rose2221 Do you mind cherry-picking 5dcbb52 into your branch? I believe this is the correct way to ignore SSZ responses

sure ! will complete it in a day or two! thanks for the same!

@rkapka
Copy link
Contributor

rkapka commented Jul 9, 2025

Also the PR has some conflicts now @rose2221

@rose2221
Copy link
Contributor Author

Also the PR has some conflicts now @rose2221

i've applied the changes as suggested! thanks very much for the same!

@rose2221 rose2221 requested a review from rkapka July 11, 2025 23:01
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.

server ignores request to gzip data
4 participants