httparty 0.17.3 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HTTParty
2
4
  # The default parser used by HTTParty, supports xml, json, html, csv and
3
5
  # plain text.
@@ -101,7 +103,7 @@ module HTTParty
101
103
  # @return [nil] when the response body is nil, an empty string, spaces only or "null"
102
104
  def parse
103
105
  return nil if body.nil?
104
- return nil if body == "null"
106
+ return nil if body == 'null'
105
107
  return nil if body.valid_encoding? && body.strip.empty?
106
108
  if body.valid_encoding? && body.encoding == Encoding::UTF_8
107
109
  @body = body.gsub(/\A#{UTF8_BOM}/, '')
@@ -116,16 +118,19 @@ module HTTParty
116
118
  protected
117
119
 
118
120
  def xml
121
+ require 'multi_xml'
119
122
  MultiXml.parse(body)
120
123
  end
121
124
 
122
- UTF8_BOM = "\xEF\xBB\xBF".freeze
125
+ UTF8_BOM = "\xEF\xBB\xBF"
123
126
 
124
127
  def json
128
+ require 'json'
125
129
  JSON.parse(body, :quirks_mode => true, :allow_nan => true)
126
130
  end
127
131
 
128
132
  def csv
133
+ require 'csv'
129
134
  CSV.parse(body)
130
135
  end
131
136
 
@@ -142,9 +147,11 @@ module HTTParty
142
147
  end
143
148
 
144
149
  def parse_supported_format
145
- send(format)
146
- rescue NoMethodError => e
147
- raise NotImplementedError, "#{self.class.name} has not implemented a parsing method for the #{format.inspect} format.", e.backtrace
150
+ if respond_to?(format, true)
151
+ send(format)
152
+ else
153
+ raise NotImplementedError, "#{self.class.name} has not implemented a parsing method for the #{format.inspect} format."
154
+ end
148
155
  end
149
156
  end
150
157
  end
@@ -1,8 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'multipart_boundary'
2
4
 
3
5
  module HTTParty
4
6
  class Request
5
7
  class Body
8
+ NEWLINE = "\r\n"
9
+ private_constant :NEWLINE
10
+
6
11
  def initialize(params, query_string_normalizer: nil, force_multipart: false)
7
12
  @params = params
8
13
  @query_string_normalizer = query_string_normalizer
@@ -27,23 +32,30 @@ module HTTParty
27
32
 
28
33
  private
29
34
 
35
+ # https://html.spec.whatwg.org/#multipart-form-data
36
+ MULTIPART_FORM_DATA_REPLACEMENT_TABLE = {
37
+ '"' => '%22',
38
+ "\r" => '%0D',
39
+ "\n" => '%0A'
40
+ }.freeze
41
+
30
42
  def generate_multipart
31
43
  normalized_params = params.flat_map { |key, value| HashConversions.normalize_keys(key, value) }
32
44
 
33
- multipart = normalized_params.inject('') do |memo, (key, value)|
34
- memo += "--#{boundary}\r\n"
35
- memo += %(Content-Disposition: form-data; name="#{key}")
45
+ multipart = normalized_params.inject(''.dup) do |memo, (key, value)|
46
+ memo << "--#{boundary}#{NEWLINE}"
47
+ memo << %(Content-Disposition: form-data; name="#{key}")
36
48
  # value.path is used to support ActionDispatch::Http::UploadedFile
37
49
  # https://github.com/jnunemaker/httparty/pull/585
38
- memo += %(; filename="#{file_name(value)}") if file?(value)
39
- memo += "\r\n"
40
- memo += "Content-Type: #{content_type(value)}\r\n" if file?(value)
41
- memo += "\r\n"
42
- memo += file?(value) ? value.read : value.to_s
43
- memo += "\r\n"
50
+ memo << %(; filename="#{file_name(value).gsub(/["\r\n]/, MULTIPART_FORM_DATA_REPLACEMENT_TABLE)}") if file?(value)
51
+ memo << NEWLINE
52
+ memo << "Content-Type: #{content_type(value)}#{NEWLINE}" if file?(value)
53
+ memo << NEWLINE
54
+ memo << content_body(value)
55
+ memo << NEWLINE
44
56
  end
