few sig changes (more assertive)

This commit is contained in:
HoneyryderChuck 2021-08-17 16:14:10 +01:00
parent 74dfb18ed3
commit cdcbf14675
14 changed files with 117 additions and 61 deletions

View File

@ -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

View File

@ -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?

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -10,6 +10,6 @@ module HTTPX
end
end
type sessionBasicAuthentication = sessionAuthentication & BasicAuthentication::InstanceMethods
type sessionBasicAuthentication = sessionAuthentication & Authentication::InstanceMethods & BasicAuthentication::InstanceMethods
end
end

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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