From 3901f75632aed53497d382b56c9948ca91030411 Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Wed, 20 Mar 2013 14:36:48 -0300 Subject: [PATCH] [BUGFIX] Allow sending large app arguments Application arguments (headers in general) are limited to 2048 bytes. The work-around is to send them in the body of the message with a content-length header. --- CHANGELOG.md | 1 + lib/ruby_fs/stream.rb | 10 +++++++++- spec/ruby_fs/stream_spec.rb | 7 +++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2176ffc..a8292fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # develop + * Bugfix: Allow sending large app arguments. Application arguments (headers in general) are limited to 2048 bytes. The work-around is to send them in the body of the message with a content-length header. # 1.0.3 * Bugfix: JRuby compatability diff --git a/lib/ruby_fs/stream.rb b/lib/ruby_fs/stream.rb index fb737f2..d6cff28 100644 --- a/lib/ruby_fs/stream.rb +++ b/lib/ruby_fs/stream.rb @@ -60,9 +60,11 @@ def command(command, options = {}, &callback) uuid = SecureRandom.uuid @command_callbacks << (callback || lambda { |reply| signal uuid, reply }) string = "#{command}\n" + body_value = options.delete :command_body_value options.each_pair do |key, value| string << "#{key.to_s.gsub '_', '-'}: #{value}\n" if value end + string << "\n" << body_value << "\n" if body_value string << "\n" send_data string wait uuid unless callback @@ -108,7 +110,13 @@ def sendmsg(call, options = {}) # # @return [RubyFS::Response] response the application's response object def application(call, appname, options = nil) - sendmsg call, :call_command => 'execute', :execute_app_name => appname, :execute_app_arg => options + opts = {call_command: 'execute', execute_app_name: appname} + if options + opts[:content_type] = 'text/plain' + opts[:content_length] = options.bytesize + opts[:command_body_value] = options + end + sendmsg call, opts end # diff --git a/spec/ruby_fs/stream_spec.rb b/spec/ruby_fs/stream_spec.rb index 98fca75..8356f1b 100644 --- a/spec/ruby_fs/stream_spec.rb +++ b/spec/ruby_fs/stream_spec.rb @@ -231,7 +231,7 @@ def expect_disconnected_event end end - it "can execute applications on calls with options and returns the response" do + it "can execute applications on calls with options (in the body) and returns the response" do expect_connected_event expect_disconnected_event reply = CommandReply.new(:content_type => 'command/reply', :reply_text => '+OK accepted') @@ -239,7 +239,10 @@ def expect_disconnected_event val.should == %Q(SendMsg aUUID call-command: execute execute-app-name: playback -execute-app-arg: /tmp/test.wav +content-type: text/plain +content-length: 13 + +/tmp/test.wav ) server.send_data %Q(