Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TO3l9 Max frame size #259

Merged
merged 2 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/ably/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def as_json(*args)
end
end

# Maximum frame size exceeded TO3l9
class MaxFrameSizeExceeded < BaseAblyException; end

# Maximum message size exceeded TO3l8
class MaxMessageSizeExceeded < BaseAblyException; end

Expand Down
1 change: 1 addition & 0 deletions lib/ably/models/connection_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def initialize(attributes = {})
end
end
self.attributes[:max_message_size] ||= 65536
self.attributes[:max_frame_size] ||= 524288
self.attributes.freeze
end

Expand Down
5 changes: 5 additions & 0 deletions lib/ably/rest/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Client
# 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,
Expand Down Expand Up @@ -363,6 +365,9 @@ def request(method, path, params = {}, body = nil, headers = {}, options = {})
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
Expand Down
20 changes: 19 additions & 1 deletion spec/acceptance/rest/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ def encode64(text)
end
end

context '#request (#RSC19*)' do
context '#request (#RSC19*, #TO3l9)' do
let(:client_options) { default_options.merge(key: api_key) }
let(:device_id) { random_str }
let(:endpoint) { client.endpoint }
Expand Down Expand Up @@ -1158,6 +1158,12 @@ def encode64(text)

expect(response).to be_success
end

it 'raises an exception once body size in bytes exceeded' do
expect {
client.request(:post, endpoint, {}, { content: 'x' * Ably::Rest::Client::MAX_FRAME_SIZE })
}.to raise_error(Ably::Exceptions::MaxFrameSizeExceeded)
end
end

context 'delete', :webmock do
Expand Down Expand Up @@ -1187,6 +1193,12 @@ def encode64(text)

expect(response).to be_success
end

it 'raises an exception once body size in bytes exceeded' do
expect {
client.request(:patch, endpoint, {}, { content: 'x' * Ably::Rest::Client::MAX_FRAME_SIZE })
}.to raise_error(Ably::Exceptions::MaxFrameSizeExceeded)
end
end

context 'put', :webmock do
Expand All @@ -1210,6 +1222,12 @@ def encode64(text)

expect(response).to be_success
end

it 'raises an exception once body size in bytes exceeded' do
expect {
client.request(:put, endpoint, {}, { content: 'x' * Ably::Rest::Client::MAX_FRAME_SIZE })
}.to raise_error(Ably::Exceptions::MaxFrameSizeExceeded)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/shared/model_behaviour.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
end

context '#attributes', :api_private do
let(:model_options) { { action: 5, max_message_size: 65536 } }
let(:model_options) { { action: 5, max_message_size: 65536, max_frame_size: 524288 } }

it 'provides access to #attributes' do
expect(model.attributes).to eq(model_options)
Expand Down