-
Notifications
You must be signed in to change notification settings - Fork 0
Remove accept encoding gzip try #61
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| require_relative "../storage_helper" | ||
|
|
||
| describe "Accept-Encoding" do | ||
|
|
||
| class HeaderRecorder | ||
| def self.captured_headers | ||
| @captured_headers ||= [] | ||
| end | ||
|
|
||
| def self.clear_headers! | ||
| @captured_headers = [] | ||
| end | ||
|
|
||
| def initialize(app) | ||
| @app = app | ||
| end | ||
|
|
||
| def call(env) | ||
| self.class.captured_headers << env.request_headers | ||
| @app.call(env) | ||
| end | ||
| end | ||
|
|
||
| before do | ||
| @fresh_storage = Google::Cloud::Storage.new | ||
| @client = @fresh_storage.service.service.client | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why these many service.service.client |
||
| @client.builder.insert_before(0, HeaderRecorder) | ||
|
|
||
| # Start every test with a clean slate | ||
| HeaderRecorder.clear_headers! | ||
| end | ||
|
|
||
| after do | ||
| @client.builder.delete(HeaderRecorder) rescue nil | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the community Ruby Style Guide, using the inline @client&.builder&.delete(HeaderRecorder)References
|
||
| end | ||
|
|
||
| it "does not include Accept-Encoding gzip header on metadata calls" do | ||
| @fresh_storage.buckets(max: 1) | ||
|
|
||
| refute_empty HeaderRecorder.captured_headers | ||
| HeaderRecorder.captured_headers.each do |headers| | ||
| assert_nil headers["Accept-Encoding"] | ||
| end | ||
| end | ||
|
|
||
| it "includes Accept-Encoding gzip header on media calls (upload/download)" do | ||
| bucket_name = "gcloud-test-ae-#{Time.now.to_i}-#{SecureRandom.hex(4)}" | ||
| bucket = @fresh_storage.create_bucket(bucket_name) | ||
|
|
||
| begin | ||
| # Clear the headers generated by the bucket creation above | ||
| HeaderRecorder.clear_headers! | ||
|
|
||
| # Test Upload | ||
| file = bucket.create_file(StringIO.new("hello world"), "test.txt") | ||
| upload_headers = HeaderRecorder.captured_headers.map { |h| h["Accept-Encoding"] } | ||
| assert_includes upload_headers, "gzip" | ||
|
|
||
| # Clear headers before the next action | ||
| HeaderRecorder.clear_headers! | ||
|
|
||
| # Test Download | ||
| file.download | ||
| download_headers = HeaderRecorder.captured_headers.map { |h| h["Accept-Encoding"] } | ||
|
|
||
| assert_includes download_headers, "gzip" | ||
| ensure | ||
| # Cleanup | ||
| safe_gcs_execute { file&.delete } | ||
| safe_gcs_execute { bucket&.delete } | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,11 @@ def creds.is_a? target | |
| _(project.universe_domain).must_equal "googleapis.com" | ||
| end | ||
|
|
||
| it "does not set Accept-Encoding gzip header by default" do | ||
| service = Google::Cloud::Storage::Service.new "my-project", default_credentials | ||
| _(service.service.request_options.header["Accept-Encoding"]).must_be :nil? | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Minitest, it is more idiomatic and readable to use the built-in _(service.service.request_options.header["Accept-Encoding"]).must_be_nilReferences
|
||
| end | ||
|
|
||
| it "supports setting a universe domain argument" do | ||
| service = Google::Cloud::Storage::Service.new "my-project", default_credentials, universe_domain: "mydomain1.com" | ||
| _(service.universe_domain).must_equal "mydomain1.com" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove fresh_storage, add some name like storage like that