amq-protocol 1.7.0 → 1.8.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1186376a08e72a7c0638f0722abfe51156a219a3
4
- data.tar.gz: ea6f5b0d5e17db93da66d452770e54df709c0e77
3
+ metadata.gz: 4ed555f9528be0395d8ba9a11a39e193aa347f89
4
+ data.tar.gz: 345f66cb02153603fb16465bc9edddaf1b2bc63a
5
5
  SHA512:
6
- metadata.gz: b1a755c018b85afbd991fbd569b32ceb49c329a7f33480c4f080f3cb79b3cd521708ba59e312a83aa3ec4ef441c592ad9348caef39314f5e73e95ea6ad9a9486
7
- data.tar.gz: eceb36030d7404ff5530141f4a9c2f337324f85de5c58a08dfdb9c3480411b120b1988771d7949e4dc5238273ff9dd9a2364558084f5b7465fbd03d7e5a7af3e
6
+ metadata.gz: b5b11714e11f26704f9768d750bb61c4034edac91141d6a1743ad7fbbc6999fc88b2c70acbbbc42f14cdc6bd3eb3a0a3441519bd2922413a03d13a208d101e08
7
+ data.tar.gz: f50280bc01e330a2b2952585b444ceb5b195855836d572791c727c73b6d295b3037b76fc4ccf042837656a684f23889658114a981a55a33f50a05651d85b8478
data/.travis.yml CHANGED
@@ -14,3 +14,6 @@ rvm:
14
14
  notifications:
15
15
  recipients:
16
16
  - michael@novemberain.com
17
+ matrix:
18
+ allow_failures:
19
+ - rvm: ruby-head
@@ -177,7 +177,7 @@ module AMQ
177
177
  body.force_encoding("ASCII-8BIT") if RUBY_VERSION.to_f >= 1.9
178
178
 
179
179
  array = Array.new
180
- while body
180
+ while body && !body.empty?
181
181
  payload, body = body[0, limit], body[limit, body.length - limit]
182
182
  array << BodyFrame.new(payload, channel)
183
183
  end
@@ -1,5 +1,5 @@
1
1
  module AMQ
2
2
  module Protocol
3
- VERSION = "1.7.0"
3
+ VERSION = "1.8.0"
4
4
  end # Protocol
5
5
  end # AMQ
data/lib/amq/settings.rb CHANGED
@@ -1,12 +1,10 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require "amq/protocol/client"
4
- require "uri"
4
+ require "amq/uri"
5
5
 
6
6
  module AMQ
7
7
  module Settings
8
- # @private
9
- AMQP_PORTS = {"amqp" => 5672, "amqps" => 5671}.freeze
10
8
 
11
9
  # @private
12
10
  AMQPS = "amqps".freeze
@@ -110,23 +108,7 @@ module AMQ
110
108
  #
111
109
  # @api public
112
110
  def self.parse_amqp_url(connection_string)
113
- uri = URI.parse(connection_string)
114
- raise ArgumentError.new("Connection URI must use amqp or amqps schema (example: amqp://bus.megacorp.internal:5766), learn more at http://bit.ly/ks8MXK") unless %w{amqp amqps}.include?(uri.scheme)
115
-
116
- opts = {}
117
-
118
- opts[:scheme] = uri.scheme
119
- opts[:user] = URI.unescape(uri.user) if uri.user
120
- opts[:pass] = URI.unescape(uri.password) if uri.password
121
- opts[:host] = uri.host if uri.host
122
- opts[:port] = uri.port || AMQP_PORTS[uri.scheme]
123
- opts[:ssl] = uri.scheme.to_s.downcase =~ /amqps/i
124
- if uri.path =~ %r{^/(.*)}
125
- raise ArgumentError.new("#{uri} has multiple-segment path; please percent-encode any slashes in the vhost name (e.g. /production => %2Fproduction). Learn more at http://bit.ly/amqp-gem-and-connection-uris") if $1.index('/')
126
- opts[:vhost] = URI.unescape($1)
127
- end
128
-
129
- opts
111
+ AMQ::URI.parse(connection_string)
130
112
  end
