registering http1 and http2 handlers directly in the channel

This commit is contained in:
HoneyryderChuck 2017-12-13 00:09:54 +00:00
parent 117acfb6f7
commit e19d9a0dd2
3 changed files with 4 additions and 6 deletions

View File

@ -5,16 +5,12 @@ require "httpx/buffer"
module HTTPX
class Channel
include Registry
require "httpx/channel/http2"
require "httpx/channel/http1"
BUFFER_SIZE = 1 << 14
PROTOCOLS = {
"h2" => HTTP2,
"http/1.1" => HTTP1
}
class << self
def by(uri, options, &blk)
io = case uri.scheme
@ -132,7 +128,7 @@ module HTTPX
def parser
@parser || begin
@parser = PROTOCOLS[@io.protocol].new(@write_buffer, @options)
@parser = registry(@io.protocol).new(@write_buffer, @options)
@parser.on(:response, &@on_response)
@parser.on(:close) { throw(:close, self) }
@parser

View File

@ -149,5 +149,6 @@ module HTTPX
$stderr << (+"" << msg.call << "\n")
end
end
Channel.register "http/1.1", Channel::HTTP1
end

View File

@ -180,4 +180,5 @@ module HTTPX
$stderr << (+"connection (HTTP/2): " << msg.call << "\n")
end
end
Channel.register "h2", Channel::HTTP2
end