diff --git a/lib/rtsp/response.rb b/lib/rtsp/response.rb index e0b5ca0..504e536 100644 --- a/lib/rtsp/response.rb +++ b/lib/rtsp/response.rb @@ -68,10 +68,10 @@ def split_head_and_body_from raw_response # # @param [String] line The String containing the status line info. def extract_status_line(line) - line =~ /RTSP|HTTP\/(\d\.\d) (\d\d\d) ([^\r\n]+)/ - @rtsp_version = $1 - @code = $2.to_i - @message = $3 + line =~ /(RTSP|HTTP)\/(\d\.\d) (\d\d\d) ([^\r\n]+)/ + @rtsp_version = $2 + @code = $3.to_i + @message = $4 if @rtsp_version.nil? raise RTSP::Error, "Status line corrupted: #{line}" diff --git a/spec/rtsp/response_spec.rb b/spec/rtsp/response_spec.rb index 8aca6ea..1aa0663 100644 --- a/spec/rtsp/response_spec.rb +++ b/spec/rtsp/response_spec.rb @@ -12,6 +12,36 @@ end end + describe "#extract_status_line" do + before do + RTSP::Response.any_instance.stub(:split_head_and_body_from) + RTSP::Response.any_instance.stub(:parse_head) + RTSP::Response.any_instance.stub(:parse_body) + end + + subject { RTSP::Response.new " " } + + context "RTSP response" do + let(:status_line) { "RTSP/1.0 200 OK\r\n" } + before { subject.extract_status_line(status_line) } + specify { + subject.rtsp_version.should == "1.0" + subject.code.should == 200 + subject.message.should == "OK" + } + end + + context "HTTP response" do + let(:status_line) { "HTTP/1.1 200 OK\r\n" } + before { subject.extract_status_line(status_line) } + specify { + subject.rtsp_version.should == "1.1" + subject.code.should == 200 + subject.message.should == "OK" + } + end + end + describe "#parse_head" do let(:head) do head = double "head"