Skip to content

Commit

Permalink
refactor: change config name to capitalize_headers
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanSiqueira committed Nov 7, 2023
1 parent f2cd8e7 commit d688a13
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions lib/net/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,10 @@ class HTTPHeaderSyntaxError < StandardError; end
# Returns the write timeout.
# - {write_timeout=}[rdoc-ref:Net::HTTP#write_timeout=]:
# Sets the write timeout.
# - {:preserve_headers}[rdoc-ref:Net::HTTP#preserve_headers]:
# Returns the open timeout.
# - {:preserve_headers=}[rdoc-ref:Net::HTTP#preserve_headers=]:
# Sets the read timeout.
# - {:capitalize_headers}[rdoc-ref:Net::HTTP#capitalize_headers]:
# Returns the capitalize_headers config.
# - {:capitalize_headers=}[rdoc-ref:Net::HTTP#capitalize_headers=]:
# Sets the capitalize_headers config.
#
# === Requests
#
Expand Down Expand Up @@ -1127,7 +1127,7 @@ def initialize(address, port = nil) # :nodoc:
@ssl_context = nil
@ssl_session = nil
@sspi_enabled = false
@preserve_headers = false
@capitalize_headers = true
SSL_IVNAMES.each do |ivname|
instance_variable_set ivname, nil
end
Expand Down Expand Up @@ -1537,8 +1537,8 @@ def use_ssl=(flag)
# See {OpenSSL::SSL::SSLContext#verify_hostname=}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#attribute-i-verify_mode].
attr_accessor :verify_hostname

# Sets or returns whether to preserve the headers case
attr_accessor :preserve_headers
# Sets or returns whether to capitalize the headers
attr_accessor :capitalize_headers

# Returns the X509 certificate chain (an array of strings)
# for the session's socket peer,
Expand Down Expand Up @@ -2308,7 +2308,7 @@ def request(req, body = nil, &block) # :yield: +response+
return request(req, body, &block)
}
end
req.preserve_headers = preserve_headers
req.capitalize_headers = capitalize_headers
if proxy_user()
req.proxy_basic_auth proxy_user(), proxy_pass() unless use_ssl?
end
Expand Down
12 changes: 6 additions & 6 deletions lib/net/http/generic_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def initialize(m, reqbody, resbody, uri_or_path, initheader = nil) # :nodoc:
@body = nil
@body_stream = nil
@body_data = nil
@preserve_headers = false
@capitalize_headers = true
end

# Returns the string method name for the request:
Expand Down Expand Up @@ -95,8 +95,8 @@ def initialize(m, reqbody, resbody, uri_or_path, initheader = nil) # :nodoc:
#
attr_reader :decode_content

# Sets if will preserve case from headers
attr_accessor :preserve_headers
# Sets if will capitalize headers
attr_accessor :capitalize_headers

# Returns a string representation of the request:
#
Expand Down Expand Up @@ -407,12 +407,12 @@ def write_header(sock, ver, path)
end
buf = +''
buf << reqline << "\r\n"
if preserve_headers
each_header do |k,v|
if capitalize_headers
each_capitalized do |k,v|
buf << "#{k}: #{v}\r\n"
end
else
each_capitalized do |k,v|
each_header do |k,v|
buf << "#{k}: #{v}\r\n"
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/net/http/test_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ def test_partial_response
assert_raise(EOFError) {http.get('/')}
end

def test_no_preserved_headers
def test_capitalized_headers
headers = { accept: '*/*' }
expected_raw_header = "Accept: */*\r\n"
@server.mount_proc('/') do |req, _res|
Expand All @@ -1379,15 +1379,15 @@ def test_no_preserved_headers
http.get('/', headers)
end

def test_preserved_headers
def test_no_capitalized_headers
headers = { accept: '*/*' }
expected_raw_header = "accept: */*\r\n"
@server.mount_proc('/') do |req, _res|
assert_includes(req.raw_header, expected_raw_header)
end

http = Net::HTTP.new(config('host'), config('port'))
http.preserve_headers = true
http.capitalize_headers = false
http.get('/', headers)
end
end

0 comments on commit d688a13

Please sign in to comment.