rbs 1.0.6 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +2 -2
- data/CHANGELOG.md +37 -0
- data/Rakefile +3 -2
- data/Steepfile +2 -0
- data/bin/rbs-prof +1 -1
- data/core/array.rbs +8 -4
- data/core/thread.rbs +14 -1
- data/lib/rbs.rb +3 -0
- data/lib/rbs/ancestor_graph.rb +90 -0
- data/lib/rbs/char_scanner.rb +20 -0
- data/lib/rbs/definition_builder.rb +38 -20
- data/lib/rbs/definition_builder/method_builder.rb +14 -0
- data/lib/rbs/environment.rb +42 -5
- data/lib/rbs/environment_walker.rb +4 -4
- data/lib/rbs/errors.rb +32 -17
- data/lib/rbs/parser.rb +437 -416
- data/lib/rbs/parser.y +29 -16
- data/lib/rbs/test/type_check.rb +7 -3
- data/lib/rbs/version.rb +1 -1
- data/sig/ancestor_graph.rbs +40 -0
- data/sig/char_scanner.rbs +9 -0
- data/sig/definition_builder.rbs +5 -1
- data/sig/environment.rbs +22 -2
- data/sig/environment_walker.rbs +39 -0
- data/sig/errors.rbs +42 -17
- data/sig/method_builder.rbs +2 -0
- data/sig/parser.rbs +11 -4
- data/sig/polyfill.rbs +0 -14
- data/stdlib/cgi/0/core.rbs +595 -0
- data/stdlib/rubygems/0/basic_specification.rbs +3 -0
- data/stdlib/rubygems/0/config_file.rbs +3 -0
- data/stdlib/rubygems/0/dependency_installer.rbs +5 -0
- data/stdlib/rubygems/0/installer.rbs +3 -0
- data/stdlib/rubygems/0/path_support.rbs +3 -0
- data/stdlib/rubygems/0/platform.rbs +3 -0
- data/stdlib/rubygems/0/request_set.rbs +7 -0
- data/stdlib/rubygems/0/requirement.rbs +3 -0
- data/stdlib/rubygems/0/rubygems.rbs +710 -0
- data/stdlib/rubygems/0/source_list.rbs +2 -0
- data/stdlib/rubygems/0/specification.rbs +3 -0
- data/stdlib/rubygems/0/stream_ui.rbs +3 -0
- data/stdlib/rubygems/0/uninstaller.rbs +3 -0
- data/stdlib/rubygems/0/version.rbs +228 -0
- data/stdlib/strscan/0/string_scanner.rbs +582 -0
- metadata +23 -2
data/sig/method_builder.rbs
CHANGED
@@ -66,6 +66,8 @@ module RBS
|
|
66
66
|
def build_method: (Methods, Methods::instance_type, member: AST::Members::MethodDefinition, accessibility: Methods::Definition::accessibility) -> void
|
67
67
|
|
68
68
|
def each_member_with_accessibility: (Array[AST::Members::t | AST::Declarations::t], ?accessibility: Definition::accessibility) { (AST::Members::t | AST::Declarations::t, Definition::accessibility) -> void } -> void
|
69
|
+
|
70
|
+
def update: (env: Environment, except: _Each[TypeName]) -> MethodBuilder
|
69
71
|
end
|
70
72
|
end
|
71
73
|
end
|
data/sig/parser.rbs
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module RBS
|
2
2
|
class Parser
|
3
|
-
class SyntaxError <
|
3
|
+
class SyntaxError < ParsingError
|
4
4
|
attr_reader token_str: String
|
5
5
|
attr_reader error_value: untyped
|
6
6
|
attr_reader value_stack: untyped?
|
@@ -8,7 +8,14 @@ module RBS
|
|
8
8
|
def initialize: (token_str: String, error_value: untyped, ?value_stack: untyped?) -> void
|
9
9
|
end
|
10
10
|
|
11
|
-
class
|
11
|
+
class LexerError < ParsingError
|
12
|
+
attr_reader input: String
|
13
|
+
attr_reader location: Location
|
14
|
+
|
15
|
+
def initialize: (input: String, location: Location) -> void
|
16
|
+
end
|
17
|
+
|
18
|
+
class SemanticsError < ParsingError
|
12
19
|
attr_reader subject: untyped
|
13
20
|
attr_reader location: Location
|
14
21
|
attr_reader original_message: String
|
@@ -17,9 +24,9 @@ module RBS
|
|
17
24
|
end
|
18
25
|
|
19
26
|
def self.parse_method_type: (String | Buffer, ?variables: Array[Symbol], ?eof_re: Regexp?) -> MethodType
|
20
|
-
|
27
|
+
|
21
28
|
def self.parse_type: (String | Buffer, ?variables: Array[Symbol], ?eof_re: Regexp?) -> Types::t
|
22
|
-
|
29
|
+
|
23
30
|
def self.parse_signature: (String | Buffer, ?eof_re: Regexp?) -> Array[AST::Declarations::t]
|
24
31
|
end
|
25
32
|
end
|
data/sig/polyfill.rbs
CHANGED
@@ -3,20 +3,6 @@ module Kernel
|
|
3
3
|
end
|
4
4
|
|
5
5
|
module Gem
|
6
|
-
class Version
|
7
|
-
def self.correct?: (String) -> bool
|
8
|
-
|
9
|
-
def self.create: (String?) -> instance?
|
10
|
-
|
11
|
-
include Comparable
|
12
|
-
|
13
|
-
def prerelease?: () -> bool
|
14
|
-
|
15
|
-
def release: () -> self
|
16
|
-
|
17
|
-
def version: () -> String
|
18
|
-
end
|
19
|
-
|
20
6
|
class Specification
|
21
7
|
attr_reader version (): Version
|
22
8
|
|
@@ -0,0 +1,595 @@
|
|
1
|
+
# ## Overview
|
2
|
+
#
|
3
|
+
# The Common Gateway Interface (CGI) is a simple protocol for passing an HTTP
|
4
|
+
# request from a web server to a standalone program, and returning the output to
|
5
|
+
# the web browser. Basically, a CGI program is called with the parameters of
|
6
|
+
# the request passed in either in the environment (GET) or via $stdin (POST),
|
7
|
+
# and everything it prints to $stdout is returned to the client.
|
8
|
+
#
|
9
|
+
# This file holds the CGI class. This class provides functionality for
|
10
|
+
# retrieving HTTP request parameters, managing cookies, and generating HTML
|
11
|
+
# output.
|
12
|
+
#
|
13
|
+
# The file CGI::Session provides session management functionality; see that
|
14
|
+
# class for more details.
|
15
|
+
#
|
16
|
+
# See http://www.w3.org/CGI/ for more information on the CGI protocol.
|
17
|
+
#
|
18
|
+
# ## Introduction
|
19
|
+
#
|
20
|
+
# CGI is a large class, providing several categories of methods, many of which
|
21
|
+
# are mixed in from other modules. Some of the documentation is in this class,
|
22
|
+
# some in the modules CGI::QueryExtension and CGI::HtmlExtension. See
|
23
|
+
# CGI::Cookie for specific information on handling cookies, and cgi/session.rb
|
24
|
+
# (CGI::Session) for information on sessions.
|
25
|
+
#
|
26
|
+
# For queries, CGI provides methods to get at environmental variables,
|
27
|
+
# parameters, cookies, and multipart request data. For responses, CGI provides
|
28
|
+
# methods for writing output and generating HTML.
|
29
|
+
#
|
30
|
+
# Read on for more details. Examples are provided at the bottom.
|
31
|
+
#
|
32
|
+
# ## Queries
|
33
|
+
#
|
34
|
+
# The CGI class dynamically mixes in parameter and cookie-parsing functionality,
|
35
|
+
# environmental variable access, and support for parsing multipart requests
|
36
|
+
# (including uploaded files) from the CGI::QueryExtension module.
|
37
|
+
#
|
38
|
+
# ### Environmental Variables
|
39
|
+
#
|
40
|
+
# The standard CGI environmental variables are available as read-only attributes
|
41
|
+
# of a CGI object. The following is a list of these variables:
|
42
|
+
#
|
43
|
+
# AUTH_TYPE HTTP_HOST REMOTE_IDENT
|
44
|
+
# CONTENT_LENGTH HTTP_NEGOTIATE REMOTE_USER
|
45
|
+
# CONTENT_TYPE HTTP_PRAGMA REQUEST_METHOD
|
46
|
+
# GATEWAY_INTERFACE HTTP_REFERER SCRIPT_NAME
|
47
|
+
# HTTP_ACCEPT HTTP_USER_AGENT SERVER_NAME
|
48
|
+
# HTTP_ACCEPT_CHARSET PATH_INFO SERVER_PORT
|
49
|
+
# HTTP_ACCEPT_ENCODING PATH_TRANSLATED SERVER_PROTOCOL
|
50
|
+
# HTTP_ACCEPT_LANGUAGE QUERY_STRING SERVER_SOFTWARE
|
51
|
+
# HTTP_CACHE_CONTROL REMOTE_ADDR
|
52
|
+
# HTTP_FROM REMOTE_HOST
|
53
|
+
#
|
54
|
+
# For each of these variables, there is a corresponding attribute with the same
|
55
|
+
# name, except all lower case and without a preceding HTTP_. `content_length`
|
56
|
+
# and `server_port` are integers; the rest are strings.
|
57
|
+
#
|
58
|
+
# ### Parameters
|
59
|
+
#
|
60
|
+
# The method #params() returns a hash of all parameters in the request as
|
61
|
+
# name/value-list pairs, where the value-list is an Array of one or more values.
|
62
|
+
# The CGI object itself also behaves as a hash of parameter names to values,
|
63
|
+
# but only returns a single value (as a String) for each parameter name.
|
64
|
+
#
|
65
|
+
# For instance, suppose the request contains the parameter "favourite_colours"
|
66
|
+
# with the multiple values "blue" and "green". The following behavior would
|
67
|
+
# occur:
|
68
|
+
#
|
69
|
+
# cgi.params["favourite_colours"] # => ["blue", "green"]
|
70
|
+
# cgi["favourite_colours"] # => "blue"
|
71
|
+
#
|
72
|
+
# If a parameter does not exist, the former method will return an empty array,
|
73
|
+
# the latter an empty string. The simplest way to test for existence of a
|
74
|
+
# parameter is by the #has_key? method.
|
75
|
+
#
|
76
|
+
# ### Cookies
|
77
|
+
#
|
78
|
+
# HTTP Cookies are automatically parsed from the request. They are available
|
79
|
+
# from the #cookies() accessor, which returns a hash from cookie name to
|
80
|
+
# CGI::Cookie object.
|
81
|
+
#
|
82
|
+
# ### Multipart requests
|
83
|
+
#
|
84
|
+
# If a request's method is POST and its content type is multipart/form-data,
|
85
|
+
# then it may contain uploaded files. These are stored by the QueryExtension
|
86
|
+
# module in the parameters of the request. The parameter name is the name
|
87
|
+
# attribute of the file input field, as usual. However, the value is not a
|
88
|
+
# string, but an IO object, either an IOString for small files, or a Tempfile
|
89
|
+
# for larger ones. This object also has the additional singleton methods:
|
90
|
+
#
|
91
|
+
# #local_path()
|
92
|
+
# : the path of the uploaded file on the local filesystem
|
93
|
+
# #original_filename()
|
94
|
+
# : the name of the file on the client computer
|
95
|
+
# #content_type()
|
96
|
+
# : the content type of the file
|
97
|
+
#
|
98
|
+
#
|
99
|
+
# ## Responses
|
100
|
+
#
|
101
|
+
# The CGI class provides methods for sending header and content output to the
|
102
|
+
# HTTP client, and mixes in methods for programmatic HTML generation from
|
103
|
+
# CGI::HtmlExtension and CGI::TagMaker modules. The precise version of HTML to
|
104
|
+
# use for HTML generation is specified at object creation time.
|
105
|
+
#
|
106
|
+
# ### Writing output
|
107
|
+
#
|
108
|
+
# The simplest way to send output to the HTTP client is using the #out() method.
|
109
|
+
# This takes the HTTP headers as a hash parameter, and the body content via a
|
110
|
+
# block. The headers can be generated as a string using the #http_header()
|
111
|
+
# method. The output stream can be written directly to using the #print()
|
112
|
+
# method.
|
113
|
+
#
|
114
|
+
# ### Generating HTML
|
115
|
+
#
|
116
|
+
# Each HTML element has a corresponding method for generating that element as a
|
117
|
+
# String. The name of this method is the same as that of the element, all
|
118
|
+
# lowercase. The attributes of the element are passed in as a hash, and the
|
119
|
+
# body as a no-argument block that evaluates to a String. The HTML generation
|
120
|
+
# module knows which elements are always empty, and silently drops any passed-in
|
121
|
+
# body. It also knows which elements require matching closing tags and which
|
122
|
+
# don't. However, it does not know what attributes are legal for which
|
123
|
+
# elements.
|
124
|
+
#
|
125
|
+
# There are also some additional HTML generation methods mixed in from the
|
126
|
+
# CGI::HtmlExtension module. These include individual methods for the different
|
127
|
+
# types of form inputs, and methods for elements that commonly take particular
|
128
|
+
# attributes where the attributes can be directly specified as arguments, rather
|
129
|
+
# than via a hash.
|
130
|
+
#
|
131
|
+
# ### Utility HTML escape and other methods like a function.
|
132
|
+
#
|
133
|
+
# There are some utility tool defined in cgi/util.rb . And when include, you can
|
134
|
+
# use utility methods like a function.
|
135
|
+
#
|
136
|
+
# ## Examples of use
|
137
|
+
#
|
138
|
+
# ### Get form values
|
139
|
+
#
|
140
|
+
# require "cgi"
|
141
|
+
# cgi = CGI.new
|
142
|
+
# value = cgi['field_name'] # <== value string for 'field_name'
|
143
|
+
# # if not 'field_name' included, then return "".
|
144
|
+
# fields = cgi.keys # <== array of field names
|
145
|
+
#
|
146
|
+
# # returns true if form has 'field_name'
|
147
|
+
# cgi.has_key?('field_name')
|
148
|
+
# cgi.has_key?('field_name')
|
149
|
+
# cgi.include?('field_name')
|
150
|
+
#
|
151
|
+
# CAUTION! [cgi]('field_name') returned an Array with the old cgi.rb(included in
|
152
|
+
# Ruby 1.6)
|
153
|
+
#
|
154
|
+
# ### Get form values as hash
|
155
|
+
#
|
156
|
+
# require "cgi"
|
157
|
+
# cgi = CGI.new
|
158
|
+
# params = cgi.params
|
159
|
+
#
|
160
|
+
# cgi.params is a hash.
|
161
|
+
#
|
162
|
+
# cgi.params['new_field_name'] = ["value"] # add new param
|
163
|
+
# cgi.params['field_name'] = ["new_value"] # change value
|
164
|
+
# cgi.params.delete('field_name') # delete param
|
165
|
+
# cgi.params.clear # delete all params
|
166
|
+
#
|
167
|
+
# ### Save form values to file
|
168
|
+
#
|
169
|
+
# require "pstore"
|
170
|
+
# db = PStore.new("query.db")
|
171
|
+
# db.transaction do
|
172
|
+
# db["params"] = cgi.params
|
173
|
+
# end
|
174
|
+
#
|
175
|
+
# ### Restore form values from file
|
176
|
+
#
|
177
|
+
# require "pstore"
|
178
|
+
# db = PStore.new("query.db")
|
179
|
+
# db.transaction do
|
180
|
+
# cgi.params = db["params"]
|
181
|
+
# end
|
182
|
+
#
|
183
|
+
# ### Get multipart form values
|
184
|
+
#
|
185
|
+
# require "cgi"
|
186
|
+
# cgi = CGI.new
|
187
|
+
# value = cgi['field_name'] # <== value string for 'field_name'
|
188
|
+
# value.read # <== body of value
|
189
|
+
# value.local_path # <== path to local file of value
|
190
|
+
# value.original_filename # <== original filename of value
|
191
|
+
# value.content_type # <== content_type of value
|
192
|
+
#
|
193
|
+
# and value has StringIO or Tempfile class methods.
|
194
|
+
#
|
195
|
+
# ### Get cookie values
|
196
|
+
#
|
197
|
+
# require "cgi"
|
198
|
+
# cgi = CGI.new
|
199
|
+
# values = cgi.cookies['name'] # <== array of 'name'
|
200
|
+
# # if not 'name' included, then return [].
|
201
|
+
# names = cgi.cookies.keys # <== array of cookie names
|
202
|
+
#
|
203
|
+
# and cgi.cookies is a hash.
|
204
|
+
#
|
205
|
+
# ### Get cookie objects
|
206
|
+
#
|
207
|
+
# require "cgi"
|
208
|
+
# cgi = CGI.new
|
209
|
+
# for name, cookie in cgi.cookies
|
210
|
+
# cookie.expires = Time.now + 30
|
211
|
+
# end
|
212
|
+
# cgi.out("cookie" => cgi.cookies) {"string"}
|
213
|
+
#
|
214
|
+
# cgi.cookies # { "name1" => cookie1, "name2" => cookie2, ... }
|
215
|
+
#
|
216
|
+
# require "cgi"
|
217
|
+
# cgi = CGI.new
|
218
|
+
# cgi.cookies['name'].expires = Time.now + 30
|
219
|
+
# cgi.out("cookie" => cgi.cookies['name']) {"string"}
|
220
|
+
#
|
221
|
+
# ### Print http header and html string to $DEFAULT_OUTPUT ($>)
|
222
|
+
#
|
223
|
+
# require "cgi"
|
224
|
+
# cgi = CGI.new("html4") # add HTML generation methods
|
225
|
+
# cgi.out do
|
226
|
+
# cgi.html do
|
227
|
+
# cgi.head do
|
228
|
+
# cgi.title { "TITLE" }
|
229
|
+
# end +
|
230
|
+
# cgi.body do
|
231
|
+
# cgi.form("ACTION" => "uri") do
|
232
|
+
# cgi.p do
|
233
|
+
# cgi.textarea("get_text") +
|
234
|
+
# cgi.br +
|
235
|
+
# cgi.submit
|
236
|
+
# end
|
237
|
+
# end +
|
238
|
+
# cgi.pre do
|
239
|
+
# CGI.escapeHTML(
|
240
|
+
# "params: #{cgi.params.inspect}\n" +
|
241
|
+
# "cookies: #{cgi.cookies.inspect}\n" +
|
242
|
+
# ENV.collect do |key, value|
|
243
|
+
# "#{key} --> #{value}\n"
|
244
|
+
# end.join("")
|
245
|
+
# )
|
246
|
+
# end
|
247
|
+
# end
|
248
|
+
# end
|
249
|
+
# end
|
250
|
+
#
|
251
|
+
# # add HTML generation methods
|
252
|
+
# CGI.new("html3") # html3.2
|
253
|
+
# CGI.new("html4") # html4.01 (Strict)
|
254
|
+
# CGI.new("html4Tr") # html4.01 Transitional
|
255
|
+
# CGI.new("html4Fr") # html4.01 Frameset
|
256
|
+
# CGI.new("html5") # html5
|
257
|
+
#
|
258
|
+
# ### Some utility methods
|
259
|
+
#
|
260
|
+
# require 'cgi/util'
|
261
|
+
# CGI.escapeHTML('Usage: foo "bar" <baz>')
|
262
|
+
#
|
263
|
+
# ### Some utility methods like a function
|
264
|
+
#
|
265
|
+
# require 'cgi/util'
|
266
|
+
# include CGI::Util
|
267
|
+
# escapeHTML('Usage: foo "bar" <baz>')
|
268
|
+
# h('Usage: foo "bar" <baz>') # alias
|
269
|
+
class CGI
|
270
|
+
# Create a new CGI instance.
|
271
|
+
#
|
272
|
+
# `tag_maker`
|
273
|
+
# : This is the same as using the `options_hash` form with the value `{
|
274
|
+
# :tag_maker => tag_maker }` Note that it is recommended to use the
|
275
|
+
# `options_hash` form, since it also allows you specify the charset you will
|
276
|
+
# accept.
|
277
|
+
# `options_hash`
|
278
|
+
# : A Hash that recognizes three options:
|
279
|
+
#
|
280
|
+
# `:accept_charset`
|
281
|
+
# : specifies encoding of received query string. If omitted,
|
282
|
+
# `@@accept_charset` is used. If the encoding is not valid, a
|
283
|
+
# CGI::InvalidEncoding will be raised.
|
284
|
+
#
|
285
|
+
# Example. Suppose `@@accept_charset` is "UTF-8"
|
286
|
+
#
|
287
|
+
# when not specified:
|
288
|
+
#
|
289
|
+
# cgi=CGI.new # @accept_charset # => "UTF-8"
|
290
|
+
#
|
291
|
+
# when specified as "EUC-JP":
|
292
|
+
#
|
293
|
+
# cgi=CGI.new(:accept_charset => "EUC-JP") # => "EUC-JP"
|
294
|
+
#
|
295
|
+
# `:tag_maker`
|
296
|
+
# : String that specifies which version of the HTML generation methods to
|
297
|
+
# use. If not specified, no HTML generation methods will be loaded.
|
298
|
+
#
|
299
|
+
# The following values are supported:
|
300
|
+
#
|
301
|
+
# "html3"
|
302
|
+
# : HTML 3.x
|
303
|
+
# "html4"
|
304
|
+
# : HTML 4.0
|
305
|
+
# "html4Tr"
|
306
|
+
# : HTML 4.0 Transitional
|
307
|
+
# "html4Fr"
|
308
|
+
# : HTML 4.0 with Framesets
|
309
|
+
# "html5"
|
310
|
+
# : HTML 5
|
311
|
+
#
|
312
|
+
#
|
313
|
+
# `:max_multipart_length`
|
314
|
+
# : Specifies maximum length of multipart data. Can be an Integer scalar
|
315
|
+
# or a lambda, that will be evaluated when the request is parsed. This
|
316
|
+
# allows more complex logic to be set when determining whether to accept
|
317
|
+
# multipart data (e.g. consult a registered users upload allowance)
|
318
|
+
#
|
319
|
+
# Default is 128 * 1024 * 1024 bytes
|
320
|
+
#
|
321
|
+
# cgi=CGI.new(:max_multipart_length => 268435456) # simple scalar
|
322
|
+
#
|
323
|
+
# cgi=CGI.new(:max_multipart_length => -> {check_filesystem}) # lambda
|
324
|
+
#
|
325
|
+
#
|
326
|
+
# `block`
|
327
|
+
# : If provided, the block is called when an invalid encoding is encountered.
|
328
|
+
# For example:
|
329
|
+
#
|
330
|
+
# encoding_errors={}
|
331
|
+
# cgi=CGI.new(:accept_charset=>"EUC-JP") do |name,value|
|
332
|
+
# encoding_errors[name] = value
|
333
|
+
# end
|
334
|
+
#
|
335
|
+
#
|
336
|
+
# Finally, if the CGI object is not created in a standard CGI call environment
|
337
|
+
# (that is, it can't locate REQUEST_METHOD in its environment), then it will run
|
338
|
+
# in "offline" mode. In this mode, it reads its parameters from the command
|
339
|
+
# line or (failing that) from standard input. Otherwise, cookies and other
|
340
|
+
# parameters are parsed automatically from the standard CGI locations, which
|
341
|
+
# varies according to the REQUEST_METHOD.
|
342
|
+
#
|
343
|
+
def initialize: (?String tag_maker) ?{ (String name, String value) -> void } -> void
|
344
|
+
| (Hash[Symbol, untyped] options_hash) ?{ (String name, String value) -> void } -> void
|
345
|
+
|
346
|
+
attr_reader accept_charset: String
|
347
|
+
|
348
|
+
# Return the accept character set for all new CGI instances.
|
349
|
+
#
|
350
|
+
def self.accept_charset: () -> String
|
351
|
+
|
352
|
+
# Set the accept character set for all new CGI instances.
|
353
|
+
#
|
354
|
+
def self.accept_charset=: (String accept_charset) -> String
|
355
|
+
|
356
|
+
# Parse an HTTP query string into a hash of key=>value pairs.
|
357
|
+
#
|
358
|
+
# params = CGI.parse("query_string")
|
359
|
+
# # {"name1" => ["value1", "value2", ...],
|
360
|
+
# # "name2" => ["value1", "value2", ...], ... }
|
361
|
+
#
|
362
|
+
def self.parse: (String query) -> Hash[String, String | Array[String]]
|
363
|
+
|
364
|
+
public
|
365
|
+
|
366
|
+
# This method is an alias for #http_header, when HTML5 tag maker is inactive.
|
367
|
+
#
|
368
|
+
# NOTE: use #http_header to create HTTP header blocks, this alias is only
|
369
|
+
# provided for backwards compatibility.
|
370
|
+
#
|
371
|
+
# Using #header with the HTML5 tag maker will create a <header> element.
|
372
|
+
#
|
373
|
+
alias header http_header
|
374
|
+
|
375
|
+
# Create an HTTP header block as a string.
|
376
|
+
#
|
377
|
+
# Includes the empty line that ends the header block.
|
378
|
+
#
|
379
|
+
# `content_type_string`
|
380
|
+
# : If this form is used, this string is the `Content-Type`
|
381
|
+
# `headers_hash`
|
382
|
+
# : A Hash of header values. The following header keys are recognized:
|
383
|
+
#
|
384
|
+
# type
|
385
|
+
# : The Content-Type header. Defaults to "text/html"
|
386
|
+
# charset
|
387
|
+
# : The charset of the body, appended to the Content-Type header.
|
388
|
+
# nph
|
389
|
+
# : A boolean value. If true, prepend protocol string and status code,
|
390
|
+
# and date; and sets default values for "server" and "connection" if not
|
391
|
+
# explicitly set.
|
392
|
+
# status
|
393
|
+
# : The HTTP status code as a String, returned as the Status header. The
|
394
|
+
# values are:
|
395
|
+
#
|
396
|
+
# OK
|
397
|
+
# : 200 OK
|
398
|
+
# PARTIAL_CONTENT
|
399
|
+
# : 206 Partial Content
|
400
|
+
# MULTIPLE_CHOICES
|
401
|
+
# : 300 Multiple Choices
|
402
|
+
# MOVED
|
403
|
+
# : 301 Moved Permanently
|
404
|
+
# REDIRECT
|
405
|
+
# : 302 Found
|
406
|
+
# NOT_MODIFIED
|
407
|
+
# : 304 Not Modified
|
408
|
+
# BAD_REQUEST
|
409
|
+
# : 400 Bad Request
|
410
|
+
# AUTH_REQUIRED
|
411
|
+
# : 401 Authorization Required
|
412
|
+
# FORBIDDEN
|
413
|
+
# : 403 Forbidden
|
414
|
+
# NOT_FOUND
|
415
|
+
# : 404 Not Found
|
416
|
+
# METHOD_NOT_ALLOWED
|
417
|
+
# : 405 Method Not Allowed
|
418
|
+
# NOT_ACCEPTABLE
|
419
|
+
# : 406 Not Acceptable
|
420
|
+
# LENGTH_REQUIRED
|
421
|
+
# : 411 Length Required
|
422
|
+
# PRECONDITION_FAILED
|
423
|
+
# : 412 Precondition Failed
|
424
|
+
# SERVER_ERROR
|
425
|
+
# : 500 Internal Server Error
|
426
|
+
# NOT_IMPLEMENTED
|
427
|
+
# : 501 Method Not Implemented
|
428
|
+
# BAD_GATEWAY
|
429
|
+
# : 502 Bad Gateway
|
430
|
+
# VARIANT_ALSO_VARIES
|
431
|
+
# : 506 Variant Also Negotiates
|
432
|
+
#
|
433
|
+
#
|
434
|
+
# server
|
435
|
+
# : The server software, returned as the Server header.
|
436
|
+
# connection
|
437
|
+
# : The connection type, returned as the Connection header (for instance,
|
438
|
+
# "close".
|
439
|
+
# length
|
440
|
+
# : The length of the content that will be sent, returned as the
|
441
|
+
# Content-Length header.
|
442
|
+
# language
|
443
|
+
# : The language of the content, returned as the Content-Language header.
|
444
|
+
# expires
|
445
|
+
# : The time on which the current content expires, as a `Time` object,
|
446
|
+
# returned as the Expires header.
|
447
|
+
# cookie
|
448
|
+
# : A cookie or cookies, returned as one or more Set-Cookie headers. The
|
449
|
+
# value can be the literal string of the cookie; a CGI::Cookie object;
|
450
|
+
# an Array of literal cookie strings or Cookie objects; or a hash all of
|
451
|
+
# whose values are literal cookie strings or Cookie objects.
|
452
|
+
#
|
453
|
+
# These cookies are in addition to the cookies held in the
|
454
|
+
# @output_cookies field.
|
455
|
+
#
|
456
|
+
#
|
457
|
+
# Other headers can also be set; they are appended as key: value.
|
458
|
+
#
|
459
|
+
#
|
460
|
+
# Examples:
|
461
|
+
#
|
462
|
+
# http_header
|
463
|
+
# # Content-Type: text/html
|
464
|
+
#
|
465
|
+
# http_header("text/plain")
|
466
|
+
# # Content-Type: text/plain
|
467
|
+
#
|
468
|
+
# http_header("nph" => true,
|
469
|
+
# "status" => "OK", # == "200 OK"
|
470
|
+
# # "status" => "200 GOOD",
|
471
|
+
# "server" => ENV['SERVER_SOFTWARE'],
|
472
|
+
# "connection" => "close",
|
473
|
+
# "type" => "text/html",
|
474
|
+
# "charset" => "iso-2022-jp",
|
475
|
+
# # Content-Type: text/html; charset=iso-2022-jp
|
476
|
+
# "length" => 103,
|
477
|
+
# "language" => "ja",
|
478
|
+
# "expires" => Time.now + 30,
|
479
|
+
# "cookie" => [cookie1, cookie2],
|
480
|
+
# "my_header1" => "my_value",
|
481
|
+
# "my_header2" => "my_value")
|
482
|
+
#
|
483
|
+
# This method does not perform charset conversion.
|
484
|
+
#
|
485
|
+
def http_header: (?String options) -> String
|
486
|
+
| (?Hash[String | Symbol, untyped] header_hash) -> String
|
487
|
+
|
488
|
+
def nph?: () -> boolish
|
489
|
+
|
490
|
+
# Print an HTTP header and body to $DEFAULT_OUTPUT ($>)
|
491
|
+
#
|
492
|
+
# `content_type_string`
|
493
|
+
# : If a string is passed, it is assumed to be the content type.
|
494
|
+
# `headers_hash`
|
495
|
+
# : This is a Hash of headers, similar to that used by #http_header.
|
496
|
+
# `block`
|
497
|
+
# : A block is required and should evaluate to the body of the response.
|
498
|
+
#
|
499
|
+
#
|
500
|
+
# `Content-Length` is automatically calculated from the size of the String
|
501
|
+
# returned by the content block.
|
502
|
+
#
|
503
|
+
# If `ENV['REQUEST_METHOD'] == "HEAD"`, then only the header is output (the
|
504
|
+
# content block is still required, but it is ignored).
|
505
|
+
#
|
506
|
+
# If the charset is "iso-2022-jp" or "euc-jp" or "shift_jis" then the content is
|
507
|
+
# converted to this charset, and the language is set to "ja".
|
508
|
+
#
|
509
|
+
# Example:
|
510
|
+
#
|
511
|
+
# cgi = CGI.new
|
512
|
+
# cgi.out{ "string" }
|
513
|
+
# # Content-Type: text/html
|
514
|
+
# # Content-Length: 6
|
515
|
+
# #
|
516
|
+
# # string
|
517
|
+
#
|
518
|
+
# cgi.out("text/plain") { "string" }
|
519
|
+
# # Content-Type: text/plain
|
520
|
+
# # Content-Length: 6
|
521
|
+
# #
|
522
|
+
# # string
|
523
|
+
#
|
524
|
+
# cgi.out("nph" => true,
|
525
|
+
# "status" => "OK", # == "200 OK"
|
526
|
+
# "server" => ENV['SERVER_SOFTWARE'],
|
527
|
+
# "connection" => "close",
|
528
|
+
# "type" => "text/html",
|
529
|
+
# "charset" => "iso-2022-jp",
|
530
|
+
# # Content-Type: text/html; charset=iso-2022-jp
|
531
|
+
# "language" => "ja",
|
532
|
+
# "expires" => Time.now + (3600 * 24 * 30),
|
533
|
+
# "cookie" => [cookie1, cookie2],
|
534
|
+
# "my_header1" => "my_value",
|
535
|
+
# "my_header2" => "my_value") { "string" }
|
536
|
+
# # HTTP/1.1 200 OK
|
537
|
+
# # Date: Sun, 15 May 2011 17:35:54 GMT
|
538
|
+
# # Server: Apache 2.2.0
|
539
|
+
# # Connection: close
|
540
|
+
# # Content-Type: text/html; charset=iso-2022-jp
|
541
|
+
# # Content-Length: 6
|
542
|
+
# # Content-Language: ja
|
543
|
+
# # Expires: Tue, 14 Jun 2011 17:35:54 GMT
|
544
|
+
# # Set-Cookie: foo
|
545
|
+
# # Set-Cookie: bar
|
546
|
+
# # my_header1: my_value
|
547
|
+
# # my_header2: my_value
|
548
|
+
# #
|
549
|
+
# # string
|
550
|
+
#
|
551
|
+
def out: (?String content_type_string) { () -> String } -> void
|
552
|
+
| (Hash[String | Symbol, untyped] headers_hash) { () -> String } -> void
|
553
|
+
|
554
|
+
# Print an argument or list of arguments to the default output stream
|
555
|
+
#
|
556
|
+
# cgi = CGI.new
|
557
|
+
# cgi.print # default: cgi.print == $DEFAULT_OUTPUT.print
|
558
|
+
#
|
559
|
+
def print: (*String options) -> void
|
560
|
+
|
561
|
+
private
|
562
|
+
|
563
|
+
# Synonym for $stdin.
|
564
|
+
#
|
565
|
+
def stdinput: () -> ::IO
|
566
|
+
|
567
|
+
# Synonym for $stdout.
|
568
|
+
#
|
569
|
+
def stdoutput: () -> ::IO
|
570
|
+
end
|
571
|
+
|
572
|
+
# String for carriage return
|
573
|
+
CGI::CR: String
|
574
|
+
|
575
|
+
# Standard internet newline sequence
|
576
|
+
CGI::EOL: String
|
577
|
+
|
578
|
+
# HTTP status codes.
|
579
|
+
CGI::HTTP_STATUS: Hash[String, String]
|
580
|
+
|
581
|
+
# String for linefeed
|
582
|
+
CGI::LF: String
|
583
|
+
|
584
|
+
# Maximum number of request parameters when multipart
|
585
|
+
CGI::MAX_MULTIPART_COUNT: Integer
|
586
|
+
|
587
|
+
# Whether processing will be required in binary vs text
|
588
|
+
CGI::NEEDS_BINMODE: bool
|
589
|
+
|
590
|
+
# Path separators in different environments.
|
591
|
+
CGI::PATH_SEPARATOR: Hash[String, String]
|
592
|
+
|
593
|
+
CGI::REVISION: String
|
594
|
+
|
595
|
+
CGI::VERSION: String
|