45
57
 
46
- multipart += "--#{boundary}--\r\n"
58
+ multipart << "--#{boundary}--#{NEWLINE}"
47
59
  end
48
60
 
49
61
  def has_file?(value)
@@ -68,10 +80,20 @@ module HTTParty
68
80
  end
69
81
  end
70
82
 
83
+ def content_body(object)
84
+ if file?(object)
85
+ object = (file = object).read
86
+ file.rewind if file.respond_to?(:rewind)
87
+ end
88
+
89
+ object.to_s
90
+ end
91
+
71
92
  def content_type(object)
72
93
  return object.content_type if object.respond_to?(:content_type)
73
- mime = MIME::Types.type_for(object.path)
74
- mime.empty? ? 'application/octet-stream' : mime[0].content_type
94
+ require 'mini_mime'
95
+ mime = MiniMime.lookup_by_filename(object.path)
96
+ mime ? mime.content_type : 'application/octet-stream'
75
97
  end
76
98
 
77
99
  def file_name(object)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'securerandom'
2
4
 
3
5
  module HTTParty
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'erb'
2
4
 
3
5
  module HTTParty
@@ -44,6 +46,15 @@ module HTTParty
44
46
  end.flatten.join('&')
45
47
  end
46
48
 
49
+ def self._load(data)
50
+ http_method, path, options, last_response, last_uri, raw_request = Marshal.load(data)
51
+ instance = new(http_method, path, options)
52
+ instance.last_response = last_response
53
+ instance.last_uri = last_uri
54
+ instance.instance_variable_set("@raw_request", raw_request)
55
+ instance
56
+ end
57
+
47
58
  attr_accessor :http_method, :options, :last_response, :redirect, :last_uri
48
59
  attr_reader :path
49
60
 
@@ -87,11 +98,11 @@ module HTTParty
87
98
  end
88
99
 
89
100
  def uri
90
- if redirect && path.relative? && path.path[0] != "/"
91
- last_uri_host = @last_uri.path.gsub(/[^\/]+$/, "")
101
+ if redirect && path.relative? && path.path[0] != '/'
102
+ last_uri_host = @last_uri.path.gsub(/[^\/]+$/, '')
92
103
 
93
- path.path = "/#{path.path}" if last_uri_host[-1] != "/"
94
- path.path = last_uri_host + path.path
104
+ path.path = "/#{path.path}" if last_uri_host[-1] != '/'
105
+ path.path = "#{last_uri_host}#{path.path}"
95
106
  end
96
107
 
97
108
  if path.relative? && path.host
@@ -117,7 +128,7 @@ module HTTParty
117
128
  def base_uri
118
129
  if redirect
119
130
  base_uri = "#{@last_uri.scheme}://#{@last_uri.host}"
120
- base_uri += ":#{@last_uri.port}" if @last_uri.port != 80
131
+ base_uri = "#{base_uri}:#{@last_uri.port}" if @last_uri.port != 80
121
132
  base_uri
122
133
  else
123
134
  options[:base_uri] && HTTParty.normalize_base_uri(options[:base_uri])
@@ -173,6 +184,13 @@ module HTTParty
173
184
  @raw_request.body
174
185
  end
175
186
 
187
+ def _dump(_level)
188
+ opts = options.dup
189
+ opts.delete(:logger)
190
+ opts.delete(:parser) if opts[:parser] && opts[:parser].is_a?(Proc)
191
+ Marshal.dump([http_method, path, opts, last_response, @last_uri, @raw_request])
192
+ end
193
+
176
194
  private
177
195
 
178
196
  def http
@@ -204,22 +222,15 @@ module HTTParty
204
222
  end
205
223
 
206
224
  def setup_raw_request
207
- @raw_request = http_method.new(request_uri(uri))
208
- @raw_request.body_stream = options[:body_stream] if options[:body_stream]
209
-
210
225
  if options[:headers].respond_to?(:to_hash)
211
226
  headers_hash = options[:headers].to_hash
