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

Multiple headers with the same key return a comma-separated string #43

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/ruby_ami/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ def syntax_error_encountered(ignored_chunk)
# returns first char index after last match
def populate_message_body(obj, raw)
headers = raw.scan(KEYVALUEPAIR)
# get the values of repeated keys (example 'Variable' header)
headers = headers.group_by(&:shift).map { |k, v| [ k, v.join(',') ] }
if match = $~
obj.merge_headers!(Hash[headers])
match.end(match.size - 1) + 2
Expand Down
20 changes: 20 additions & 0 deletions spec/ruby_ami/stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,26 @@ def mocked_server(times = nil, fake_client = nil, &block)
]
end

it 'sends events with multiple headers with the same key to the client when the stream is ready' do
mocked_server(1, lambda { @stream.send_data 'Foo' }) do |val, server|
server.send_data <<-EVENT
Event: Status
Channel: SIP/101-3f3f
Variable: CDR(ds_type)=Test-INT
Variable: from_user=ssether
Variable: companyID=Test
ActionID: 2

EVENT
end

client_messages.should be == [
[Stream::Connected.new, @stream],
[Event.new('Status', 'Channel' => 'SIP/101-3f3f', 'Variable' => 'CDR(ds_type)=Test-INT,from_user=ssether,companyID=Test', 'ActionID' => '2'), @stream],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this?

Suggested change
[Event.new('Status', 'Channel' => 'SIP/101-3f3f', 'Variable' => 'CDR(ds_type)=Test-INT,from_user=ssether,companyID=Test', 'ActionID' => '2'), @stream],
[Event.new('Status', 'Channel' => 'SIP/101-3f3f', 'Variable' => ['CDR(ds_type)=Test-INT', 'from_user=ssether', 'companyID=Test'], 'ActionID' => '2'), @stream],

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather a 'string' to not change the interface, but it could return a 'map' with key / values

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with a Hash is that it is specific to the Variable header, and not a generic way of expressing multiple values for any header.

[Stream::Disconnected.new, @stream],
]
end

describe 'when a response is received' do
it 'should be returned from #send_action' do
response = nil
Expand Down