131
113
  end
132
114
  end
data/lib/amq/uri.rb ADDED
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require "amq/settings"
4
+
5
+ require "cgi"
6
+ require "uri"
7
+
8
+ module AMQ
9
+ class URI
10
+ # @private
11
+ AMQP_PORTS = {"amqp" => 5672, "amqps" => 5671}.freeze
12
+
13
+
14
+ def self.parse(connection_string)
15
+ uri = ::URI.parse(connection_string)
16
+ raise ArgumentError.new("Connection URI must use amqp or amqps schema (example: amqp://bus.megacorp.internal:5766), learn more at http://bit.ly/ks8MXK") unless %w{amqp amqps}.include?(uri.scheme)
17
+
18
+ opts = {}
19
+
20
+ opts[:scheme] = uri.scheme
21
+ opts[:user] = ::URI.unescape(uri.user) if uri.user
22
+ opts[:pass] = ::URI.unescape(uri.password) if uri.password
23
+ opts[:host] = uri.host if uri.host
24
+ opts[:port] = uri.port || AMQP_PORTS[uri.scheme]
25
+ opts[:ssl] = uri.scheme.to_s.downcase =~ /amqps/i
26
+ if uri.path =~ %r{^/(.*)}
27
+ raise ArgumentError.new("#{uri} has multiple-segment path; please percent-encode any slashes in the vhost name (e.g. /production => %2Fproduction). Learn more at http://bit.ly/amqp-gem-and-connection-uris") if $1.index('/')
28
+ opts[:vhost] = ::URI.unescape($1)
29
+ end
30
+
31
+ opts
32
+ end
33
+ def self.parse_amqp_url(s)
34
+ parse(s)
35
+ end
36
+ end
37
+ end
@@ -34,6 +34,14 @@ module AMQ
34
34
  body_frames.map(&:payload).should == lipsum.split('').each_slice(expected_payload_size).map(&:join)
35
35
  end
36
36
  end
37
+
38
+ context 'when the body fits perfectly in a single frame' do
39
+ it 'encodes a body into a single BodyFrame' do
40
+ body_frames = Method.encode_body('*' * 131064, 1, 131072)
41
+ body_frames.first.payload.should == '*' * 131064
42
+ body_frames.should have(1).item
43
+ end
44
+ end
37
45
  end
38
46
  end
39
47
  end
@@ -22,95 +22,4 @@ describe AMQ::Settings do
22
22
  settings[:host].should eql("tagadab")
23
23
  end
24
24
  end