212
-
213
- @raw_request.initialize_http_header(headers_hash)
214
- # If the caller specified a header of 'Accept-Encoding', assume they want to
215
- # deal with encoding of content. Disable the internal logic in Net:HTTP
216
- # that handles encoding, if the platform supports it.
217
- if @raw_request.respond_to?(:decode_content) && (headers_hash.key?('Accept-Encoding') || headers_hash.key?('accept-encoding'))
218
- # Using the '[]=' sets decode_content to false
219
- @raw_request['accept-encoding'] = @raw_request['accept-encoding']
220
- end
227
+ else
228
+ headers_hash = nil
221
229
  end
222
230
 
231
+ @raw_request = http_method.new(request_uri(uri), headers_hash)
232
+ @raw_request.body_stream = options[:body_stream] if options[:body_stream]
233
+
223
234
  if options[:body]
224
235
  body = Body.new(
225
236
  options[:body],
@@ -234,6 +245,8 @@ module HTTParty
234
245
  @raw_request.body = body.call
235
246
  end
236
247
 
248
+ @raw_request.instance_variable_set(:@decode_content, decompress_content?)
249
+
237
250
  if options[:basic_auth] && send_authorization_header?
238
251
  @raw_request.basic_auth(username, password)
239
252
  @credentials_sent = true
@@ -245,6 +258,10 @@ module HTTParty
245
258
  !!options[:digest_auth]
246
259
  end
247
260
 
261
+ def decompress_content?
262
+ !options[:skip_decompression]
263
+ end
264
+
248
265
  def response_unauthorized?
249
266
  !!last_response && last_response.code == '401'
250
267
  end
@@ -268,7 +285,7 @@ module HTTParty
268
285
  query_string_parts << options[:query] unless options[:query].nil?
269
286
  end
270
287
 
271
- query_string_parts.reject!(&:empty?) unless query_string_parts == [""]
288
+ query_string_parts.reject!(&:empty?) unless query_string_parts == ['']
272
289
  query_string_parts.size > 0 ? query_string_parts.join('&') : nil
273
290
  end
274
291
 
@@ -276,37 +293,55 @@ module HTTParty
276
293
  options[:assume_utf16_is_big_endian]
277
294
  end
278
295
 
279
- def handle_response(body, &block)
296
+ def handle_response(raw_body, &block)
280
297
  if response_redirects?
281
- options[:limit] -= 1
282
- if options[:logger]
283
- logger = HTTParty::Logger.build(options[:logger], options[:log_level], options[:log_format])
284
- logger.format(self, last_response)
285
- end
286
- self.path = last_response['location']
287
- self.redirect = true
288
- if last_response.class == Net::HTTPSeeOther
289
- unless options[:maintain_method_across_redirects] && options[:resend_on_redirect]
290
- self.http_method = Net::HTTP::Get
291
- end
292
- elsif last_response.code != '307' && last_response.code != '308'
293
- unless options[:maintain_method_across_redirects]
294
- self.http_method = Net::HTTP::Get
298
+ handle_redirection(&block)
299
+ else
300
+ raw_body ||= last_response.body
301
+
302
+ body = decompress(raw_body, last_response['content-encoding']) unless raw_body.nil?
303
+
304
+ unless body.nil?
305
+ body = encode_text(body, last_response['content-type'])
306
+
307
+ if decompress_content?
308
+ last_response.delete('content-encoding')
309
+ raw_body = body
295
310
  end
296
311
  end
297
- capture_cookies(last_response)
298
- perform(&block)
299
- else
300
- body ||= last_response.body
301
- body = body.nil? ? body : encode_text(body, last_response['content-type'])
302
- Response.new(self, last_response, lambda { parse_response(body) }, body: body)
312
+
313
+ Response.new(self, last_response, lambda { parse_response(body) }, body: raw_body)
303
314
  end
304
315
  end
305
316
 
317
+ def handle_redirection(&block)
318
+ options[:limit] -= 1
319
+ if options[:logger]
320
+ logger = HTTParty::Logger.build(options[:logger], options[:log_level], options[:log_format])
321
+ logger.format(self, last_response)
322
+ end
323
+ self.path = last_response['location']
324
+ self.redirect = true
325
+ if last_response.class == Net::HTTPSeeOther
326
+ unless options[:maintain_method_across_redirects] && options[:resend_on_redirect]
327
+ self.http_method = Net::HTTP::Get
328
+ end
329
+ elsif last_response.code != '307' && last_response.code != '308'
330
+ unless options[:maintain_method_across_redirects]
331
+ self.http_method = Net::HTTP::Get
332
+ end
333
+ end
334
+ if http_method == Net::HTTP::Get
335
+ clear_body
336
+ end
337
+ capture_cookies(last_response)
338
+ perform(&block)
339
+ end
340
+
306
341
  def handle_host_redirection
307
342
  check_duplicate_location_header
308
343
  redirect_path = options[:uri_adapter].parse(last_response['location']).normalize
309
- return if redirect_path.relative? || path.host == redirect_path.host
344
+ return if redirect_path.relative? || path.host == redirect_path.host || uri.host == redirect_path.host
310
345
  @changed_hosts = true
311
346
  end
312
347
 
@@ -334,6 +369,14 @@ module HTTParty
334
369
  parser.call(body, format)
335
370
  end
336
371
 
372
+ # Some Web Application Firewalls reject incoming GET requests that have a body
373
+ # if we redirect, and the resulting verb is GET then we will clear the body that
374
+ # may be left behind from the initiating request
375
+ def clear_body
376
+ options[:body] = nil
377
+ @raw_request.body = nil
378
+ end
379
+
337
380
  def capture_cookies(response)
338
381
  return unless response['Set-Cookie']
339
382
  cookies_hash = HTTParty::CookieHash.new
@@ -375,6 +418,10 @@ module HTTParty
375
418
  end
376
419
  end
377
420
 
421
+ def decompress(body, encoding)
422
+ Decompressor.new(body, encoding).decompress
423
+ end
424
+
378
425
  def encode_text(text, content_type)
379
426
  TextEncoder.new(
380
427
  text,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'delegate'
2
4
 
3
5
  module HTTParty
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HTTParty
2
4
  class Response < Object
3
5
  def self.underscore(string)
@@ -49,14 +51,14 @@ module HTTParty
49
51
  end
50
52
 
51
53
  def inspect
52
- inspect_id = ::Kernel::format "%x", (object_id * 2)
54
+ inspect_id = ::Kernel::format '%x', (object_id * 2)
53
55
  %(#<#{self.class}:0x#{inspect_id} parsed_response=#{parsed_response.inspect}, @response=#{response.inspect}, @headers=#{headers.inspect}>)
54
56
  end
55
57
 
56
58
  CODES_TO_OBJ = ::Net::HTTPResponse::CODE_CLASS_TO_OBJ.merge ::Net::HTTPResponse::CODE_TO_OBJ
57
59
 
58
60
  CODES_TO_OBJ.each do |response_code, klass|
59
- name = klass.name.sub("Net::HTTP", '')
61
+ name = klass.name.sub('Net::HTTP', '')
60
62
  name = "#{underscore(name)}?".to_sym
61
63
 
62
64
  define_method(name) do
@@ -65,12 +67,12 @@ module HTTParty
65
67
  end
66
68
 
67
69
  # Support old multiple_choice? method from pre 2.0.0 era.
68
- if ::RUBY_VERSION >= "2.0.0" && ::RUBY_PLATFORM != "java"
70
+ if ::RUBY_PLATFORM != 'java'
69
71
  alias_method :multiple_choice?, :multiple_choices?
70
72
  end
71
73
 
72
74
  # Support old status codes method from pre 2.6.0 era.
73
- if ::RUBY_VERSION >= "2.6.0" && ::RUBY_PLATFORM != "java"
75
+ if ::RUBY_PLATFORM != 'java'
74
76
  alias_method :gateway_time_out?, :gateway_timeout?
75
77
  alias_method :request_entity_too_large?, :payload_too_large?
76
78
  alias_method :request_time_out?, :request_timeout?
@@ -131,7 +133,7 @@ module HTTParty
131
133
  end
132
134
 
133
135
  def throw_exception
134
- if @request.options[:raise_on] && @request.options[:raise_on].include?(code)
136
+ if @request.options[:raise_on].to_a.detect { |c| code.to_s.match(/#{c.to_s}/) }
135
137
  ::Kernel.raise ::HTTParty::ResponseError.new(@response), "Code #{code} - #{body}"
136
138
  end
137
139
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'delegate'
2
4
 
3
5
  module HTTParty
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HTTParty
2
4
  class TextEncoder
3
5
  attr_reader :text, :content_type, :assume_utf16_is_big_endian
4
6
 
5
7
  def initialize(text, assume_utf16_is_big_endian: true, content_type: nil)
6
- @text = text.dup
8
+ @text = +text
7
9
  @content_type = content_type
8
10
  @assume_utf16_is_big_endian = assume_utf16_is_big_endian
9
11
  end
@@ -33,16 +35,16 @@ module HTTParty
33
35
  def encode_utf_16
34
36
  if text.bytesize >= 2
35
37
  if text.getbyte(0) == 0xFF && text.getbyte(1) == 0xFE
36
- return text.force_encoding("UTF-16LE")
38
+ return text.force_encoding('UTF-16LE')
37
39
  elsif text.getbyte(0) == 0xFE && text.getbyte(1) == 0xFF
38
- return text.force_encoding("UTF-16BE")
40
+ return text.force_encoding('UTF-16BE')
39
41
  end
40
42
  end
41
43
 
42
44
  if assume_utf16_is_big_endian # option
43
- text.force_encoding("UTF-16BE")
45
+ text.force_encoding('UTF-16BE')
44
46
  else
45
- text.force_encoding("UTF-16LE")
47
+ text.force_encoding('UTF-16LE')
46
48
  end
47
49
  end
48
50
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HTTParty
2
4
  module Utils
3
5
  def self.stringify_keys(hash)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HTTParty
2
- VERSION = "0.17.3"
4
+ VERSION = '0.22.0'
3
5
  end
data/lib/httparty.rb CHANGED
@@ -1,12 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
  require 'net/http'
3
- require 'net/https'
4
5
  require 'uri'
5
- require 'zlib'
6
- require 'multi_xml'
7
- require 'mime/types'
8
- require 'json'
9
- require 'csv'
10
6
 
11
7
  require 'httparty/module_inheritable_attributes'
12
8
  require 'httparty/cookie_hash'
@@ -16,6 +12,7 @@ require 'httparty/connection_adapter'
16
12
  require 'httparty/logger/logger'
17
13
  require 'httparty/request/body'
18
14
  require 'httparty/response_fragment'
15
+ require 'httparty/decompressor'
19
16
  require 'httparty/text_encoder'
20
17
  require 'httparty/headers_processor'
21
18
 
@@ -26,8 +23,8 @@ module HTTParty
26
23
  base.send :include, ModuleInheritableAttributes
27
24
  base.send(:mattr_inheritable, :default_options)
28
25
  base.send(:mattr_inheritable, :default_cookies)
29
- base.instance_variable_set("@default_options", {})
30
- base.instance_variable_set("@default_cookies", CookieHash.new)
26
+ base.instance_variable_set(:@default_options, {})
27
+ base.instance_variable_set(:@default_cookies, CookieHash.new)
31
28
  end
32
29
 
33
30
  # == Common Request Options
@@ -41,11 +38,11 @@ module HTTParty
41
38
  # [:+limit+:] Maximum number of redirects to follow. Takes precedences over :+no_follow+.
42
39
  # [:+query+:] Query string, or an object that responds to #to_hash representing it. Normalized according to the same rules as :+body+. If you specify this on a POST, you must use an object which responds to #to_hash. See also HTTParty::ClassMethods.default_params.
43
40
  # [:+timeout+:] Timeout for opening connection and reading data.
44
- # [:+local_host:] Local address to bind to before connecting.
45
- # [:+local_port:] Local port to bind to before connecting.
46
- # [:+body_stream:] Allow streaming to a REST server to specify a body_stream.
47
- # [:+stream_body:] Allow for streaming large files without loading them into memory.
48
- # [:+multipart:] Force content-type to be multipart
41
+ # [:+local_host+:] Local address to bind to before connecting.
42
+ # [:+local_port+:] Local port to bind to before connecting.
43
+ # [:+body_stream+:] Allow streaming to a REST server to specify a body_stream.
44
+ # [:+stream_body+:] Allow for streaming large files without loading them into memory.
45
+ # [:+multipart+:] Force content-type to be multipart
49
46
  #
50
47
  # There are also another set of options with names corresponding to various class methods. The methods in question are those that let you set a class-wide default, and the options override the defaults on a request-by-request basis. Those options are:
51
48
  # * :+base_uri+: see HTTParty::ClassMethods.base_uri.
@@ -81,7 +78,7 @@ module HTTParty
81
78
  #
82
79
  # class Foo
83
80
  # include HTTParty
84
- # raise_on [404, 500]
81
+ # raise_on [404, 500, '5[0-9]*']
85
82
  # end
86
83
  def raise_on(codes = [])
87
84
  default_options[:raise_on] = *codes
@@ -399,6 +396,22 @@ module HTTParty
399
396
  default_options[:ssl_version] = version
400
397
  end
401
398
 
399
+ # Deactivate automatic decompression of the response body.
400
+ # This will require you to explicitly handle body decompression
401
+ # by inspecting the Content-Encoding response header.
402
+ #
403
+ # Refer to docs/README.md "HTTP Compression" section for
404
+ # further details.
405
+ #
406
+ # @example
407
+ # class Foo
408
+ # include HTTParty
409
+ # skip_decompression
410
+ # end
411
+ def skip_decompression(value = true)
412
+ default_options[:skip_decompression] = !!value
413
+ end
414
+
402
415
  # Allows setting of SSL ciphers to use. This only works in Ruby 1.9+.
403
416
  # You can get a list of valid specific ciphers from OpenSSL::Cipher.ciphers.
404
417
  # You also can specify a cipher suite here, listed here at openssl.org:
@@ -573,6 +586,13 @@ module HTTParty
573
586
  perform_request Net::HTTP::Unlock, path, options, &block
574
587
  end
575
588
 
589
+ def build_request(http_method, path, options = {})
590
+ options = ModuleInheritableAttributes.hash_deep_dup(default_options).merge(options)
591
+ HeadersProcessor.new(headers, options).call
592
+ process_cookies(options)
593
+ Request.new(http_method, path, options)
594
+ end
595
+
576
596
  attr_reader :default_options
577
597
 
578
598
  private
@@ -588,16 +608,13 @@ module HTTParty
588
608
  end
589
609
 
590
610
  def perform_request(http_method, path, options, &block) #:nodoc:
591
- options = ModuleInheritableAttributes.hash_deep_dup(default_options).merge(options)
592
- HeadersProcessor.new(headers, options).call
593
- process_cookies(options)
594
- Request.new(http_method, path, options).perform(&block)
611
+ build_request(http_method, path, options).perform(&block)
595
612
  end
596
613
 
597
614
  def process_cookies(options) #:nodoc:
598
615
  return unless options[:cookies] || default_cookies.any?
599
616
  options[:headers] ||= headers.dup
600
- options[:headers]["cookie"] = cookies.merge(options.delete(:cookies) || {}).to_cookie_string
617
+ options[:headers]['cookie'] = cookies.merge(options.delete(:cookies) || {}).to_cookie_string
601
618
  end
602
619
 
603
620
  def validate_format
@@ -658,6 +675,10 @@ module HTTParty
658
675
  def self.options(*args, &block)
659
676
  Basement.options(*args, &block)
660
677
  end
678
+
679
+ def self.build_request(*args, &block)
680
+ Basement.build_request(*args, &block)
681
+ end
661
682
  end
662
683
 
663
684
  require 'httparty/hash_conversions'
data/script/release CHANGED
@@ -18,9 +18,9 @@ gem_name=httparty
18
18
  rm -rf $gem_name-*.gem
19
19
  gem build -q $gem_name.gemspec
20
20
 
21
- # Make sure we're on the master branch.
22
- (git branch | grep -q '* master') || {
23
- echo "Only release from the master branch."
21
+ # Make sure we're on the main branch.
22
+ (git branch | grep -q '* main') || {
23
+ echo "Only release from the main branch."
24
24
  exit 1
25
25
  }
26
26
 
@@ -39,4 +39,4 @@ git fetch -t origin
39
39
 
40
40
  # Tag it and bag it.
41
41
  gem push $gem_name-*.gem && git tag "$tag" &&
42
- git push origin master && git push origin "$tag"
42
+ git push origin main && git push origin "$tag"