added more typing, improved correctness of a few checks

This commit is contained in:
HoneyryderChuck 2023-04-28 17:25:15 +01:00
parent bd233c5303
commit cfac38dc62
14 changed files with 40 additions and 18 deletions

View File

@ -101,7 +101,7 @@ module HTTPX
# was the result of coalescing. To prevent blind trust in the case where the
# origin came from an ORIGIN frame, we're going to verify the hostname with the
# SSL certificate
(@origins.size == 1 || @origin == uri.origin || (@io && @io.verify_hostname(uri.host)))
(@origins.size == 1 || @origin == uri.origin || (@io.is_a?(SSL) && @io.verify_hostname(uri.host)))
) && @options == options
) || (match_altsvcs?(uri) && match_altsvc_options?(uri, options))
end
@ -115,7 +115,7 @@ module HTTPX
(
(open? && @origin == connection.origin) ||
!(@io.addresses & connection.addresses).empty?
!(@io.addresses & (connection.addresses || [])).empty?
) && @options == connection.options
end

View File

@ -203,6 +203,7 @@ module HTTPX
end
def receive_requests(requests, connections)
# @type var responses: Array[response]
responses = []
begin

View File

@ -34,7 +34,13 @@ module HTTPX
@write_buffer: Buffer
@inflight: Integer
@keep_alive_timeout: Numeric?
@timeout: Numeric?
@current_timeout: Numeric?
@total_timeout: Numeric?
@io: TCP | SSL | UNIX
@parser: HTTP1 | HTTP2 | _Parser
@connected_at: Float
@response_received_at: Float
def addresses: () -> Array[ipaddr]?
@ -75,6 +81,8 @@ module HTTPX
def deactivate: () -> void
def open?: () -> bool
def raise_timeout_error: (Numeric interval) -> void
private
@ -89,17 +97,18 @@ module HTTPX
def send_pending: () -> void
def parser: () -> _Parser
def parser: () -> (HTTP1 | HTTP2 | _Parser)
def send_request_to_parser: (Request request) -> void
def build_parser: () -> _Parser
| (String) -> _Parser
def build_parser: (?String protocol) -> (HTTP1 | HTTP2)
def set_parser_callbacks: (_Parser) -> void
def set_parser_callbacks: (HTTP1 | HTTP2 parser) -> void
def transition: (Symbol) -> void
def handle_transition: (Symbol) -> void
def build_socket: (?Array[ipaddr]? addrs) -> (TCP | SSL | UNIX)
def on_error: (HTTPX::TimeoutError | Error | StandardError) -> void

View File

@ -2,6 +2,12 @@ module HTTPX
class Error < StandardError
end
class UnsupportedSchemeError < Error
end
class ConnectionError < Error
end
class TimeoutError < Error
attr_reader timeout: Numeric
@ -55,4 +61,7 @@ module HTTPX
def initialize: (Connection connection, String hostname, ?String message) -> untyped
end
class MisdirectedRequestError < HTTPError
end
end

View File

@ -1,6 +1,9 @@
module HTTPX
IPRegex: Regexp
class TLSError < OpenSSL::SSL::SSLError
end
class SSL < TCP
TLS_OPTIONS: Hash[Symbol, untyped]

View File

@ -10,7 +10,7 @@ module HTTPX
attr_reader state: Symbol
attr_reader interests: Symbol
attr_reader interests: io_interests
alias host ip

View File

@ -46,7 +46,7 @@ module HTTPX
attr_reader body_threshold_size: Integer
# transport
attr_reader transport: String?
attr_reader transport: "unix" | nil
# transport_options
attr_reader transport_options: Hash[untyped, untyped]?

View File

@ -13,8 +13,8 @@ module HTTPX
def []: (uri) -> Array[Cookie]
def each: (?uri) { (Cookie) -> void } -> void
| (?uri) -> Enumerable[Cookie]
def each: (?uri?) { (Cookie) -> void } -> void
| (?uri?) -> Enumerable[Cookie]
def merge: (_Each[cookie] cookies) -> instance

View File

@ -2,7 +2,7 @@ module HTTPX
module Plugins
module Retries
MAX_RETRIES: Integer
IDEMPOTENT_METHODS: Array[verb]
IDEMPOTENT_METHODS: Array[String]
RETRYABLE_ERRORS: Array[singleton(StandardError)]
DEFAULT_JITTER: ^(Numeric) -> Numeric

View File

@ -7,7 +7,7 @@ module HTTPX
USER_AGENT: String
attr_reader verb: verb
attr_reader uri: URI::Generic
attr_reader uri: URI::HTTP | URI::HTTPS
attr_reader headers: Headers
attr_reader body: Body
attr_reader state: Symbol

View File

@ -22,7 +22,7 @@ module HTTPX
def self?.resolver_for: (:native resolver_type) -> singleton(Native) |
(:system resolver_type) -> singleton(System) |
(:https resolver_type) -> singleton(HTTPS) |
(singleton(Resolver::Resolver) resolver_type) -> singleton(Resolver::Resolver)
[U] (U resolver_type) -> U
def self?.cached_lookup: (String hostname) -> Array[IPAddr]?

View File

@ -48,7 +48,7 @@ module HTTPX
include _ToS
include _ToStr
attr_reader encoding: String
attr_reader encoding: Encoding | String
@response: Response
@headers: Headers

View File

@ -11,8 +11,6 @@ module HTTPX
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
@ -41,12 +39,14 @@ module HTTPX
| (verb, _Each[[uri, options]], Options) -> Array[Request]
| (verb, _Each[uri], options) -> Array[Request]
def build_connection: (URI::Generic, Options) -> Connection
def build_connection: (URI::HTTP | URI::HTTPS uri, Options options) -> Connection
def send_requests: (*Request) -> Array[response]
def _send_requests: (Array[Request]) -> Array[Connection]
def receive_requests: (Array[Request], Array[Connection]) -> Array[response]
attr_reader self.default_options: Options
end
end

View File

@ -1,5 +1,5 @@
module HTTPX::Transcoder
module XML
module Xml
def self?.encode: (untyped xml) -> Encoder
def self?.decode: (HTTPX::Response response) -> _Decoder