manticore 0.4.3-java → 0.4.4-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e663f9b19e305371f23a33ca105cf960255b53a
4
- data.tar.gz: 6c0dd62a760f11460cf565949632e8dbfa77d117
3
+ metadata.gz: e35496eb223648d01aea2dbe4132d88102b599f6
4
+ data.tar.gz: d87ffe86b45313d8836354c9df4419e3c91c9fd9
5
5
  SHA512:
6
- metadata.gz: f0f65941a497dfa2254d4859bf8528cfc0b299f280a6564556aa3a9f08de4d634a1ef3f488ac467b12ace46a5637a793a65a63ffa290300551019f7b49fd0d1f
7
- data.tar.gz: 3e5766be83ff90fc7bab9b5becdc5801156a1fe06ead3f3dd679ee686c8b9c1994ba12c04f7bb450f6758b9d21b21f7e67f41f979b083ce421feecf721b8880e
6
+ metadata.gz: e03381476da9b771bf8961c0767312639147d4bc15435879144f4d37960dcac693bc07c43ab9c963fefe846df76163569483040230d852e1038dcff58157fd7a
7
+ data.tar.gz: 011f97038fd79f71cb3b734639fa468f3395073efe5697d838543ecbe38f26da94ee005726379fedd54cfac9789d9271169a168b0930b1096568d8d98e5a4901
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,9 +1,20 @@
1
1
  ## v0.5
2
2
 
3
- ### v0.5.0 (pending)
3
+ ### v0.5.0 (pending, hc-4.5 branch)
4
+
5
+ * Upgrade to HTTPClient and HTTPCore 4.5
4
6
 
5
7
  ## v0.4
6
8
 
9
+ ## v0.4.5 (pending, master branch)
10
+
11
+ ## v0.4.4
12
+
13
+ * Manticore now treats post bodies with binary encodings as binary byte lists rather than strings with an encoding
14
+ * Manticore now treats :params as :query for GET, HEAD, and DELETE requests, where :query is not specified, in order to minimize confusion.
15
+ * Deprecated dependency on the Addressable gem. URI building is now done with HTTPClient's utils package instead.
16
+ * Manticore no longer always sets a body and content-length for stubbed responses
17
+
7
18
  ### v0.4.3
8
19
 
9
20
  * Manticore no longer automatically retries all request types. Only non-idempotent requests will be automatically retried by default.
data/README.md CHANGED
@@ -46,11 +46,12 @@ Or install it yourself as:
46
46
  If you don't want to worry about setting up and maintaining client pools, Manticore comes with a facade that you can use to start making requests right away:
47
47
 
48
48
  ```ruby
49
- document_body = Manticore.get("http://www.google.com/").body
49
+ get_body = Manticore.get("http://www.google.com/", query: {q: "kittens"}).body
50
+ post_body = Manticore.post("http://www.google.com/", params: {q: "kittens"}).body
50
51
 
51
52
  # Or
52
53
 
53
- document_body = Manticore.http(:get, "http://www.google.com/").body
54
+ get_body = Manticore.http(:get, "http://www.google.com/").body
54
55
  ```
55
56
 
56
57
  This is threadsafe and automatically backed with a pool, so you can execute `Manticore.get` in multiple threads without harming performance.
data/lib/manticore.rb CHANGED
@@ -17,7 +17,6 @@ require_relative "./jar/manticore-ext"
17
17
  org.manticore.Manticore.new.load(JRuby.runtime, false)
18
18
 
19
19
  require_relative "./manticore/version"
20
- require "addressable/uri"
21
20
 
22
21
  # HTTP client with the body of a lion and the head of a man. Or more simply, the power of Java
23
22
  # with the beauty of Ruby.
@@ -6,7 +6,9 @@ module Manticore
6
6
  # @!macro [new] http_method_shared
7
7
  # @param url [String] URL to request
8
8
  # @param options [Hash]
9
- # @option options [Hash] params Hash of options to pass as request parameters
9
+ # @option options [Hash] query Hash of options to be added to the URL as part of the query string
10
+ # @option options [Hash] params Hash of options to pass as a request body. For GET, HEAD, and DELETE requests,
11
+ # :params will be treated as :query if :query is not present.
10
12
  # @option options [Hash] headers Hash of options to pass as additional request headers
11
13
  # @option options [String] proxy Proxy host in form: http://proxy.org:1234
12
14
  # @option options [Hash] proxy Proxy host in form: {host: 'proxy.org'[, port: 80[, scheme: 'http']]}
@@ -81,6 +83,7 @@ module Manticore
81
83
  include_package "java.security.cert"
82
84
  include_package "java.security.spec"
83
85
  include_package "java.security"
86
+ include_package "org.apache.http.client.utils"
84
87
  java_import "org.apache.http.HttpHost"
85
88
  java_import "javax.net.ssl.SSLContext"
86
89
  java_import "org.manticore.HttpGetWithEntity"
@@ -219,6 +222,7 @@ module Manticore
219
222
  # Perform a HTTP GET request
220
223
  # @macro http_method_shared_sync
