lib/ably/rest/client.rb in ably-1.1.6 vs lib/ably/rest/client.rb in ably-1.1.7
- old
+ new
@@ -23,10 +23,12 @@
extend Forwardable
# Default Ably domain for REST
DOMAIN = 'rest.ably.io'
+ MAX_FRAME_SIZE = 524288
+
# Configuration for HTTP timeouts and HTTP request reattempts to fallback hosts
HTTP_DEFAULTS = {
open_timeout: 4,
request_timeout: 10,
max_retry_duration: 15,
@@ -50,10 +52,14 @@
# The protocol configured for this client, either binary `:msgpack` or text based `:json`
# @return [Symbol]
attr_reader :protocol
+ # Client agent i.e. `example-gem/1.2.0 ably-ruby/1.1.5 ruby/1.9.3`
+ # @return [String]
+ attr_reader :agent
+
# {Ably::Auth} authentication object configured for this connection
# @return [Ably::Auth]
attr_reader :auth
# The collection of {Ably::Rest::Channel}s that have been created
@@ -166,10 +172,11 @@
else
{ token: options }
end
end
+ @agent = options.delete(:agent) || Ably::AGENT
@realtime_client = options.delete(:realtime_client)
@tls = options.delete(:tls) == false ? false : true
@environment = options.delete(:environment) # nil is production
@environment = nil if [:production, 'production'].include?(@environment)
@protocol = options.delete(:protocol) || :msgpack
@@ -356,10 +363,13 @@
when :get, :delete
reauthorize_on_authorization_failure do
send_request(method, path, params, headers: headers)
end
when :post, :patch, :put
+ if body.to_json.bytesize > MAX_FRAME_SIZE
+ raise Ably::Exceptions::MaxFrameSizeExceeded.new("Maximum frame size exceeded #{MAX_FRAME_SIZE} bytes.")
+ end
path_with_params = Addressable::URI.new
path_with_params.query_values = params || {}
query = path_with_params.query
reauthorize_on_authorization_failure do
send_request(method, "#{path}#{"?#{query}" unless query.nil? || query.empty?}", body, headers: headers)
@@ -471,20 +481,10 @@
@fallback_connections[@fallback_index % @fallback_connections.count].tap do
@fallback_index += 1
end
end
- # Library Ably version user agent
- # @api private
- def lib_version_id
- @lib_version_id ||= [
- 'ruby',
- Ably.lib_variant,
- Ably::VERSION
- ].compact.join('-')
- end
-
# Allowable duration for an external auth request
# For REST client this defaults to request_timeout
# For Realtime clients this defaults to 250ms less than the realtime_request_timeout
# ensuring an auth failure will be triggered before the realtime request timeout fires
# which would lead to a misleading error message (connection timeout as opposed to auth request timeout)
@@ -661,10 +661,10 @@
headers: {
content_type: mime_type,
accept: mime_type,
user_agent: user_agent,
'X-Ably-Version' => Ably::PROTOCOL_VERSION,
- 'X-Ably-Lib' => lib_version_id
+ 'Ably-Agent' => agent
},
request: {
open_timeout: http_defaults.fetch(:open_timeout),
timeout: http_defaults.fetch(:request_timeout)
}