bertclient 0.3 → 0.3.1

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.
Files changed (2) hide show
  1. data/lib/bertclient.rb +17 -4
  2. metadata +3 -2
@@ -15,12 +15,16 @@ module BERT
15
15
  class BadData < RPCError; end
16
16
 
17
17
  GZIP_BERP = t[:info, :encoding, [t[:gzip]]]
18
+ ACCEPT_ENCODING_BERP = t[:info, :accept_encoding, [t[:gzip]]]
18
19
 
19
20
  def initialize(opts={}, &block)
20
21
  @host = opts[:host] || 'localhost'
21
22
  @port = opts[:port] || 9999
23
+
22
24
  @gzip = opts[:gzip] || false
23
25
  @gzip_threshold = opts[:gzip_threshold] || 1024 # bytes
26
+ @gzip_accept_sent = false
27
+
24
28
  @ssl = opts[:ssl] || false
25
29
  @verify_ssl = opts.has_key?(:verify_ssl) ? opts[:verify_ssl] : true
26
30
  @socket = {}
@@ -74,7 +78,7 @@ module BERT
74
78
  # See bert-rpc.org for error response mechanisms
75
79
  def handle_error(response)
76
80
  unless response[0] == :error
77
- raise InvalidReponse, "Expected error response, got: #{response.inspect}"
81
+ raise InvalidResponse, "Expected error response, got: #{response.inspect}"
78
82
  end
79
83
 
80
84
  type, code, klass, detail, backtrace = response[1]
@@ -146,12 +150,21 @@ module BERT
146
150
  # -> {gzip, GzippedBertEncodedData}
147
151
  def write_berp(obj)
148
152
  data = BERT.encode(obj)
149
- if @gzip and data.bytesize > @gzip_threshold
150
- socket.write(Client.create_berp(BERT.encode(GZIP_BERP)))
153
+ data = negotiate_gzip(data) if @gzip
154
+ socket.write(Client.create_berp(data))
155
+ end
151
156
 
157
+ def negotiate_gzip(data)
158
+ if not @gzip_accept_sent
159
+ @gzip_accept_sent = true
160
+ socket.write(Client.create_berp(BERT.encode(ACCEPT_ENCODING_BERP)))
161
+ end
162
+
163
+ if data.bytesize > @gzip_threshold
164
+ socket.write(Client.create_berp(BERT.encode(GZIP_BERP)))
152
165
  data = BERT.encode(t[:gzip, Zlib::Deflate.deflate(data)])
153
166
  end
154
- socket.write(Client.create_berp(data))
167
+ data
155
168
  end
156
169
 
157
170
  # Accepts a string and returns a berp
metadata CHANGED
@@ -5,7 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- version: "0.3"
8
+ - 1
9
+ version: 0.3.1
9
10
  platform: ruby
10
11
  authors:
11
12
  - Jared Kuolt
@@ -13,7 +14,7 @@ autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
16
 
16
- date: 2010-03-29 00:00:00 -07:00
17
+ date: 2010-03-31 00:00:00 -07:00
17
18
  default_executable:
18
19
  dependencies: []
19
20