mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
added limited buffer type; it's a weak buffer, in that it doesn't break if buffer limit it is exceeded, it just doesn't let append more data after limit is reached
This commit is contained in:
parent
e6a5fbdf45
commit
6acffbc297
32
lib/httpx/buffer.rb
Normal file
32
lib/httpx/buffer.rb
Normal file
@ -0,0 +1,32 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "forwardable"
|
||||
|
||||
module HTTPX
|
||||
class Buffer
|
||||
extend Forwardable
|
||||
|
||||
def_delegator :@buffer, :<<
|
||||
|
||||
def_delegator :@buffer, :to_s
|
||||
|
||||
def_delegator :@buffer, :to_str
|
||||
|
||||
def_delegator :@buffer, :empty?
|
||||
|
||||
def_delegator :@buffer, :slice!
|
||||
|
||||
def initialize(limit)
|
||||
@buffer = "".b
|
||||
@limit = limit
|
||||
end
|
||||
|
||||
def <<(data)
|
||||
@buffer << data
|
||||
end
|
||||
|
||||
def full?
|
||||
@buffer.bytesize >= @limit
|
||||
end
|
||||
end
|
||||
end
|
@ -1,12 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "httpx/io"
|
||||
require "httpx/buffer"
|
||||
|
||||
module HTTPX
|
||||
class Channel
|
||||
require "httpx/channel/http2"
|
||||
require "httpx/channel/http1"
|
||||
|
||||
BUFFER_SIZE = 1 << 14
|
||||
|
||||
PROTOCOLS = {
|
||||
"h2" => HTTP2,
|
||||
"http/1.1" => HTTP1
|
||||
@ -30,8 +33,8 @@ module HTTPX
|
||||
@io = io
|
||||
@options = Options.new(options)
|
||||
@window_size = @options.window_size
|
||||
@read_buffer = +""
|
||||
@write_buffer = +""
|
||||
@read_buffer = "".b
|
||||
@write_buffer = Buffer.new(BUFFER_SIZE)
|
||||
@pending = []
|
||||
@on_response = on_response
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user