Skip to content

Commit

Permalink
[BUGFIX] Allow sending large app arguments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
benlangfeld committed Mar 23, 2013
1 parent df0aced commit 3901f75
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions 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
Expand Down
10 changes: 9 additions & 1 deletion lib/ruby_fs/stream.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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

#
Expand Down
7 changes: 5 additions & 2 deletions spec/ruby_fs/stream_spec.rb
Expand Up @@ -231,15 +231,18 @@ 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')
mocked_server(1, lambda { |server| @stream.application('aUUID', 'playback', '/tmp/test.wav').should == reply }) do |val, server|
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(
Expand Down

0 comments on commit 3901f75

Please sign in to comment.