diff --git a/sig/plugins/multipart.rbs b/sig/plugins/multipart.rbs index 89126add..62399621 100644 --- a/sig/plugins/multipart.rbs +++ b/sig/plugins/multipart.rbs @@ -3,18 +3,41 @@ module HTTPX module Multipart def self.load_dependencies: (singleton(Session)) -> void def self.configure: (*untyped) -> void - def self?.encode: (untyped) -> Encoder + def self?.encode: (untyped) -> (Encoder | Transcoder::Form::Encoder) + + type multipart_value = string | Pathname | File | _Reader + + type record_multipart_value = 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] + + type multipart_input = Enumerable[[string, multipart_value], untyped] class Encoder include Transcoder::_Encoder - include _ToS include _Reader + def content_type: () -> String + private - def initialize: (Hash[Symbol | string, HTTP::FormData::Part | string] multipart_data) -> untyped + def initialize: (Hash[Symbol | string, multipart_nested_value] multipart_data) -> untyped - def multipart?: (top) -> bool + def header_part: (string key, String content_type, String? filename) -> StringIO + + def read_chunks: (String buffer, Integer? length) -> void + + def read_from_part: (Integer? max_length) -> void + end + + module Part + def self?.call: (multipart_nested_value) -> ([_Reader, String, String?] | [_Reader, String]) + end + + module MimeTypeDetector + def self?.call: (IO file, ?String filename) -> String? end end end diff --git a/sig/transcoder.rbs b/sig/transcoder.rbs index e151c902..84785d48 100644 --- a/sig/transcoder.rbs +++ b/sig/transcoder.rbs @@ -4,8 +4,8 @@ module HTTPX module Transcoder extend HTTPX::Registry[String, Class] - def self.normalize_keys: (string | Symbol, top) { (string, top) -> void } -> void - | (string | Symbol, top) { (string) -> void } -> void + def self.normalize_keys: (string | Symbol, top, ?Proc?) { (string, top) -> void } -> void + | (string | Symbol, top, ?Proc?) { (string) -> void } -> void interface _Encoder def bytesize: () -> Numeric diff --git a/sig/transcoder/body.rbs b/sig/transcoder/body.rbs index 1969f3fd..4af5a0c9 100644 --- a/sig/transcoder/body.rbs +++ b/sig/transcoder/body.rbs @@ -7,6 +7,8 @@ module HTTPX @raw: bodyIO + def content_type: () -> String + private def initialize: (untyped body ) -> untyped diff --git a/sig/transcoder/form.rbs b/sig/transcoder/form.rbs index 7981be20..cd7b5fec 100644 --- a/sig/transcoder/form.rbs +++ b/sig/transcoder/form.rbs @@ -1,5 +1,9 @@ module HTTPX::Transcoder - type urlencoded_input = Enumerable[[string, string], untyped] + type form_value = string + + type form_nested_value = form_value | _ToAry[form_value] | _ToHash[string, form_value] + + type urlencoded_input = Enumerable[[string, form_nested_value], untyped] module Form def self?.encode: (urlencoded_input form) -> Encoder @@ -8,6 +12,8 @@ module HTTPX::Transcoder include _Encoder include _ToS + def content_type: () -> String + private def initialize: (urlencoded_input form) -> untyped diff --git a/sig/transcoder/json.rbs b/sig/transcoder/json.rbs index c1f14770..c9b51412 100644 --- a/sig/transcoder/json.rbs +++ b/sig/transcoder/json.rbs @@ -6,9 +6,11 @@ module HTTPX::Transcoder include _Encoder include _ToS + def content_type: () -> String + private - def initalize: (_ToJson json) -> untyped + def initialize: (_ToJson json) -> untyped end end end diff --git a/test/support/ci/build.sh b/test/support/ci/build.sh index c3b2c4f4..5287e92e 100755 --- a/test/support/ci/build.sh +++ b/test/support/ci/build.sh @@ -35,7 +35,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 -ruri -rjson -ripaddr -rhttp-2-next" + export RBS_TEST_OPT="-Isig -ruri -rjson -ripaddr -rpathname -rhttp-2-next" export RBS_TEST_TARGET="HTTP*" fi