25
-
26
- describe ".parse_amqp_url(connection_string)" do
27
- context "when schema is not one of [amqp, amqps]" do
28
- it "raises ArgumentError" do
29
- expect {
30
- described_class.parse_amqp_url("http://dev.rabbitmq.com")
31
- }.to raise_error(ArgumentError, /amqp or amqps schema/)
32
- end
33
- end
34
-
35
-
36
- it "handles amqp:// URIs w/o path part" do
37
- val = described_class.parse_amqp_url("amqp://dev.rabbitmq.com")
38
-
39
- val[:vhost].should be_nil # in this case, default / will be used
40
- val[:host].should == "dev.rabbitmq.com"
41
- val[:port].should == 5672
42
- val[:scheme].should == "amqp"
43
- val[:ssl].should be_false
44
- end
45
-
46
- it "handles amqps:// URIs w/o path part" do
47
- val = described_class.parse_amqp_url("amqps://dev.rabbitmq.com")
48
-
49
- val[:vhost].should be_nil
50
- val[:host].should == "dev.rabbitmq.com"
51
- val[:port].should == 5671
52
- val[:scheme].should == "amqps"
53
- val[:ssl].should be_true
54
- end
55
-
56
-
57
- context "when URI ends in a slash" do
58
- it "parses vhost as an empty string" do
59
- val = described_class.parse_amqp_url("amqp://dev.rabbitmq.com/")
60
-
61
- val[:host].should == "dev.rabbitmq.com"
62
- val[:port].should == 5672
63
- val[:scheme].should == "amqp"
64
- val[:ssl].should be_false
65
- val[:vhost].should == ""
66
- end
67
- end
68
-
69
-
70
- context "when URI ends in /%2Fvault" do
71
- it "parses vhost as /vault" do
72
- val = described_class.parse_amqp_url("amqp://dev.rabbitmq.com/%2Fvault")
73
-
74
- val[:host].should == "dev.rabbitmq.com"
75
- val[:port].should == 5672
76
- val[:scheme].should == "amqp"
77
- val[:ssl].should be_false
78
- val[:vhost].should == "/vault"
79
- end
80
- end
81
-
82
-
83
- context "when URI is amqp://dev.rabbitmq.com/a.path.without.slashes" do
84
- it "parses vhost as a.path.without.slashes" do
85
- val = described_class.parse_amqp_url("amqp://dev.rabbitmq.com/a.path.without.slashes")
86
-
87
- val[:host].should == "dev.rabbitmq.com"
88
- val[:port].should == 5672
89
- val[:scheme].should == "amqp"
90
- val[:ssl].should be_false
91
- val[:vhost].should == "a.path.without.slashes"
92
- end
93
- end
94
-
95
- context "when URI is amqp://dev.rabbitmq.com/a/path/with/slashes" do
96
- it "raises an ArgumentError" do
97
- lambda { described_class.parse_amqp_url("amqp://dev.rabbitmq.com/a/path/with/slashes") }.should raise_error(ArgumentError)
98
- end
99
- end
100
-
101
-
102
- context "when URI has username:password, for instance, amqp://hedgehog:t0ps3kr3t@hub.megacorp.internal" do
103
- it "parses them out" do
104
- val = described_class.parse_amqp_url("amqp://hedgehog:t0ps3kr3t@hub.megacorp.internal")
105
-
106
- val[:host].should == "hub.megacorp.internal"
107
- val[:port].should == 5672
108
- val[:scheme].should == "amqp"
109
- val[:ssl].should be_false
110
- val[:user].should == "hedgehog"
111
- val[:pass].should == "t0ps3kr3t"
112
- val[:vhost].should be_nil # in this case, default / will be used
113
- end
114
- end
115
- end
116
25
  end
