Skip to content

Commit 818830b

Browse files
authored
Merge pull request #151 from ruby/add-rbs
Add RBS files
2 parents 9350944 + 12b4027 commit 818830b

38 files changed

+1849
-0
lines changed

.github/workflows/test.yml

+3
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ jobs:
3434
bundler-cache: true # 'bundle install' and cache
3535
- name: Run test
3636
run: bundle exec rake test
37+
- name: RBS validate
38+
run: bundle exec rbs -r openssl -r digest -r uri -r erb -r singleton -r tempfile -r socket -I sig validate
39+
if: ${{ ! startsWith(matrix.ruby, '2.') }} # rbs requires ruby 3.0+

Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ gemspec
55
gem "rake"
66
gem "test-unit"
77
gem "test-unit-ruby-core"
8+
9+
# rbs requires ruby 3.0+
10+
gem "rbs", require: false if !RUBY_VERSION.start_with?('2.')

sig/accesslog.rbs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module WEBrick
2+
module AccessLog
3+
class AccessLogError < StandardError
4+
end
5+
6+
CLF_TIME_FORMAT: String
7+
8+
COMMON_LOG_FORMAT: String
9+
10+
CLF: String
11+
12+
REFERER_LOG_FORMAT: String
13+
14+
AGENT_LOG_FORMAT: String
15+
16+
COMBINED_LOG_FORMAT: String
17+
18+
def self?.setup_params: (Hash[Symbol, untyped] config, HTTPRequest req, HTTPResponse res) -> Hash[String, untyped]
19+
20+
def self?.format: (String format_string, Hash[String, untyped] params) -> String
21+
22+
def self?.escape: (String data) -> String
23+
end
24+
end

sig/cgi.rbs

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
module WEBrick
2+
class CGI
3+
@options: Array[untyped]
4+
5+
class CGIError < StandardError
6+
end
7+
8+
attr_reader config: Hash[Symbol, untyped]
9+
10+
attr_reader logger: BasicLog
11+
12+
def initialize: (*untyped args) -> void
13+
14+
def []: (Symbol key) -> untyped
15+
16+
interface _Env
17+
def []: (String) -> String?
18+
end
19+
20+
def start: (?_Env env, ?IO stdin, ?IO stdout) -> void
21+
22+
def self.setup_header: () -> untyped
23+
24+
def self.status_line: () -> ""
25+
26+
def service: (HTTPRequest req, HTTPResponse res) -> void
27+
28+
class Socket
29+
@config: Hash[Symbol, untyped]
30+
31+
@env: _Env
32+
33+
@header_part: StringIO
34+
35+
@body_part: IO
36+
37+
@out_port: IO
38+
39+
@server_addr: String
40+
41+
@server_name: String?
42+
43+
@server_port: String?
44+
45+
@remote_addr: String?
46+
47+
@remote_host: String?
48+
49+
@remote_port: (String | 0)
50+
51+
include Enumerable[String]
52+
53+
private
54+
55+
def initialize: (Hash[Symbol, untyped] config, _Env env, IO stdin, IO stdout) -> void
56+
57+
def request_line: () -> String
58+
59+
def setup_header: () -> void
60+
61+
def add_header: (String hdrname, String value) -> void
62+
63+
def input: () -> (IO | StringIO)
64+
65+
public
66+
67+
def peeraddr: () -> [nil, (String | 0), String?, String?]
68+
69+
def addr: () -> [nil, String?, String?, String]
70+
71+
def gets: (?String eol, ?Integer? size) -> String?
72+
73+
def read: (?Integer? size) -> String?
74+
75+
def each: () { (String) -> void } -> void
76+
77+
def eof?: () -> bool
78+
79+
def <<: (_ToS data) -> IO
80+
81+
def write: (_ToS data) -> Integer
82+
83+
def cert: () -> OpenSSL::X509::Certificate?
84+
85+
def peer_cert: () -> OpenSSL::X509::Certificate?
86+
87+
def peer_cert_chain: () -> Array[OpenSSL::X509::Certificate]?
88+
89+
def cipher: () -> [String?, String?, String?, String?]?
90+
end
91+
end
92+
end

sig/compat.rbs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# System call error module used by webrick for cross platform compatibility.
3+
#
4+
# EPROTO:: protocol error
5+
# ECONNRESET:: remote host reset the connection request
6+
# ECONNABORTED:: Client sent TCP reset (RST) before server has accepted the
7+
# connection requested by client.
8+
#
9+
module Errno
10+
class EPROTO < SystemCallError
11+
end
12+
13+
class ECONNRESET < SystemCallError
14+
end
15+
16+
class ECONNABORTED < SystemCallError
17+
end
18+
end

sig/config.rbs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module WEBrick
2+
module Config
3+
LIBDIR: String
4+
5+
# for GenericServer
6+
General: Hash[Symbol, untyped]
7+
8+
# for HTTPServer, HTTPRequest, HTTPResponse ...
9+
HTTP: Hash[Symbol, untyped]
10+
11+
FileHandler: Hash[Symbol, untyped]
12+
13+
BasicAuth: Hash[Symbol, untyped]
14+
15+
DigestAuth: Hash[Symbol, untyped]
16+
end
17+
end

sig/cookie.rbs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module WEBrick
2+
class Cookie
3+
@expires: String?
4+
5+
attr_reader name: String?
6+
7+
attr_accessor value: String?
8+
9+
attr_accessor version: Integer
10+
11+
#
12+
# The cookie domain
13+
attr_accessor domain: String?
14+
15+
attr_accessor path: String?
16+
17+
attr_accessor secure: true?
18+
19+
attr_accessor comment: String?
20+
21+
attr_accessor max_age: Integer?
22+
23+
def initialize: (untyped name, untyped value) -> void
24+
25+
def expires=: ((Time | _ToS)? t) -> untyped
26+
27+
def expires: () -> Time?
28+
29+
def to_s: () -> String
30+
31+
def self.parse: (String? str) -> Array[instance]?
32+
33+
def self.parse_set_cookie: (String str) -> instance
34+
35+
def self.parse_set_cookies: (String str) -> Array[instance]
36+
end
37+
end

sig/htmlutils.rbs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module WEBrick
2+
module HTMLUtils
3+
def self?.escape: (String? string) -> String
4+
end
5+
end

sig/httpauth.rbs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module WEBrick
2+
module HTTPAuth
3+
interface _Callable
4+
def call: (String user, String pass) -> bool
5+
end
6+
7+
def self?._basic_auth: (HTTPRequest req, HTTPResponse res, String realm, String req_field, String res_field, HTTPStatus::Error err_type, _Callable block) -> void
8+
9+
def self?.basic_auth: (HTTPRequest req, HTTPResponse res, String realm) { (String user, String pass) -> bool } -> void
10+
11+
def self?.proxy_basic_auth: (HTTPRequest req, HTTPResponse res, String realm) { (String user, String pass) -> bool } -> void
12+
end
13+
end

sig/httpauth/authenticator.rbs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
module WEBrick
2+
module HTTPAuth
3+
module Authenticator
4+
@reload_db: bool?
5+
6+
@request_field: String
7+
8+
@response_field: String
9+
10+
@resp_info_field: String
11+
12+
@auth_exception: singleton(HTTPStatus::ClientError)
13+
14+
@auth_scheme: String
15+
16+
RequestField: String
17+
18+
ResponseField: String
19+
20+
ResponseInfoField: String
21+
22+
AuthException: singleton(HTTPStatus::ClientError)
23+
24+
AuthScheme: String?
25+
26+
attr_reader realm: String?
27+
28+
attr_reader userdb: UserDB
29+
30+
attr_reader logger: Log
31+
32+
private
33+
34+
def check_init: (Hash[Symbol, untyped] config) -> void
35+
36+
def check_scheme: (HTTPRequest req) -> String?
37+
38+
def log: (interned meth, String fmt, *untyped args) -> void
39+
40+
def error: (String fmt, *untyped args) -> void
41+
42+
def info: (String fmt, *untyped args) -> void
43+
end
44+
45+
module ProxyAuthenticator
46+
RequestField: String
47+
48+
ResponseField: String
49+
50+
InfoField: String
51+
52+
AuthException: singleton(HTTPStatus::ClientError)
53+
end
54+
end
55+
end

sig/httpauth/basicauth.rbs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module WEBrick
2+
module HTTPAuth
3+
class BasicAuth
4+
@config: Hash[Symbol, untyped]
5+
6+
include Authenticator
7+
8+
AuthScheme: String
9+
10+
def self.make_passwd: (String? realm, String? user, String? pass) -> String
11+
12+
attr_reader realm: String?
13+
14+
attr_reader userdb: UserDB
15+
16+
attr_reader logger: Log
17+
18+
def initialize: (Hash[Symbol, untyped] config, ?Hash[Symbol, untyped] default) -> void
19+
20+
def authenticate: (HTTPRequest req, HTTPResponse res) -> void
21+
22+
def challenge: (HTTPRequest req, HTTPResponse res) -> bot
23+
end
24+
25+
class ProxyBasicAuth < BasicAuth
26+
include ProxyAuthenticator
27+
end
28+
end
29+
end

sig/httpauth/digestauth.rbs

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
module WEBrick
2+
module HTTPAuth
3+
class DigestAuth
4+
@config: Hash[Symbol, untyped]
5+
6+
@domain: Array[String]?
7+
8+
@use_opaque: bool
9+
10+
@use_next_nonce: bool
11+
12+
@check_nc: bool
13+
14+
@use_auth_info_header: bool
15+
16+
@nonce_expire_period: Integer
17+
18+
@nonce_expire_delta: Integer
19+
20+
@internet_explorer_hack: bool
21+
22+
@h: singleton(Digest::Base)
23+
24+
@instance_key: String
25+
26+
@opaques: Hash[String, OpaqueInfo]
27+
28+
@last_nonce_expire: Time
29+
30+
@mutex: Thread::Mutex
31+
32+
include Authenticator
33+
34+
AuthScheme: String
35+
36+
class OpaqueInfo < Struct[untyped]
37+
attr_accessor time(): Time
38+
attr_accessor nonce(): String?
39+
attr_accessor nc(): String
40+
end
41+
42+
attr_reader algorithm: String?
43+
44+
attr_reader qop: Array[String]
45+
46+
def self.make_passwd: (String realm, String user, String pass) -> untyped
47+
48+
def initialize: (Hash[Symbol, untyped] config, ?Hash[Symbol, untyped] default) -> void
49+
50+
def authenticate: (HTTPRequest req, HTTPResponse res) -> void
51+
52+
def challenge: (HTTPRequest req, HTTPResponse res, ?bool stale) -> bot
53+
54+
private
55+
56+
MustParams: Array[String]
57+
58+
MustParamsAuth: Array[String]
59+
60+
def _authenticate: (HTTPRequest req, HTTPResponse res) -> (:nonce_is_stale | bool)
61+
62+
def split_param_value: (String string) -> Hash[String, String]
63+
64+
def generate_next_nonce: (HTTPRequest req) -> String
65+
66+
def check_nonce: (HTTPRequest req, Hash[String, String] auth_req) -> bool
67+
68+
def generate_opaque: (HTTPRequest req) -> String
69+
70+
def check_opaque: (OpaqueInfo opaque_struct, untyped req, Hash[String, String] auth_req) -> bool
71+
72+
def check_uri: (HTTPRequest req, Hash[String, String] auth_req) -> bool
73+
74+
def hexdigest: (*_ToS? args) -> String
75+
end
76+
77+
class ProxyDigestAuth < DigestAuth
78+
include ProxyAuthenticator
79+
80+
private
81+
82+
def check_uri: (HTTPRequest req, Hash[String, String] auth_req) -> true
83+
end
84+
end
85+
end

0 commit comments

Comments
 (0)