Skip to content

Commit cb21e4c

Browse files
committed
Update RBS signatures and fix type errors
Update the public RBS to better match actual net/http behavior around URI handling, nilable headers and response bodies, exception classes, and request/response entry points. Keep shipped signatures in sig/ focused on net/http’s public API, and add a separate *-impl.rbs files for implementation-only declarations used only by Steep when typechecking lib/. The *-impl.rbs files cover internal protocol classes, helper methods, constants, and stdlib gaps needed by the implementation, without shipping those internal details as part of the gem’s public RBS.
1 parent 336fb86 commit cb21e4c

File tree

4 files changed

+393
-63
lines changed

4 files changed

+393
-63
lines changed

net-http.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
3030

3131
# Specify which files should be added to the gem when it is released.
3232
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
33-
excludes = %W[/.git* /bin /test /*file /#{File.basename(__FILE__)}]
33+
excludes = %W[/.git* /bin /test /steep_sig /sig/*-impl.rbs /*file /#{File.basename(__FILE__)}]
3434
spec.files = IO.popen(%W[git -C #{__dir__} ls-files -z --] + excludes.map {|e| ":^#{e}"}, &:read).split("\x0")
3535
spec.bindir = "exe"
3636
spec.require_paths = ["lib"]

sig/net-http-impl.rbs

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
class URI::Generic
2+
def authority: () -> String?
3+
end
4+
5+
module Win32
6+
module SSPI
7+
class NegotiateAuth
8+
def self.new: () -> NegotiateAuth
9+
def get_initial_token: () -> String
10+
def complete_authentication: (String authphrase) -> String
11+
end
12+
end
13+
end
14+
15+
module Net
16+
class HTTPAuthenticationError < StandardError
17+
def initialize: (String msg, untyped err) -> void
18+
end
19+
20+
module HTTPHeader
21+
@header: Hash[String, Array[String]]
22+
@body: String?
23+
@body_data: Array[untyped] | Hash[untyped, untyped] | nil
24+
@body_stream: untyped
25+
@form_option: Hash[Symbol, untyped]
26+
27+
attr_accessor body: String?
28+
end
29+
30+
class HTTP
31+
@address: String
32+
@port: Integer
33+
@ipaddr: String?
34+
@local_host: String?
35+
@local_port: Integer?
36+
@curr_http_version: String
37+
@keep_alive_timeout: Float | Integer
38+
@last_communicated: Float?
39+
@close_on_empty_response: bool
40+
@socket: Net::BufferedIO?
41+
@started: bool
42+
@open_timeout: Float | Integer
43+
@read_timeout: Float | Integer
44+
@write_timeout: Float | Integer
45+
@continue_timeout: Float | Integer | nil
46+
@max_retries: Integer
47+
@debug_output: IO?
48+
@response_body_encoding: Encoding | false | nil
49+
@ignore_eof: bool
50+
@tcpsocket_supports_open_timeout: bool?
51+
@proxy_from_env: bool
52+
@proxy_uri: URI::Generic | false | nil
53+
@proxy_address: String?
54+
@proxy_port: Integer?
55+
@proxy_user: String?
56+
@proxy_pass: String?
57+
@proxy_use_ssl: bool?
58+
@use_ssl: bool
59+
@ssl_context: OpenSSL::SSL::SSLContext?
60+
@ssl_session: OpenSSL::SSL::Session?
61+
@sspi_enabled: bool
62+
self.@is_proxy_class: bool
63+
self.@proxy_from_env: bool
64+
self.@proxy_addr: String?
65+
self.@proxy_address: String?
66+
self.@proxy_port: Integer?
67+
self.@proxy_user: String?
68+
self.@proxy_pass: String?
69+
self.@proxy_use_ssl: bool?
70+
71+
TCP_SOCKET_NEW_HAS_OPEN_TIMEOUT: bool
72+
IDEMPOTENT_METHODS_: Array[String]
73+
74+
def initialize: (String address, ?Integer? port) -> void
75+
def do_start: () -> void
76+
def connect: () -> void
77+
def timeouted_connect: (String? conn_addr, Integer? conn_port) -> TCPSocket
78+
def on_connect: () -> void
79+
def do_finish: () -> void
80+
def unescape: (String value) -> String
81+
def conn_address: () -> String?
82+
def conn_port: () -> Integer?
83+
def edit_path: (String path) -> String
84+
def send_entity: (String | URI::HTTP path, String data, headers? initheader, untyped dest, singleton(Net::HTTPRequest) type) ?{ (String body_segment) -> void } -> Net::HTTPResponse
85+
def transport_request: (Net::HTTPGenericRequest req) ?{ (Net::HTTPResponse response) -> void } -> Net::HTTPResponse
86+
def begin_transport: (Net::HTTPGenericRequest req) -> void
87+
def end_transport: (Net::HTTPGenericRequest req, Net::HTTPResponse res) -> void
88+
def keep_alive?: (Net::HTTPGenericRequest req, Net::HTTPResponse res) -> bool
89+
def sspi_auth?: (Net::HTTPResponse res) -> bool
90+
def sspi_auth: (Net::HTTPGenericRequest req) -> untyped
91+
def addr_port: () -> String
92+
def debug: (String msg) -> void
93+
94+
alias D debug
95+
end
96+
97+
class HTTPSession = HTTP
98+
99+
module HTTP::ProxyDelta
100+
def proxy_address: () -> String?
101+
def proxy_port: () -> Integer?
102+
def use_ssl?: () -> bool
103+
def addr_port: () -> String
104+
def conn_address: () -> String?
105+
def conn_port: () -> Integer?
106+
def edit_path: (String path) -> String
107+
end
108+
109+
class HTTPRequest
110+
METHOD: String
111+
REQUEST_HAS_BODY: bool
112+
RESPONSE_HAS_BODY: bool
113+
end
114+
115+
class HTTPGenericRequest
116+
@method: String
117+
@request_has_body: bool
118+
@response_has_body: bool
119+
@uri: URI::Generic?
120+
@path: String
121+
@decode_content: bool
122+
@body: String?
123+
@body_stream: untyped
124+
@body_data: Array[untyped] | Hash[untyped, untyped] | nil
125+
126+
def set_body_internal: (String? str) -> void
127+
def exec: (Net::BufferedIO sock, String ver, String path) -> void
128+
def update_uri: (String address, Integer port, bool ssl) -> void
129+
def pretty_print: (untyped q) -> void
130+
def send_request_with_body: (Net::BufferedIO sock, String ver, String path, String body) -> void
131+
def send_request_with_body_stream: (Net::BufferedIO sock, String ver, String path, untyped body_stream) -> void
132+
def send_request_with_body_data: (Net::BufferedIO sock, String ver, String path, untyped params) -> void
133+
def encode_multipart_form_data: (untyped out, untyped params, untyped opt) -> void
134+
def quote_string: (String str, untyped charset) -> String
135+
def flush_buffer: (untyped out, String? buf, bool chunked_p) -> untyped
136+
def wait_for_continue: (Net::BufferedIO sock, String ver) -> void
137+
def write_header: (Net::BufferedIO sock, String ver, String path) -> Integer
138+
139+
class Chunker
140+
@sock: Net::BufferedIO
141+
142+
def initialize: (Net::BufferedIO sock) -> void
143+
def write: (*_ToS buf) -> Integer
144+
def finish: () -> Integer
145+
end
146+
end
147+
148+
class HTTPResponse
149+
@http_version: String?
150+
@code: String
151+
@message: String?
152+
@body: String?
153+
@read: bool
154+
@uri: URI::Generic?
155+
@decode_content: bool
156+
@body_encoding: Encoding | false | nil
157+
@ignore_eof: bool
158+
@socket: Net::BufferedIO?
159+
@body_exist: bool
160+
161+
HAS_BODY: bool
162+
EXCEPTION_TYPE: untyped
163+
def self.read_new: (Net::BufferedIO sock) -> Net::HTTPResponse
164+
def self.exception_type: () -> untyped
165+
def self.read_status_line: (Net::BufferedIO sock) -> [String?, String, String?]
166+
def self.response_class: (String code) -> singleton(Net::HTTPResponse)
167+
def self.each_response_header: (Net::BufferedIO sock) { (String, String) -> void } -> void
168+
169+
def initialize: (String? httpv, String code, String? msg) -> void
170+
def body_encoding=: (Encoding | String | false | nil value) -> (Encoding | false | nil)
171+
def ignore_eof=: (bool value) -> bool
172+
def response: () -> self
173+
def header: () -> self
174+
def read_header: () -> self
175+
def reading_body: (Net::BufferedIO sock, bool reqmethodallowbody) { () -> untyped } -> String?
176+
def detect_encoding: (String str, ?Encoding? encoding) -> Encoding?
177+
def sniff_encoding: (String str, ?Encoding? encoding) -> Encoding?
178+
def check_bom: (String str) -> Encoding?
179+
def scanning_meta: (String str) -> Encoding?
180+
def get_attribute: (StringScanner ss) -> [String, String]?
181+
def extracting_encodings_from_meta_elements: (String value) -> String?
182+
def inflater: () { (untyped io) -> untyped } -> untyped
183+
def read_body_0: (untyped dest) -> void
184+
def read_chunked: (untyped dest, untyped chunk_data_io) -> void
185+
def stream_check: () -> void
186+
def procdest: (untyped dest, untyped block) -> untyped
187+
188+
class Inflater
189+
@socket: Net::BufferedIO
190+
@inflate: Zlib::Inflate
191+
192+
def initialize: (Net::BufferedIO socket) -> void
193+
def finish: () -> void
194+
def bytes_inflated: () -> Integer
195+
def inflate_adapter: (untyped dest) -> Net::ReadAdapter
196+
def read: (Integer clen, untyped dest, ?bool ignore_eof) -> untyped
197+
def read_all: (untyped dest) -> untyped
198+
end
199+
end
200+
end

0 commit comments

Comments
 (0)