@@ -0,0 +1,95 @@
1
+ # encoding: utf-8
2
+
3
+ require "spec_helper"
4
+ require "amq/uri"
5
+
6
+ describe AMQ::URI, ".parse" do
7
+ context "when schema is not one of [amqp, amqps]" do
8
+ it "raises ArgumentError" do
9
+ expect {
10
+ described_class.parse_amqp_url("http://dev.rabbitmq.com")
11
+ }.to raise_error(ArgumentError, /amqp or amqps schema/)
12
+ end
13
+ end
14
+
15
+
16
+ it "handles amqp:// URIs w/o path part" do
17
+ val = described_class.parse_amqp_url("amqp://dev.rabbitmq.com")
18
+
19
+ val[:vhost].should be_nil # in this case, default / will be used
20
+ val[:host].should == "dev.rabbitmq.com"
21
+ val[:port].should == 5672
22
+ val[:scheme].should == "amqp"
23
+ val[:ssl].should be_false
24
+ end
25
+
26
+ it "handles amqps:// URIs w/o path part" do
27
+ val = described_class.parse_amqp_url("amqps://dev.rabbitmq.com")
28
+
29
+ val[:vhost].should be_nil
30
+ val[:host].should == "dev.rabbitmq.com"
31
+ val[:port].should == 5671
32
+ val[:scheme].should == "amqps"
33
+ val[:ssl].should be_true
34
+ end
35
+
36
+
37
+ context "when URI ends in a slash" do
38
+ it "parses vhost as an empty string" do
39
+ val = described_class.parse_amqp_url("amqp://dev.rabbitmq.com/")
40
+
41
+ val[:host].should == "dev.rabbitmq.com"
42
+ val[:port].should == 5672
43
+ val[:scheme].should == "amqp"
44
+ val[:ssl].should be_false
45
+ val[:vhost].should == ""
46
+ end
47
+ end
48
+
49
+
50
+ context "when URI ends in /%2Fvault" do
51
+ it "parses vhost as /vault" do
52
+ val = described_class.parse_amqp_url("amqp://dev.rabbitmq.com/%2Fvault")
53
+
54
+ val[:host].should == "dev.rabbitmq.com"
55
+ val[:port].should == 5672
56
+ val[:scheme].should == "amqp"
57
+ val[:ssl].should be_false
58
+ val[:vhost].should == "/vault"
59
+ end
60
+ end
61
+
62
+
63
+ context "when URI is amqp://dev.rabbitmq.com/a.path.without.slashes" do
64
+ it "parses vhost as a.path.without.slashes" do
65
+ val = described_class.parse_amqp_url("amqp://dev.rabbitmq.com/a.path.without.slashes")
66
+
67
+ val[:host].should == "dev.rabbitmq.com"
68
+ val[:port].should == 5672
69
+ val[:scheme].should == "amqp"
70
+ val[:ssl].should be_false
71
+ val[:vhost].should == "a.path.without.slashes"
72
+ end
73
+ end
74
+
75
+ context "when URI is amqp://dev.rabbitmq.com/a/path/with/slashes" do
76
+ it "raises an ArgumentError" do
77
+ lambda { described_class.parse_amqp_url("amqp://dev.rabbitmq.com/a/path/with/slashes") }.should raise_error(ArgumentError)
78
+ end
79
+ end
80
+
81
+
82
+ context "when URI has username:password, for instance, amqp://hedgehog:t0ps3kr3t@hub.megacorp.internal" do
83
+ it "parses them out" do
84
+ val = described_class.parse_amqp_url("amqp://hedgehog:t0ps3kr3t@hub.megacorp.internal")
85
+
86
+ val[:host].should == "hub.megacorp.internal"
87
+ val[:port].should == 5672
88
+ val[:scheme].should == "amqp"
89
+ val[:ssl].should be_false
90
+ val[:user].should == "hedgehog"
91
+ val[:pass].should == "t0ps3kr3t"
92
+ val[:vhost].should be_nil # in this case, default / will be used
93
+ end
94
+ end
95
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amq-protocol
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Stastny
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-08-07 00:00:00.000000000 Z
14
+ date: 2013-09-17 00:00:00.000000000 Z
15
15
  dependencies: []
16
16
  description: |2
17
17
  amq-protocol is an AMQP 0.9.1 serialization library for Ruby. It is not an
@@ -59,6 +59,7 @@ files:
59
59
  - lib/amq/protocol/type_constants.rb
60
60
  - lib/amq/protocol/version.rb
61
61
  - lib/amq/settings.rb
62
+ - lib/amq/uri.rb
62
63
  - profiling/pure/body_framing_with_2k_payload.rb
63
64
  - spec/amq/bit_set_spec.rb
64
65
  - spec/amq/hacks_spec.rb
@@ -79,6 +80,7 @@ files:
79
80
  - spec/amq/protocol/value_encoder_spec.rb
80
81
  - spec/amq/protocol_spec.rb
81
82
  - spec/amq/settings_spec.rb
83
+ - spec/amq/uri_parsing_spec.rb
82
84
  - spec/spec_helper.rb
83
85
  homepage: http://github.com/ruby-amqp/amq-protocol
84
86
  licenses: