Permalink
Browse files

update SPDY; send the request off after it came in as a whole

  • Loading branch information...
1 parent c033063 commit 58d93c45c9ceb9d7c9d76d726ef5a38407921406 @jonasschneider committed Jan 5, 2012
Showing with 35 additions and 15 deletions.
  1. +18 −8 lib/momentum/connection.rb
  2. +9 −3 lib/momentum/request_stream.rb
  3. +1 −1 spdy
  4. +5 −1 spec/momentum/request_stream_spec.rb
  5. +2 −2 spec/support/dumb_spdy_client.rb
View
@@ -14,17 +14,27 @@ def initialize(*args)
@next_stream_id = 0
@parser = ::SPDY::Parser.new
- @parser.on_headers_complete do |stream_id, associated_stream, priority, headers|
- stream = RequestStream.new(stream_id, self, headers, backend)
- stream.process_request!
+ @streams = {}
+
+ @parser.on_open do |stream_id, associated, pri|
+ @streams[stream_id] = RequestStream.new(stream_id, self, backend)
end
- @parser.on_body { |stream_id, data|
+ @parser.on_headers do |stream_id, headers|
+ stream = @streams[stream_id]
+ raise "invalid stream #{stream_id.class}" unless stream
+ stream.add_headers(headers)
+ end
- }
- @parser.on_message_complete { |stream_id|
+ @parser.on_body do |stream_id, data|
+ # TODO
+ end
- }
+ @parser.on_message_complete do |stream_id|
+ stream = @streams[stream_id]
+ raise "invalid stream #{stream_id.class}" unless stream
+ stream.process_request!
+ end
@parser.on_ping do |id|
logger.debug "> Ping #{id}"
@@ -33,8 +43,8 @@ def initialize(*args)
send_data pong.to_binary_s
end
- @streams = []
@could_be_http = true
+ end_t = Time.now
end
def post_init
@@ -1,14 +1,20 @@
module Momentum
class RequestStream < Stream
- def initialize(stream_id, session, headers, backend)
+ def initialize(stream_id, session, backend)
super(stream_id, session)
@session, @backend = session, backend
- @request = Request.new(headers: headers)
+ @headers = {}
@request_received_at = Time.now
- logger.info "[#{@stream_id}] got a request to #{@request.uri}"
+ end
+
+ def add_headers(headers)
+ @headers.merge! headers
end
def process_request!
+ @request = Request.new(headers: @headers)
+
+ logger.info "[#{@stream_id}] got a request to #{@request.uri}"
reply = @backend.prepare(@request)
reply.on_push do |url|
2 spdy
Submodule spdy updated 2 files
+28 −13 lib/spdy/parser.rb
+63 −8 spec/parser_spec.rb
@@ -13,7 +13,11 @@
let(:backend) { double(:prepare => backend_response) }
let(:session) { double('Session', :logger => double(:debug => true, :info => true)) }
- let(:stream) { described_class.new(1, session, request_headers, backend) }
+ let(:stream) do
+ described_class.new(1, session, backend).tap do |stream|
+ stream.add_headers(request_headers)
+ end
+ end
before :each do
session.stub(:send_data_frame) # We check for Stream#send_data
@@ -13,14 +13,14 @@ def post_init
@body_chunk_count += 1
end
- @parser.on_headers_complete do |a, s, d, headers|
+ @parser.on_headers do |stream, headers|
DumbSPDYClient.headers = headers
end
@parser.on_message_complete do
DumbSPDYClient.body = @body
DumbSPDYClient.body_chunk_count = @body_chunk_count
- EventMachine::stop_event_loop
+ EM.stop
end
send_data GET_REQUEST

0 comments on commit 58d93c4

Please sign in to comment.