Skip to content

Commit eed1143

Browse files
committed
moved encoding to the http methods
1 parent 1817b17 commit eed1143

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

lib/http_client/client.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ def initialize(options = {})
1414
@response_handler = BasicResponseHandler.new
1515
end
1616

17-
@encoding = options[:encoding] || "UTF-8"
18-
1917
@client = HTTP::ClientConfiguration.new(options).build_http_client
2018
end
2119

@@ -38,7 +36,7 @@ def put(path)
3836
end
3937

4038
def execute(request)
41-
request.make_native_request(@client, @encoding, @response_handler)
39+
request.make_native_request(@client, @response_handler)
4240
rescue SocketTimeoutException => e
4341
raise Timeout::Error, e.message
4442
end

lib/http_client/methods.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ module HTTP
44
class Request
55
def self.create_type(&native_request_factory)
66
Class.new do
7+
attr_accessor :body, :encoding
8+
79
def initialize(uri, params = {})
810
@uri = uri
911
@params = params
12+
@encoding = "UTF-8"
13+
1014
@headers = {}
1115
end
1216

@@ -18,17 +22,13 @@ def content_type=(type)
1822
add_headers({'content-type' => type})
1923
end
2024

21-
def body=(request_body)
22-
@body = request_body
23-
end
24-
2525
def basic_auth(username, password)
2626
@username = username
2727
@password = password
2828
end
2929

30-
def make_native_request(client, encoding, handler=nil)
31-
request = create_native_request(encoding)
30+
def make_native_request(client, handler=nil)
31+
request = create_native_request
3232
request.entity = StringEntity.new(@body) unless @body.nil?
3333

3434
unless @username.nil?
@@ -50,12 +50,12 @@ def parse_uri
5050
end
5151

5252
private
53-
define_method(:create_native_request) do |encoding|
53+
define_method(:create_native_request) do
5454
scheme, host, port, path, query = parse_uri
5555
query_params = CGI.parse(query || "").merge(@params)
5656

5757
params = query_params.collect { |key, value| BasicNameValuePair.new(key.to_s, value.to_s) }
58-
request = native_request_factory.call(scheme, host, port, path, params, encoding)
58+
request = native_request_factory.call(scheme, host, port, path, params, @encoding)
5959

6060
@headers.each { |name, value| request.add_header(name.to_s, value.to_s) }
6161

0 commit comments

Comments
 (0)