Skip to content

Commit

Permalink
Merge 4f25eb7 into bf4b930
Browse files Browse the repository at this point in the history
  • Loading branch information
kenichi committed Oct 18, 2016
2 parents bf4b930 + 4f25eb7 commit dea3287
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions example/upgrade_server.rb
@@ -1,3 +1,5 @@
# frozen_string_literals: true

require_relative 'helper'
require 'http_parser'
require 'base64'
Expand Down Expand Up @@ -82,6 +84,15 @@ def on_message_complete
end
end

def request_header_hash received_hash = {}
Hash.new do |hash, key|
k = key.to_s.upcase
k.gsub! '_', '-'
_, value = received_hash.find {|header_key,v| header_key.upcase == k}
hash[key] = value if value
end
end

loop do
sock = server.accept
puts 'New TCP connection!'
Expand All @@ -99,16 +110,19 @@ def on_message_complete
end

conn.on(:stream) do |stream|

log = Logger.new(stream.id)
req, buffer = {}, ''
request_headers = {}
req = request_header_hash(request_headers)
buffer = ''

stream.on(:active) { log.info 'client opened new stream' }
stream.on(:close) do
log.info 'stream closed'
end

stream.on(:headers) do |h|
req = Hash[*h.flatten]
request_headers.merge! Hash[*h.flatten]
log.info "request headers: #{h}"
end

Expand Down

0 comments on commit dea3287

Please sign in to comment.