From b9339a12ae0ed001ac15ac354d9cf9402d96b27b Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Mon, 16 Aug 2021 14:37:47 +0100 Subject: [PATCH 1/4] targeting rbs with openssl --- test/support/ci/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/support/ci/build.sh b/test/support/ci/build.sh index 30250ce0..42c7f14c 100755 --- a/test/support/ci/build.sh +++ b/test/support/ci/build.sh @@ -72,7 +72,7 @@ if [[ ${RUBY_VERSION:0:1} = "3" ]]; then export RUBYOPT="$RUBYOPT -rbundler/setup -rrbs/test/setup" export RBS_TEST_RAISE=true export RBS_TEST_LOGLEVEL=error - export RBS_TEST_OPT="-Isig -rforwardable -ruri -rjson -ripaddr -rpathname -rhttp-2-next" + export RBS_TEST_OPT="-Isig -rset -rforwardable -ruri -rjson -ripaddr -rpathname -rtime -rtimeout -rresolv -rsocket -ropenssl -rbase64 -rzlib -rcgi -rhttp-2-next" export RBS_TEST_TARGET="HTTP*" fi From b92829d0252195ac54957b579e3ec03eed099047 Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Tue, 17 Aug 2021 16:13:05 +0100 Subject: [PATCH 2/4] do not needlessly forward method used only once --- lib/httpx/connection/http1.rb | 2 +- lib/httpx/request.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/httpx/connection/http1.rb b/lib/httpx/connection/http1.rb index 3a24fc3a..454885bc 100644 --- a/lib/httpx/connection/http1.rb +++ b/lib/httpx/connection/http1.rb @@ -265,7 +265,7 @@ module HTTPX def set_protocol_headers(request) if !request.headers.key?("content-length") && request.body.bytesize == Float::INFINITY - request.chunk! + request.body.chunk! end connection = request.headers["connection"] diff --git a/lib/httpx/request.rb b/lib/httpx/request.rb index b4ddb385..beca7eb1 100644 --- a/lib/httpx/request.rb +++ b/lib/httpx/request.rb @@ -41,8 +41,6 @@ module HTTPX def_delegator :@body, :empty? - def_delegator :@body, :chunk! - def initialize(verb, uri, options = {}) @verb = verb.to_s.downcase.to_sym @options = Options.new(options) From 74dfb18ed301016eb99c9839ad58213dddc701e2 Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Tue, 17 Aug 2021 16:13:32 +0100 Subject: [PATCH 3/4] few extra changes to appease the type checker --- lib/httpx/connection/http1.rb | 8 ++++--- lib/httpx/connection/http2.rb | 21 +++++++++++-------- lib/httpx/headers.rb | 2 +- lib/httpx/parser/http1.rb | 2 +- .../plugins/multipart/mime_type_detector.rb | 6 +++--- lib/httpx/plugins/multipart/part.rb | 4 ++-- lib/httpx/request.rb | 9 ++++---- 7 files changed, 29 insertions(+), 23 deletions(-) diff --git a/lib/httpx/connection/http1.rb b/lib/httpx/connection/http1.rb index 454885bc..a8b60747 100644 --- a/lib/httpx/connection/http1.rb +++ b/lib/httpx/connection/http1.rb @@ -322,7 +322,7 @@ module HTTPX end def join_body(request) - return if request.empty? + return if request.body.empty? while (chunk = request.drain_body) log(color: :green) { "<- DATA: #{chunk.bytesize} bytes..." } @@ -331,7 +331,9 @@ module HTTPX throw(:buffer_full, request) if @buffer.full? end - raise request.drain_error if request.drain_error + return unless (error = request.drain_error) + + raise error end def join_trailers(request) @@ -358,7 +360,7 @@ module HTTPX }.freeze def capitalized(field) - UPCASED[field] || field.to_s.split("-").map(&:capitalize).join("-") + UPCASED[field] || field.split("-").map(&:capitalize).join("-") end end Connection.register "http/1.1", Connection::HTTP1 diff --git a/lib/httpx/connection/http2.rb b/lib/httpx/connection/http2.rb index 7e416df8..49801304 100644 --- a/lib/httpx/connection/http2.rb +++ b/lib/httpx/connection/http2.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "securerandom" -require "io/wait" require "http/2/next" module HTTPX @@ -218,7 +217,7 @@ module HTTPX log(level: 1, color: :yellow) do request.headers.merge(extra_headers).each.map { |k, v| "#{stream.id}: -> HEADER: #{k}: #{v}" }.join("\n") end - stream.headers(request.headers.each(extra_headers), end_stream: request.empty?) + stream.headers(request.headers.each(extra_headers), end_stream: request.body.empty?) end def join_trailers(stream, request) @@ -234,7 +233,7 @@ module HTTPX end def join_body(stream, request) - return if request.empty? + return if request.body.empty? chunk = @drains.delete(request) || request.drain_body while chunk @@ -249,7 +248,9 @@ module HTTPX chunk = next_chunk end - on_stream_refuse(stream, request, request.drain_error) if request.drain_error + return unless (error = request.drain_error) + + on_stream_refuse(stream, request, error) end ###### @@ -257,8 +258,10 @@ module HTTPX ###### def on_stream_headers(stream, request, h) - if request.response && request.response.version == "2.0" - on_stream_trailers(stream, request, h) + response = request.response + + if response.is_a?(Response) && response.version == "2.0" + on_stream_trailers(stream, response, h) return end @@ -274,11 +277,11 @@ module HTTPX handle(request, stream) if request.expects? end - def on_stream_trailers(stream, request, h) + def on_stream_trailers(stream, response, h) log(color: :yellow) do h.map { |k, v| "#{stream.id}: <- HEADER: #{k}: #{v}" }.join("\n") end - request.response.merge_headers(h) + response.merge_headers(h) end def on_stream_data(stream, request, data) @@ -304,7 +307,7 @@ module HTTPX emit(:response, request, response) else response = request.response - if response.status == 421 + if response && response.status == 421 ex = MisdirectedRequestError.new(response) ex.set_backtrace(caller) emit(:error, request, ex) diff --git a/lib/httpx/headers.rb b/lib/httpx/headers.rb index b3604adf..72f74e87 100644 --- a/lib/httpx/headers.rb +++ b/lib/httpx/headers.rb @@ -57,7 +57,7 @@ module HTTPX def merge(other) headers = dup other.each do |field, value| - headers[field] = value + headers[downcased(field)] = value end headers end diff --git a/lib/httpx/parser/http1.rb b/lib/httpx/parser/http1.rb index 9ed11665..3edd3793 100644 --- a/lib/httpx/parser/http1.rb +++ b/lib/httpx/parser/http1.rb @@ -60,7 +60,7 @@ module HTTPX (m = %r{\AHTTP(?:/(\d+\.\d+))?\s+(\d\d\d)(?:\s+(.*))?}in.match(@buffer)) || raise(Error, "wrong head line format") version, code, _ = m.captures - raise(Error, "unsupported HTTP version (HTTP/#{version})") unless VERSIONS.include?(version) + raise(Error, "unsupported HTTP version (HTTP/#{version})") unless version && VERSIONS.include?(version) @http_version = version.split(".").map(&:to_i) @status_code = code.to_i diff --git a/lib/httpx/plugins/multipart/mime_type_detector.rb b/lib/httpx/plugins/multipart/mime_type_detector.rb index 9106469c..37317a17 100644 --- a/lib/httpx/plugins/multipart/mime_type_detector.rb +++ b/lib/httpx/plugins/multipart/mime_type_detector.rb @@ -17,7 +17,7 @@ module HTTPX elsif defined?(MimeMagic) - def call(file, *) + def call(file, _) mime = MimeMagic.by_magic(file) mime.type if mime end @@ -25,7 +25,7 @@ module HTTPX elsif system("which file", out: File::NULL) require "open3" - def call(file, *) + def call(file, _) return if file.eof? # file command returns "application/x-empty" for empty files Open3.popen3(*%w[file --mime-type --brief -]) do |stdin, stdout, stderr, thread| @@ -56,7 +56,7 @@ module HTTPX else - def call(*); end + def call(_, _); end end end diff --git a/lib/httpx/plugins/multipart/part.rb b/lib/httpx/plugins/multipart/part.rb index 575b125d..a8ef6e4a 100644 --- a/lib/httpx/plugins/multipart/part.rb +++ b/lib/httpx/plugins/multipart/part.rb @@ -8,7 +8,7 @@ module HTTPX def call(value) # take out specialized objects of the way if value.respond_to?(:filename) && value.respond_to?(:content_type) && value.respond_to?(:read) - return [value, value.content_type, value.filename] + return value, value.content_type, value.filename end content_type = filename = nil @@ -19,7 +19,7 @@ module HTTPX value = value[:body] end - value = value.open(:binmode => true) if Object.const_defined?(:Pathname) && value.is_a?(Pathname) + value = value.open(File::RDONLY) if Object.const_defined?(:Pathname) && value.is_a?(Pathname) if value.is_a?(File) filename ||= File.basename(value.path) diff --git a/lib/httpx/request.rb b/lib/httpx/request.rb index beca7eb1..5f6d50f2 100644 --- a/lib/httpx/request.rb +++ b/lib/httpx/request.rb @@ -46,9 +46,10 @@ module HTTPX @options = Options.new(options) @uri = Utils.to_uri(uri) if @uri.relative? - raise(Error, "invalid URI: #{@uri}") unless @options.origin + origin = @options.origin + raise(Error, "invalid URI: #{@uri}") unless origin - @uri = @options.origin.merge(@uri) + @uri = origin.merge(@uri) end raise(Error, "unknown method: #{verb}") unless METHODS.include?(@verb) @@ -96,7 +97,7 @@ module HTTPX def response=(response) return unless response - if response.status == 100 + if response.is_a?(Response) && response.status == 100 @informational_status = response.status return end @@ -156,7 +157,7 @@ module HTTPX class Body < SimpleDelegator class << self - def new(*, options) + def new(_, options) return options.body if options.body.is_a?(self) super From cdcbf14675a17b992b6678f45a3cd6906b91bb91 Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Tue, 17 Aug 2021 16:14:10 +0100 Subject: [PATCH 4/4] few sig changes (more assertive) --- sig/buffer.rbs | 4 +-- sig/connection.rbs | 2 +- sig/connection/http1.rbs | 14 +++++++--- sig/connection/http2.rbs | 21 +++++++++++---- sig/headers.rbs | 33 ++++++++++++----------- sig/options.rbs | 8 +++++- sig/parser/http1.rbs | 6 ++--- sig/plugins/aws_sigv4.rbs | 15 ++++++++--- sig/plugins/basic_authentication.rbs | 2 +- sig/plugins/multipart.rbs | 40 ++++++++++++++++++++++------ sig/request.rbs | 17 +++++++----- sig/response.rbs | 2 +- sig/session.rbs | 11 +++----- sig/transcoder.rbs | 3 +-- 14 files changed, 117 insertions(+), 61 deletions(-) diff --git a/sig/buffer.rbs b/sig/buffer.rbs index 55dc260f..c32d6bbe 100644 --- a/sig/buffer.rbs +++ b/sig/buffer.rbs @@ -1,7 +1,7 @@ module HTTPX class Buffer extend Forwardable - + include _ToS include _ToStr @@ -13,7 +13,7 @@ module HTTPX def shift!: (Integer) -> void # delegated - def <<: (string data) -> void + def <<: (string data) -> String def empty?: () -> bool def bytesize: () -> Integer def clear: () -> void diff --git a/sig/connection.rbs b/sig/connection.rbs index 34c4beb2..3284fa7f 100644 --- a/sig/connection.rbs +++ b/sig/connection.rbs @@ -1,6 +1,5 @@ module HTTPX class Connection - interface _Parser def on: (Symbol) { (*untyped) -> void } -> void @@ -47,6 +46,7 @@ module HTTPX def match_altsvcs?: (URI::Generic uri) -> bool def connecting?: () -> bool + def inflight?: () -> boolish def interests: () -> io_interests? diff --git a/sig/connection/http1.rbs b/sig/connection/http1.rbs index 7689764d..59f8c746 100644 --- a/sig/connection/http1.rbs +++ b/sig/connection/http1.rbs @@ -3,6 +3,10 @@ module HTTPX include Callbacks include Loggable + UPCASED: Hash[String, String] + MAX_REQUESTS: Integer + CRLF: String + attr_reader pending: Array[Request] attr_reader requests: Array[Request] @@ -30,11 +34,13 @@ module HTTPX def handle_error: (StandardError ex) -> void + def on_start: () -> void + def on_headers: (Hash[String, Array[String]] headers) -> void def on_trailers: (Hash[String, Array[String]] headers) -> void - def on_data: (string chunk) -> void + def on_data: (String chunk) -> void def on_complete: () -> void @@ -42,7 +48,7 @@ module HTTPX def ping: () -> void - def timeout: () -> Integer + def timeout: () -> Numeric private @@ -54,7 +60,7 @@ module HTTPX def disable_pipelining: () -> void - def set_protocol_headers: (Request) -> _Each[[headers_key, String]] + def set_protocol_headers: (Request) -> _Each[[String, String]] def headline_uri: (Request) -> String @@ -64,7 +70,7 @@ module HTTPX def join_trailers: (Request request) -> void - def join_headers2: (_Each[[headers_key, String]] headers) -> void + def join_headers2: (_Each[[String, String]] headers) -> void def join_body: (Request request) -> void diff --git a/sig/connection/http2.rbs b/sig/connection/http2.rbs index 694d588b..35c2bfef 100644 --- a/sig/connection/http2.rbs +++ b/sig/connection/http2.rbs @@ -3,10 +3,13 @@ module HTTPX include Callbacks include Loggable + MAX_CONCURRENT_REQUESTS: Integer + attr_reader streams: Hash[Request, HTTP2Next::Stream] attr_reader pending: Array[Request] @options: Options + @settings: Hash[Symbol, Integer | bool] @max_concurrent_requests: Integer @max_requests: Integer @drains: Hash[Request, String] @@ -23,7 +26,7 @@ module HTTPX def <<: (String) -> void - def can_buffer_more_requests: () -> bool + def can_buffer_more_requests?: () -> bool def send: (Request) -> void @@ -35,7 +38,7 @@ module HTTPX alias reset init_connection - def timeout: () -> Integer + def timeout: () -> Numeric private @@ -45,7 +48,7 @@ module HTTPX def headline_uri: (Request) -> String - def set_protocol_headers: (Request) -> _Each[[headers_key, String]] + def set_protocol_headers: (Request) -> _Each[[String, String]] def handle: (Request request, HTTP2Next::Stream stream) -> void @@ -61,9 +64,11 @@ module HTTPX def on_stream_headers: (HTTP2Next::Stream stream, Request request, Array[[String, String]] headers) -> void - def on_stream_trailers: (HTTP2Next::Stream stream, Request request, Array[[String, String]] headers) -> void + def on_stream_trailers: (HTTP2Next::Stream stream, Response response, Array[[String, String]] headers) -> void - def on_stream_data: (HTTP2Next::Stream stream, Request request, string data) -> void + def on_stream_data: (HTTP2Next::Stream stream, Request request, String data) -> void + + def on_stream_refuse: (HTTP2Next::Stream stream, Request request, StandardError error) -> void def on_stream_close: (HTTP2Next::Stream stream, Request request, (Symbol | StandardError)? error) -> void @@ -74,12 +79,18 @@ module HTTPX def on_close: (Integer last_frame, Symbol? error, String? payload) -> void def on_frame_sent: (HTTP2Next::frame) -> void + def on_frame_received: (HTTP2Next::frame) -> void + def on_altsvc: (String origin, HTTP2Next::frame) -> void + def on_promise: (HTTP2Next::Stream) -> void def on_origin: (String) -> void def on_pong: (string ping) -> void + + class Error < ::HTTPX::Error + end end end \ No newline at end of file diff --git a/sig/headers.rbs b/sig/headers.rbs index 6bae0e6b..b771d20f 100644 --- a/sig/headers.rbs +++ b/sig/headers.rbs @@ -2,30 +2,32 @@ module HTTPX class Headers include _ToS - @headers: Hash[headers_key, Array[String]] + EMPTY: Array[untyped] + + @headers: Hash[String, Array[String]] def self.new: (?untyped headers) -> instance def ==: (untyped other) -> bool - def []: (headers_key field) -> _ToS? - def []=: (headers_key field, headers_value value) -> void + def []: (String field) -> String? + def []=: (String field, headers_value value) -> void - def add: (headers_key field, string value) -> void - def delete: (headers_key field) -> Array[String]? + def add: (String field, string value) -> void + def delete: (String field) -> Array[String]? - def each: (?_Each[[headers_key, String]]? extra_headers) { (headers_key, String) -> void } -> void - | (?_Each[[headers_key, String]]? extra_headers) -> Enumerable[[headers_key, String]] + def each: (?_Each[[String, String]]? extra_headers) { (String k, String v) -> void } -> void + | (?_Each[[String, String]]? extra_headers) -> Enumerable[[String, String]] - def get: (headers_key field) -> Array[String] - def key?: (headers_key downcased_key) -> bool + def get: (String field) -> Array[String] + def key?: (String downcased_key) -> bool - def merge: (_Each[[headers_key, headers_value]] other) -> Headers + def merge: (_Each[[String, headers_value]] other) -> Headers def same_headers?: (untyped headers) -> bool - def to_a: () -> Array[[headers_key, String]] - def to_hash: () -> Hash[headers_key, String] + def to_a: () -> Array[[String, String]] + def to_hash: () -> Hash[String, String] alias to_h to_hash def inspect: () -> String @@ -34,12 +36,11 @@ module HTTPX def initialize: (?headers?) -> untyped def array_value: (headers_value) -> Array[String] - def downcased: (headers_key) -> String + def downcased: (_ToS field) -> String end - type headers_key = String | Symbol type headers_value = _ToS | Array[_ToS] - type headers_hash = Hash[headers_key, headers_value] - type headers_input = headers_hash | Array[[headers_key, string]] + type headers_hash = Hash[_ToS, headers_value] + type headers_input = headers_hash | Array[[_ToS, string]] type headers = Headers | headers_input end diff --git a/sig/options.rbs b/sig/options.rbs index 87149618..20be8271 100644 --- a/sig/options.rbs +++ b/sig/options.rbs @@ -11,7 +11,7 @@ module HTTPX DEFAULT_OPTIONS: Hash[Symbol, untyped] type timeout_type = :connect_timeout | :settings_timeout | :operation_timeout | :keep_alive_timeout | :total_timeout - type timeout = Hash[timeout_type, Numeric?] + type timeout = Hash[timeout_type, Numeric] def self.new: (?options) -> instance @@ -26,6 +26,9 @@ module HTTPX # timeout attr_reader timeout: timeout + # http2_settings + attr_reader http2_settings: Hash[Symbol, Integer | bool] + # max_concurrent_requests attr_reader max_concurrent_requests: Integer? @@ -59,6 +62,9 @@ module HTTPX # body attr_reader body: bodyIO? + # body + attr_reader origin: URI::Generic? + # ssl # http2_settings diff --git a/sig/parser/http1.rbs b/sig/parser/http1.rbs index 4e9eb716..d666ff57 100644 --- a/sig/parser/http1.rbs +++ b/sig/parser/http1.rbs @@ -5,9 +5,9 @@ module HTTPX interface _HTTP1Events def on_start: () -> void - def on_headers: (parsed_headers) -> void - def on_trailers: (parsed_headers) -> void - def on_data: (String) -> void + def on_headers: (parsed_headers headers) -> void + def on_trailers: (parsed_headers trailers) -> void + def on_data: (String data) -> void def on_complete: () -> void end diff --git a/sig/plugins/aws_sigv4.rbs b/sig/plugins/aws_sigv4.rbs index 78747207..24792f93 100644 --- a/sig/plugins/aws_sigv4.rbs +++ b/sig/plugins/aws_sigv4.rbs @@ -9,13 +9,21 @@ module HTTPX module AWSSigV4 - Credentials: _SigV4Credentials + class Credentials < Struct[[String, String, String?]] + attr_reader username: String + attr_reader password: String + attr_reader security_token: String? + end class Signer - def sign!: (Request) -> void + @unsigned_headers: Set[String] + def sign!: (Request & RequestMethods request) -> void + + def self.new: (instance) -> instance + | (**untyped params) -> instance private def initialize: ( @@ -33,9 +41,10 @@ module HTTPX ) -> untyped - def sha256_hexdigest: (bodyIO value) -> String + def hexdigest: (bodyIO value) -> String def hmac: (String key, String value) -> String + def hexhmac: (String key, String value) -> String end diff --git a/sig/plugins/basic_authentication.rbs b/sig/plugins/basic_authentication.rbs index 0f2414ad..6d7fd164 100644 --- a/sig/plugins/basic_authentication.rbs +++ b/sig/plugins/basic_authentication.rbs @@ -10,6 +10,6 @@ module HTTPX end end - type sessionBasicAuthentication = sessionAuthentication & BasicAuthentication::InstanceMethods + type sessionBasicAuthentication = sessionAuthentication & Authentication::InstanceMethods & BasicAuthentication::InstanceMethods end end diff --git a/sig/plugins/multipart.rbs b/sig/plugins/multipart.rbs index bddfd3e8..cdeacbb9 100644 --- a/sig/plugins/multipart.rbs +++ b/sig/plugins/multipart.rbs @@ -1,34 +1,55 @@ module HTTPX module Plugins module Multipart + interface _MultipartInput + def filename: () -> String + def content_type: () -> String + def read: (?int? length, ?string? output) -> String? + end + + MULTIPART_VALUE_COND: ^(_Reader | record_multipart_value value) -> bool + def self.load_dependencies: (singleton(Session)) -> void def self.configure: (*untyped) -> void def self?.encode: (untyped) -> (Encoder | Transcoder::Form::Encoder) def self?.decode: (HTTPX::Response response) -> Transcoder::_Decoder + def self?.normalize_keys: [U] (_ToS key, _ToAry[untyped] | _ToHash[_ToS, untyped] | untyped value) { (String, ?untyped) -> U } -> U + type multipart_value = string | Pathname | File | _Reader - type record_multipart_value = multipart_value | - { content_type: String, filename: String, body: multipart_value } | + type record_multipart_value = { content_type: String, filename: String, body: multipart_value } | { content_type: String, body: multipart_value } type multipart_nested_value = multipart_value | _ToAry[multipart_value] | _ToHash[string, multipart_value] class Encoder include Transcoder::_Encoder - include _Reader + + @boundary: String + @part_index: Integer + @buffer: String + + @form: Enumerable[[Symbol | string, multipart_nested_value]] + @parts: Array[_Reader] def content_type: () -> String + def read: (?int? length, ?string? buffer) -> String? + + def rewind: () -> void + private - def initialize: (_Each[[Symbol | string, multipart_nested_value]] multipart_data) -> untyped + def to_parts: (Enumerable[[Symbol | string, multipart_nested_value]] multipart_data) -> Array[_Reader] + + def initialize: (Enumerable[[Symbol | string, multipart_nested_value]] multipart_data) -> untyped def header_part: (string key, String content_type, String? filename) -> StringIO - def read_chunks: (String buffer, Integer? length) -> void + def read_chunks: (String buffer, ?Integer? length) -> void - def read_from_part: (Integer? max_length) -> void + def read_from_part: (?Integer? max_length) -> String? end class Decoder @@ -63,11 +84,14 @@ module HTTPX end module Part - def self?.call: (multipart_nested_value) -> ([_Reader, String, String?]) + def self?.call: [U] (_MultipartInput multipart_input) -> [U, String, String] + | (multipart_nested_value input) -> ([StringIO, String, String?] | [File, String, String]) end module MimeTypeDetector - def self?.call: (::IO file, ?String filename) -> String? + DEFAULT_MIMETYPE: String + + def self?.call: (::IO file, String filename) -> String? end end end diff --git a/sig/request.rbs b/sig/request.rbs index eb06e5b0..65ccff1f 100644 --- a/sig/request.rbs +++ b/sig/request.rbs @@ -1,12 +1,13 @@ module HTTPX class Request + extend Forwardable include Callbacks - METHODS: Array[verb] + METHODS: Array[Symbol] USER_AGENT: String - attr_reader verb: verb - attr_reader uri: URI::HTTP | URI::HTTPS + attr_reader verb: Symbol + attr_reader uri: URI::Generic attr_reader headers: Headers attr_reader body: Body attr_reader state: Symbol @@ -14,13 +15,13 @@ module HTTPX attr_reader response: response? attr_reader drain_error: StandardError? - def initialize: (verb | String, generic_uri, ?options?) -> untyped + def initialize: (Symbol | String, generic_uri, ?options) -> untyped def interests: () -> (:r | :w) - def merge_headers: (_Each[[headers_key, headers_value]]) -> void + def merge_headers: (_Each[[String, headers_value]]) -> void - def scheme: () -> ("http" | "https") + def scheme: () -> String def response=: (response) -> void @@ -49,6 +50,7 @@ module HTTPX def each: () { (String) -> void } -> void | () -> Enumerable[String] + def rewind: () -> void def empty?: () -> bool def bytesize: () -> Numeric def stream: (Transcoder::_Encoder) -> bodyIO @@ -59,8 +61,9 @@ module HTTPX end class ProcIO - include _Writer def initialize: (^(String) -> void) -> untyped + + def write: (String data) -> Integer end end end diff --git a/sig/response.rbs b/sig/response.rbs index 45aa52ed..eb7a0916 100644 --- a/sig/response.rbs +++ b/sig/response.rbs @@ -22,7 +22,7 @@ module HTTPX def close: () -> void def uri: () -> URI::Generic - def merge_headers: (_Each[[headers_key, headers_value]]) -> void + def merge_headers: (_Each[[String, headers_value]]) -> void def bodyless?: () -> bool def content_type: () -> ContentType def complete?: () -> bool diff --git a/sig/session.rbs b/sig/session.rbs index 3e12d143..f2fc9190 100644 --- a/sig/session.rbs +++ b/sig/session.rbs @@ -9,19 +9,16 @@ module HTTPX @responses: Hash[Request, response] @persistent: bool? + def self.plugin: (Symbol | Module plugin, ?options? options) ?{ (Class) -> void } -> singleton(Session) + + def self.default_options: -> Options + def wrap: () { (instance) -> void } -> void def close: (*untyped) -> void def build_request: (String | verb, generic_uri, ?options) -> Request - # def self.plugin: (Symbol | Module, ?options) { (Class) -> void } -> singleton(Session) - # | (Symbol | Module, ?options) -> singleton(Session) - - - - def self.default_options: -> Options - private def initialize: (?options) { (self) -> void } -> untyped diff --git a/sig/transcoder.rbs b/sig/transcoder.rbs index 418a64d2..d40aad5e 100644 --- a/sig/transcoder.rbs +++ b/sig/transcoder.rbs @@ -7,8 +7,7 @@ module HTTPX def self?.register: (String tag, _Encode handler) -> void - def self?.normalize_keys: (_ToS key, _ToAry[untyped] | _ToHash[_ToS, untyped] | untyped value) { (String, ?untyped) -> void } -> void - | (_ToS key, untyped value, Proc? cond) { (String, untyped) -> void } -> void + def self?.normalize_keys: [U] (_ToS key, _ToAry[untyped] | _ToHash[_ToS, untyped] | untyped value, ?(^(untyped value) -> bool | nil) cond) { (String, ?untyped) -> U } -> U def self?.normalize_query: (Hash[String, untyped] params, String name, String v, Integer depth) -> void