Module: Angus::Remote::ProxyClientUtils
- Defined in:
- lib/angus/remote/proxy_client_utils.rb
Constant Summary collapse
- ALLOWED_RESPONSE_HEADERS =
['content-type']
Class Method Summary collapse
- .build_request(method, path, query, headers = {}, body = nil) ⇒ Object
- .filter_response_headers(headers) ⇒ Object
-
.normalize_headers(headers) ⇒ Hash
Converts any header value that is an array to its first value.
Class Method Details
.build_request(method, path, query, headers = {}, body = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/angus/remote/proxy_client_utils.rb', line 14 def self.build_request(method, path, query, headers = {}, body = nil) uri = URI(path) uri.query = query full_uri = uri.to_s request = case method.to_s.downcase when 'get' Net::HTTP::Get.new(full_uri) when 'post' Net::HTTP::Post.new(full_uri) when 'put' Net::HTTP::Put.new(full_uri) when 'delete' Net::HTTP::Delete.new(full_uri) else raise MethodArgumentError.new(method) end headers.each do |k, v| request[k] = v end request.body = body request end |
.filter_response_headers(headers) ⇒ Object
42 43 44 |
# File 'lib/angus/remote/proxy_client_utils.rb', line 42 def self.filter_response_headers(headers) headers.select { |h, v| ALLOWED_RESPONSE_HEADERS.include?(h) } end |
.normalize_headers(headers) ⇒ Hash
Converts any header value that is an array to its first value.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/angus/remote/proxy_client_utils.rb', line 56 def self.normalize_headers(headers) normalized = headers.map do |h, v| if v.is_a?(Array) [h, v.first] else [h, v] end end Hash[normalized] end |