diff --git a/test/protocol/rack/request.rb b/test/protocol/rack/request.rb index 9c78771..ee29244 100644 --- a/test/protocol/rack/request.rb +++ b/test/protocol/rack/request.rb @@ -10,24 +10,23 @@ let(:app) {proc{|env| [200, {}, []]}} let(:adapter) {Protocol::Rack::Adapter.new(app)} + let(:headers) {Protocol::HTTP::Headers[{'accept' => 'text/html'}]} + let(:body) {Protocol::HTTP::Body::Buffered.new} + + let(:request) {Protocol::HTTP::Request.new( + 'https', 'example.com', 'GET', '/', 'http/1.1', headers, body + )} + + let(:env) {adapter.make_environment(request)} + + let(:wrapped_request) {subject.new(env)} + with 'incoming rack env' do - let(:body) {Protocol::HTTP::Body::Buffered.new} - - let(:request) {Protocol::HTTP::Request.new( - 'https', 'example.com', 'GET', '/', 'http/1.1', Protocol::HTTP::Headers[{'accept' => 'text/html'}], body - )} - - let(:env) {adapter.make_environment(request)} - it "can restore request from original request" do expect(subject[env]).to be == request end it "can regenerate request from generic env" do - env.delete(Protocol::Rack::PROTOCOL_HTTP_REQUEST) - - wrapped_request = subject[env] - expect(wrapped_request.scheme).to be == request.scheme expect(wrapped_request.authority).to be == request.authority expect(wrapped_request.method).to be == request.method @@ -38,4 +37,26 @@ expect(wrapped_request.protocol).to be == request.protocol end end + + with 'incoming rack env which includes HTTP upgrade' do + let(:headers) {Protocol::HTTP::Headers[{'upgrade' => 'websocket'}]} + + it "can extract upgrade request" do + expect(wrapped_request).to have_attributes( + protocol: be == ["websocket"] + ) + end + end + + with 'incoming rack env which includes rack.protocol' do + let(:request) {Protocol::HTTP::Request.new( + 'https', 'example.com', 'GET', '/', 'http/1.1', headers, body, ["websocket"] + )} + + it "can extract upgrade request" do + expect(wrapped_request).to have_attributes( + protocol: be == ["websocket"] + ) + end + end end