mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
registering http1 and http2 handlers directly in the channel
This commit is contained in:
parent
117acfb6f7
commit
e19d9a0dd2
@ -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
|
||||
|
@ -149,5 +149,6 @@ module HTTPX
|
||||
$stderr << (+"" << msg.call << "\n")
|
||||
end
|
||||
end
|
||||
Channel.register "http/1.1", Channel::HTTP1
|
||||
end
|
||||
|
||||
|
@ -180,4 +180,5 @@ module HTTPX
|
||||
$stderr << (+"connection (HTTP/2): " << msg.call << "\n")
|
||||
end
|
||||
end
|
||||
Channel.register "h2", Channel::HTTP2
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user