require 'spec_helper' class RFlow module Components module HTTP describe Server do let(:conn) { Server::Connection.new('a') } it "should return a default HTTP response" do expect(conn).to receive(:send_data).with("HTTP/1.1 200 OK\r\nContent-Length: 0\r\nContent-Type: text/html\r\nServer: Apache\r\n\r\n") expect(conn).to receive(:send_data).with('') allow(conn).to receive(:close_connection) conn.send_http_response(Message.new("RFlow::Message::Data::HTTP::Response")) end it "should use proper status reason phrases" do expect(conn).to receive(:send_data).with("HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\nContent-Type: text/html\r\nServer: Apache\r\n\r\n") expect(conn).to receive(:send_data).with('') allow(conn).to receive(:close_connection) conn.send_http_response(Message.new("RFlow::Message::Data::HTTP::Response").tap {|r| r.data.status_code = 404 }) end it "should return a fully configured HTTP response" do m = Message.new("RFlow::Message::Data::HTTP::Response").tap do |m| m.data.status_code = 1337 m.data.status_reason_phrase = "JUST BECAUSE" # ignored as status phrases are overwritten m.data.headers['Boom'] = 'Town' m.data.content = 'boom' end expected_body = "boom" expect(conn).to receive(:send_data).with("HTTP/1.1 1337\r\nBoom: Town\r\nContent-Length: 4\r\nContent-Type: text/html\r\nServer: Apache\r\n\r\n") expect(conn).to receive(:send_data).with('boom') allow(conn).to receive(:close_connection) conn.send_http_response(m) end end end end end