221
224
  def get(url, options = {}, &block)
225
+ options = treat_params_as_query(options)
222
226
  request HttpGetWithEntity, url, options, &block
223
227
  end
224
228
 
@@ -231,6 +235,7 @@ module Manticore
231
235
  # Perform a HTTP HEAD request
232
236
  # @macro http_method_shared_sync
233
237
  def head(url, options = {}, &block)
238
+ options = treat_params_as_query(options)
234
239
  request HttpHead, url, options, &block
235
240
  end
236
241
 
@@ -243,6 +248,7 @@ module Manticore
243
248
  # Perform a HTTP DELETE request
244
249
  # @macro http_method_shared_sync
245
250
  def delete(url, options = {}, &block)
251
+ options = treat_params_as_query(options)
246
252
  request HttpDelete, url, options, &block
247
253
  end
248
254
 
@@ -406,19 +412,10 @@ module Manticore
406
412
  end
407
413
 
408
414
  def uri_from_url_and_options(url, options)
409
- uri = Addressable::URI.parse url
410
- if options[:query]
411
- v = uri.query_values || {}
412
- case options[:query]
413
- when Hash
414
- uri.query_values = v.merge options[:query]
415
- when String
416
- uri.query_values = v.merge CGI.parse(options[:query])
417
- else
418
- raise "Queries must be hashes or strings"
419
- end
420
- end
421
- uri
415
+ builder = URIBuilder.new(url)
416
+ pairs = struct_to_name_value_pairs(options[:query])
417
+ builder.add_parameters pairs unless pairs.empty?
418
+ builder.to_string
422
419
  end
423
420
 
424
421
  def request_from_options(klass, url, options)
@@ -427,9 +424,15 @@ module Manticore
427
424
  if ( options[:params] || options[:body] || options[:entity]) &&
428
425
  ( req.instance_of?(HttpPost) || req.instance_of?(HttpPatch) || req.instance_of?(HttpPut) || req.instance_of?(HttpGetWithEntity))
429
426
  if options[:params]
430
- req.set_entity hash_to_entity(options[:params])
427
+ pairs = struct_to_name_value_pairs(options[:params])
428
+ encoding = minimum_encoding_for options[:params].to_s
429
+ req.set_entity UrlEncodedFormEntity.new(pairs, encoding)
431
430
  elsif options[:body]
432
- req.set_entity StringEntity.new(options[:body], minimum_encoding_for(options[:body]))
431
+ if options[:body].encoding == Encoding::ASCII_8BIT
432
+ req.set_entity ByteArrayEntity.new(options[:body].to_java_bytes)
433
+ else
434
+ req.set_entity StringEntity.new(options[:body], minimum_encoding_for(options[:body]))
435
+ end
433
436
  elsif options[:entity]
434
437
  req.set_entity options[:entity]
435
438
  end
@@ -520,14 +523,17 @@ module Manticore
520
523
  end
521
524
  end
522
525
 
523
- def hash_to_entity(hash)
524
- # This is a really stupid way to get the "lowest common denominator" encoding for the options hash
525
- # Is there a better way?
526
- encoding = minimum_encoding_for hash.to_a.flatten.join
527
- pairs = hash.map do |key, val|
528
- BasicNameValuePair.new(key, val)
526
+ def struct_to_name_value_pairs(value, namespace = nil)
527
+ case value
528
+ when nil
529
+ []
530
+ when Hash
531
+ value.flat_map {|key, val| struct_to_name_value_pairs val, namespace ? "#{namespace}[#{key}]" : key }
532
+ when Array
533
+ value.flat_map {|val| struct_to_name_value_pairs val, namespace }
534
+ else
535
+ BasicNameValuePair.new(namespace, value.to_s)
529
536
  end
530
- UrlEncodedFormEntity.new(pairs, encoding)
531
537
  end
532
538
 
533
539
  # Apache HTTP assumes ISO_8859_1 for StringEntities; we'll try to be nice and pass that when possible
@@ -640,6 +646,14 @@ module Manticore
640
646
  KeyStore.get_default_type
641
647
  end
642
648
  end
649
+
650
+ def treat_params_as_query(options)
651
+ if options.key?(:params) && !options.key?(:query)
652
+ options.dup.tap {|o| o[:query] = o.delete(:params) }
653
+ else
654
+ options
655
+ end
656
+ end
643
657
  end
644
658
 
645
659
  class LoggingStandardRetryHandler < Java::OrgApacheHttpImplClient::StandardHttpRequestRetryHandler
@@ -36,11 +36,11 @@ module Manticore
36
36
  stubs[:cookies].keys.each {|key| stubs[:cookies][key] = Array(stubs[:cookies][key]) }
37
37
  end
38
38
  stubs[:code] ||= 200
39
- stubs[:body] ||= "" if stubs[:code] == 200
40
39
 
41
40
  stubs[:headers] ||= {}
42
41
  stubs[:headers] = Hash[*stubs[:headers].flat_map {|k, v| [k.downcase, v] }]
43
- stubs[:headers]["content-length"] = stubs[:body].length.to_s if stubs.key?(:body)
42
+ stubs[:headers]["content-length"] ||= stubs[:body].length.to_s if stubs.key?(:body)
43
+
44
44
  @stubs = stubs
45
45
 
46
46
  self
@@ -1,3 +1,3 @@
1
1
  module Manticore
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
data/manticore.gemspec CHANGED
@@ -25,7 +25,6 @@ Gem::Specification.new do |spec|
25
25
  spec.cert_chain = ['gem-public_cert.pem']
26
26
  end
27
27
 
28
- spec.add_dependency "addressable", "~> 2.3"
29
28
  spec.add_development_dependency "bundler", "~> 1.3"
30
29
  spec.add_development_dependency "rake"
31
30
  end
@@ -377,6 +377,32 @@ describe Manticore::Client do
377
377
  response = client.get(local_server, body: "This is a post body")
378
378
  expect(JSON.load(response.body)["body"]).to eq "This is a post body"
379
379
  end
380
+
381
+ it "can send an array of parameters as :params" do
382
+ response = client.get(local_server, params: {"foo" => ["baz", "bar"], "bar" => {"baz" => ["bin", 1, :b]}})
383
+ j = JSON.load(response.body)
384
+ expect(j["body"]).to eq ""
385
+ expect(j["uri"]["query"]).to include("foo=baz")
386
+ end
387
+
388
+ it "can send an array of parameters as :query" do
389
+ response = client.get(local_server, query: {"foo" => ["baz", "bar"]})
390
+ j = JSON.load(response.body)
391
+ expect(j["body"]).to eq ""
392
+ expect(j["uri"]["query"]).to include("foo=baz")
393
+ end
394
+
395
+ it "sends non-ASCII params" do
396
+ response = client.get(local_server, query: {"∑" => "√"})
397
+ j = JSON.load(response.body)
398
+ expect(CGI.unescape j["uri"]["query"]).to eq "∑=√"
399
+ end
400
+
401
+ it "merges implicit query parameters with explicit ones" do
402
+ response = client.get(local_server + "?foo=bar", query: {"baz" => "bin"})
403
+ j = JSON.load(response.body)
404
+ expect(CGI.parse j["uri"]["query"]).to eq({"foo" => ["bar"], "baz" => ["bin"]})
405
+ end
380
406
  end
381
407
 
382
408
  describe "#post" do
@@ -405,6 +431,12 @@ describe Manticore::Client do
405
431
  expect(CGI.unescape(JSON.load(response.body)["body"])).to eq "∑=√"
406
432
  end
407
433
 
434
+ it "sends a binary body" do
435
+ bytes = [145, 167, 116, 101, 115, 116, 49, 50, 51].pack("c*").encode("binary")
436
+ response = client.post(local_server, body: bytes, headers: {"X-Base64" => "1"})
437
+ expect(Base64.decode64(JSON.load(response.body)["body"])).to eq bytes
438
+ end
439
+
408
440
  it "sends an arbitrary entity" do
409
441
  f = open(__FILE__, "r").to_inputstream
410
442
  multipart_entity = MultipartEntityBuilder.create.add_text_body("foo", "bar").add_binary_body("whatever", f , ContentType::TEXT_PLAIN, __FILE__)
data/spec/spec_helper.rb CHANGED
@@ -72,6 +72,9 @@ def start_server(port = PORT)
72
72
  if request[:headers]["Accept-Encoding"] && request[:headers]["Accept-Encoding"].match("gzip")
73
73
  out = StringIO.new('', "w")
74
74
  io = Zlib::GzipWriter.new(out, 2)
75
+
76
+ request[:body] = Base64.encode64(request[:body]) if request[:headers]["X-Base64"]
77
+
75
78
  io.write JSON.dump(request)
76
79
  io.close
77
80
  payload = out.string
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manticore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: java
6
6
  authors:
7
7
  - Chris Heald
@@ -30,22 +30,8 @@ cert_chain:
30
30
  cnyabLOcGIKZNxvnSfwOuCBnjgoSOyJi/n48n1s+OPB/OmPJoWmhKu2DO4sUb4+K
31
31
  /3Mhp5UWSl9SmDR1
32
32
  -----END CERTIFICATE-----
33
- date: 2015-08-07 00:00:00.000000000 Z
33
+ date: 2015-08-20 00:00:00.000000000 Z
34
34
  dependencies:
35
- - !ruby/object:Gem::Dependency
36
- requirement: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '2.3'
41
- name: addressable
42
- prerelease: false
43
- type: :runtime
44
- version_requirements: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: '2.3'
49
35
  - !ruby/object:Gem::Dependency
50
36
  requirement: !ruby/object:Gem::Requirement
51
37
  requirements:
@@ -150,3 +136,4 @@ test_files:
150
136
  - spec/manticore/stubbed_response_spec.rb
151
137
  - spec/spec_helper.rb
152
138
  - spec/ssl/.keepme
139
+ has_rdoc:
metadata.gz.sig CHANGED
Binary file