Skip to content

Commit 6923bce

Browse files
committed
Add option to disable gzip compression
1 parent b64959c commit 6923bce

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_send_app_size_metrics.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def self.run(params)
3737
# Send the payload
3838
payload.send_metrics(
3939
base_url: base_url,
40-
api_token: api_token
40+
api_token: api_token,
41+
use_gzip: params[:use_gzip_content_encoding]
4142
)
4243
end
4344

@@ -84,6 +85,13 @@ def self.available_options
8485
type: String,
8586
optional: true
8687
),
88+
FastlaneCore::ConfigItem.new(
89+
key: :use_gzip_content_encoding,
90+
env_name: 'FL_IOS_SEND_APP_SIZE_METRICS_USE_GZIP_CONTENT_ENCODING',
91+
description: 'Specify that we should use `Content-Encoding: gzip` and gzipped body when sending the request',
92+
type: FastlaneCore::Boolean,
93+
default_value: true
94+
),
8795
FastlaneCore::ConfigItem.new(
8896
key: :app_name,
8997
env_name: 'FL_IOS_SEND_APP_SIZE_METRICS_APP_NAME',

lib/fastlane/plugin/wpmreleasetoolkit/models/app_size_metrics_payload.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def to_h
4747
# @param [String] api_token The API bearer token to use to register the metric.
4848
# @return [Integer] the HTTP response code
4949
#
50-
def send_metrics(base_url:, api_token:)
50+
def send_metrics(base_url:, api_token:, use_gzip: true)
5151
uri = URI(base_url)
5252
# Allow using a `file:` URI for debugging
5353
if uri.is_a?(URI::File)
@@ -60,11 +60,12 @@ def send_metrics(base_url:, api_token:)
6060
headers = {
6161
Authorization: "Bearer #{api_token}",
6262
Accept: 'application/json',
63-
'Content-Type': 'application/json',
64-
'Content-Encoding': 'gzip'
63+
'Content-Type': 'application/json'
6564
}
65+
headers[:'Content-Encoding'] = 'gzip' if use_gzip
66+
6667
request = Net::HTTP::Post.new(uri, headers)
67-
request.body = Zlib.gzip(to_h.to_json)
68+
request.body = use_gzip ? Zlib.gzip(to_h.to_json) : to_h.to_json
6869

6970
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
7071
http.request(request)

0 commit comments

Comments
 (0)