cgi 0.3.3-java
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of cgi might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +97 -0
- data/ext/java/org/jruby/ext/cgi/escape/lib/cgi/escape.rb +5 -0
- data/lib/cgi/cookie.rb +181 -0
- data/lib/cgi/core.rb +889 -0
- data/lib/cgi/escape.jar +0 -0
- data/lib/cgi/html.rb +1035 -0
- data/lib/cgi/session/pstore.rb +88 -0
- data/lib/cgi/session.rb +562 -0
- data/lib/cgi/util.rb +252 -0
- data/lib/cgi.rb +297 -0
- metadata +58 -0
data/lib/cgi/util.rb
ADDED
@@ -0,0 +1,252 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
class CGI
|
3
|
+
module Util; end
|
4
|
+
include Util
|
5
|
+
extend Util
|
6
|
+
end
|
7
|
+
module CGI::Util
|
8
|
+
@@accept_charset = Encoding::UTF_8 unless defined?(@@accept_charset)
|
9
|
+
|
10
|
+
# URL-encode a string into application/x-www-form-urlencoded.
|
11
|
+
# Space characters (+" "+) are encoded with plus signs (+"+"+)
|
12
|
+
# url_encoded_string = CGI.escape("'Stop!' said Fred")
|
13
|
+
# # => "%27Stop%21%27+said+Fred"
|
14
|
+
def escape(string)
|
15
|
+
encoding = string.encoding
|
16
|
+
buffer = string.b
|
17
|
+
buffer.gsub!(/([^ a-zA-Z0-9_.\-~]+)/) do |m|
|
18
|
+
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
|
19
|
+
end
|
20
|
+
buffer.tr!(' ', '+')
|
21
|
+
buffer.force_encoding(encoding)
|
22
|
+
end
|
23
|
+
|
24
|
+
# URL-decode an application/x-www-form-urlencoded string with encoding(optional).
|
25
|
+
# string = CGI.unescape("%27Stop%21%27+said+Fred")
|
26
|
+
# # => "'Stop!' said Fred"
|
27
|
+
def unescape(string, encoding = @@accept_charset)
|
28
|
+
str = string.tr('+', ' ')
|
29
|
+
str = str.b
|
30
|
+
str.gsub!(/((?:%[0-9a-fA-F]{2})+)/) do |m|
|
31
|
+
[m.delete('%')].pack('H*')
|
32
|
+
end
|
33
|
+
str.force_encoding(encoding)
|
34
|
+
str.valid_encoding? ? str : str.force_encoding(string.encoding)
|
35
|
+
end
|
36
|
+
|
37
|
+
# URL-encode a string following RFC 3986
|
38
|
+
# Space characters (+" "+) are encoded with (+"%20"+)
|
39
|
+
# url_encoded_string = CGI.escape("'Stop!' said Fred")
|
40
|
+
# # => "%27Stop%21%27%20said%20Fred"
|
41
|
+
def escapeURIComponent(string)
|
42
|
+
encoding = string.encoding
|
43
|
+
buffer = string.b
|
44
|
+
buffer.gsub!(/([^a-zA-Z0-9_.\-~]+)/) do |m|
|
45
|
+
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
|
46
|
+
end
|
47
|
+
buffer.force_encoding(encoding)
|
48
|
+
end
|
49
|
+
|
50
|
+
# URL-decode a string following RFC 3986 with encoding(optional).
|
51
|
+
# string = CGI.unescape("%27Stop%21%27+said%20Fred")
|
52
|
+
# # => "'Stop!'+said Fred"
|
53
|
+
def unescapeURIComponent(string, encoding = @@accept_charset)
|
54
|
+
str = string.b
|
55
|
+
str.gsub!(/((?:%[0-9a-fA-F]{2})+)/) do |m|
|
56
|
+
[m.delete('%')].pack('H*')
|
57
|
+
end
|
58
|
+
str.force_encoding(encoding)
|
59
|
+
str.valid_encoding? ? str : str.force_encoding(string.encoding)
|
60
|
+
end
|
61
|
+
|
62
|
+
# The set of special characters and their escaped values
|
63
|
+
TABLE_FOR_ESCAPE_HTML__ = {
|
64
|
+
"'" => ''',
|
65
|
+
'&' => '&',
|
66
|
+
'"' => '"',
|
67
|
+
'<' => '<',
|
68
|
+
'>' => '>',
|
69
|
+
}
|
70
|
+
|
71
|
+
# Escape special characters in HTML, namely '&\"<>
|
72
|
+
# CGI.escapeHTML('Usage: foo "bar" <baz>')
|
73
|
+
# # => "Usage: foo "bar" <baz>"
|
74
|
+
def escapeHTML(string)
|
75
|
+
enc = string.encoding
|
76
|
+
unless enc.ascii_compatible?
|
77
|
+
if enc.dummy?
|
78
|
+
origenc = enc
|
79
|
+
enc = Encoding::Converter.asciicompat_encoding(enc)
|
80
|
+
string = enc ? string.encode(enc) : string.b
|
81
|
+
end
|
82
|
+
table = Hash[TABLE_FOR_ESCAPE_HTML__.map {|pair|pair.map {|s|s.encode(enc)}}]
|
83
|
+
string = string.gsub(/#{"['&\"<>]".encode(enc)}/, table)
|
84
|
+
string.encode!(origenc) if origenc
|
85
|
+
string
|
86
|
+
else
|
87
|
+
string = string.b
|
88
|
+
string.gsub!(/['&\"<>]/, TABLE_FOR_ESCAPE_HTML__)
|
89
|
+
string.force_encoding(enc)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
begin
|
94
|
+
require 'cgi/escape'
|
95
|
+
rescue LoadError
|
96
|
+
end
|
97
|
+
|
98
|
+
# Unescape a string that has been HTML-escaped
|
99
|
+
# CGI.unescapeHTML("Usage: foo "bar" <baz>")
|
100
|
+
# # => "Usage: foo \"bar\" <baz>"
|
101
|
+
def unescapeHTML(string)
|
102
|
+
enc = string.encoding
|
103
|
+
unless enc.ascii_compatible?
|
104
|
+
if enc.dummy?
|
105
|
+
origenc = enc
|
106
|
+
enc = Encoding::Converter.asciicompat_encoding(enc)
|
107
|
+
string = enc ? string.encode(enc) : string.b
|
108
|
+
end
|
109
|
+
string = string.gsub(Regexp.new('&(apos|amp|quot|gt|lt|#[0-9]+|#x[0-9A-Fa-f]+);'.encode(enc))) do
|
110
|
+
case $1.encode(Encoding::US_ASCII)
|
111
|
+
when 'apos' then "'".encode(enc)
|
112
|
+
when 'amp' then '&'.encode(enc)
|
113
|
+
when 'quot' then '"'.encode(enc)
|
114
|
+
when 'gt' then '>'.encode(enc)
|
115
|
+
when 'lt' then '<'.encode(enc)
|
116
|
+
when /\A#0*(\d+)\z/ then $1.to_i.chr(enc)
|
117
|
+
when /\A#x([0-9a-f]+)\z/i then $1.hex.chr(enc)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
string.encode!(origenc) if origenc
|
121
|
+
return string
|
122
|
+
end
|
123
|
+
return string unless string.include? '&'
|
124
|
+
charlimit = case enc
|
125
|
+
when Encoding::UTF_8; 0x10ffff
|
126
|
+
when Encoding::ISO_8859_1; 256
|
127
|
+
else 128
|
128
|
+
end
|
129
|
+
string = string.b
|
130
|
+
string.gsub!(/&(apos|amp|quot|gt|lt|\#[0-9]+|\#[xX][0-9A-Fa-f]+);/) do
|
131
|
+
match = $1.dup
|
132
|
+
case match
|
133
|
+
when 'apos' then "'"
|
134
|
+
when 'amp' then '&'
|
135
|
+
when 'quot' then '"'
|
136
|
+
when 'gt' then '>'
|
137
|
+
when 'lt' then '<'
|
138
|
+
when /\A#0*(\d+)\z/
|
139
|
+
n = $1.to_i
|
140
|
+
if n < charlimit
|
141
|
+
n.chr(enc)
|
142
|
+
else
|
143
|
+
"&##{$1};"
|
144
|
+
end
|
145
|
+
when /\A#x([0-9a-f]+)\z/i
|
146
|
+
n = $1.hex
|
147
|
+
if n < charlimit
|
148
|
+
n.chr(enc)
|
149
|
+
else
|
150
|
+
"&#x#{$1};"
|
151
|
+
end
|
152
|
+
else
|
153
|
+
"&#{match};"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
string.force_encoding enc
|
157
|
+
end
|
158
|
+
|
159
|
+
# Synonym for CGI.escapeHTML(str)
|
160
|
+
alias escape_html escapeHTML
|
161
|
+
|
162
|
+
# Synonym for CGI.unescapeHTML(str)
|
163
|
+
alias unescape_html unescapeHTML
|
164
|
+
|
165
|
+
# Escape only the tags of certain HTML elements in +string+.
|
166
|
+
#
|
167
|
+
# Takes an element or elements or array of elements. Each element
|
168
|
+
# is specified by the name of the element, without angle brackets.
|
169
|
+
# This matches both the start and the end tag of that element.
|
170
|
+
# The attribute list of the open tag will also be escaped (for
|
171
|
+
# instance, the double-quotes surrounding attribute values).
|
172
|
+
#
|
173
|
+
# print CGI.escapeElement('<BR><A HREF="url"></A>', "A", "IMG")
|
174
|
+
# # "<BR><A HREF="url"></A>"
|
175
|
+
#
|
176
|
+
# print CGI.escapeElement('<BR><A HREF="url"></A>', ["A", "IMG"])
|
177
|
+
# # "<BR><A HREF="url"></A>"
|
178
|
+
def escapeElement(string, *elements)
|
179
|
+
elements = elements[0] if elements[0].kind_of?(Array)
|
180
|
+
unless elements.empty?
|
181
|
+
string.gsub(/<\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?>/i) do
|
182
|
+
CGI.escapeHTML($&)
|
183
|
+
end
|
184
|
+
else
|
185
|
+
string
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
# Undo escaping such as that done by CGI.escapeElement()
|
190
|
+
#
|
191
|
+
# print CGI.unescapeElement(
|
192
|
+
# CGI.escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
|
193
|
+
# # "<BR><A HREF="url"></A>"
|
194
|
+
#
|
195
|
+
# print CGI.unescapeElement(
|
196
|
+
# CGI.escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
|
197
|
+
# # "<BR><A HREF="url"></A>"
|
198
|
+
def unescapeElement(string, *elements)
|
199
|
+
elements = elements[0] if elements[0].kind_of?(Array)
|
200
|
+
unless elements.empty?
|
201
|
+
string.gsub(/<\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?>/i) do
|
202
|
+
unescapeHTML($&)
|
203
|
+
end
|
204
|
+
else
|
205
|
+
string
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
# Synonym for CGI.escapeElement(str)
|
210
|
+
alias escape_element escapeElement
|
211
|
+
|
212
|
+
# Synonym for CGI.unescapeElement(str)
|
213
|
+
alias unescape_element unescapeElement
|
214
|
+
|
215
|
+
# Format a +Time+ object as a String using the format specified by RFC 1123.
|
216
|
+
#
|
217
|
+
# CGI.rfc1123_date(Time.now)
|
218
|
+
# # Sat, 01 Jan 2000 00:00:00 GMT
|
219
|
+
def rfc1123_date(time)
|
220
|
+
time.getgm.strftime("%a, %d %b %Y %T GMT")
|
221
|
+
end
|
222
|
+
|
223
|
+
# Prettify (indent) an HTML string.
|
224
|
+
#
|
225
|
+
# +string+ is the HTML string to indent. +shift+ is the indentation
|
226
|
+
# unit to use; it defaults to two spaces.
|
227
|
+
#
|
228
|
+
# print CGI.pretty("<HTML><BODY></BODY></HTML>")
|
229
|
+
# # <HTML>
|
230
|
+
# # <BODY>
|
231
|
+
# # </BODY>
|
232
|
+
# # </HTML>
|
233
|
+
#
|
234
|
+
# print CGI.pretty("<HTML><BODY></BODY></HTML>", "\t")
|
235
|
+
# # <HTML>
|
236
|
+
# # <BODY>
|
237
|
+
# # </BODY>
|
238
|
+
# # </HTML>
|
239
|
+
#
|
240
|
+
def pretty(string, shift = " ")
|
241
|
+
lines = string.gsub(/(?!\A)<.*?>/m, "\n\\0").gsub(/<.*?>(?!\n)/m, "\\0\n")
|
242
|
+
end_pos = 0
|
243
|
+
while end_pos = lines.index(/^<\/(\w+)/, end_pos)
|
244
|
+
element = $1.dup
|
245
|
+
start_pos = lines.rindex(/^\s*<#{element}/i, end_pos)
|
246
|
+
lines[start_pos ... end_pos] = "__" + lines[start_pos ... end_pos].gsub(/\n(?!\z)/, "\n" + shift) + "__"
|
247
|
+
end
|
248
|
+
lines.gsub(/^((?:#{Regexp::quote(shift)})*)__(?=<\/?\w)/, '\1')
|
249
|
+
end
|
250
|
+
|
251
|
+
alias h escapeHTML
|
252
|
+
end
|
data/lib/cgi.rb
ADDED
@@ -0,0 +1,297 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# cgi.rb - cgi support library
|
4
|
+
#
|
5
|
+
# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
6
|
+
#
|
7
|
+
# Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
8
|
+
#
|
9
|
+
# Author: Wakou Aoyama <wakou@ruby-lang.org>
|
10
|
+
#
|
11
|
+
# Documentation: Wakou Aoyama (RDoc'd and embellished by William Webber)
|
12
|
+
#
|
13
|
+
|
14
|
+
# == Overview
|
15
|
+
#
|
16
|
+
# The Common Gateway Interface (CGI) is a simple protocol for passing an HTTP
|
17
|
+
# request from a web server to a standalone program, and returning the output
|
18
|
+
# to the web browser. Basically, a CGI program is called with the parameters
|
19
|
+
# of the request passed in either in the environment (GET) or via $stdin
|
20
|
+
# (POST), and everything it prints to $stdout is returned to the client.
|
21
|
+
#
|
22
|
+
# This file holds the CGI class. This class provides functionality for
|
23
|
+
# retrieving HTTP request parameters, managing cookies, and generating HTML
|
24
|
+
# output.
|
25
|
+
#
|
26
|
+
# The file CGI::Session provides session management functionality; see that
|
27
|
+
# class for more details.
|
28
|
+
#
|
29
|
+
# See http://www.w3.org/CGI/ for more information on the CGI protocol.
|
30
|
+
#
|
31
|
+
# == Introduction
|
32
|
+
#
|
33
|
+
# CGI is a large class, providing several categories of methods, many of which
|
34
|
+
# are mixed in from other modules. Some of the documentation is in this class,
|
35
|
+
# some in the modules CGI::QueryExtension and CGI::HtmlExtension. See
|
36
|
+
# CGI::Cookie for specific information on handling cookies, and cgi/session.rb
|
37
|
+
# (CGI::Session) for information on sessions.
|
38
|
+
#
|
39
|
+
# For queries, CGI provides methods to get at environmental variables,
|
40
|
+
# parameters, cookies, and multipart request data. For responses, CGI provides
|
41
|
+
# methods for writing output and generating HTML.
|
42
|
+
#
|
43
|
+
# Read on for more details. Examples are provided at the bottom.
|
44
|
+
#
|
45
|
+
# == Queries
|
46
|
+
#
|
47
|
+
# The CGI class dynamically mixes in parameter and cookie-parsing
|
48
|
+
# functionality, environmental variable access, and support for
|
49
|
+
# parsing multipart requests (including uploaded files) from the
|
50
|
+
# CGI::QueryExtension module.
|
51
|
+
#
|
52
|
+
# === Environmental Variables
|
53
|
+
#
|
54
|
+
# The standard CGI environmental variables are available as read-only
|
55
|
+
# attributes of a CGI object. The following is a list of these variables:
|
56
|
+
#
|
57
|
+
#
|
58
|
+
# AUTH_TYPE HTTP_HOST REMOTE_IDENT
|
59
|
+
# CONTENT_LENGTH HTTP_NEGOTIATE REMOTE_USER
|
60
|
+
# CONTENT_TYPE HTTP_PRAGMA REQUEST_METHOD
|
61
|
+
# GATEWAY_INTERFACE HTTP_REFERER SCRIPT_NAME
|
62
|
+
# HTTP_ACCEPT HTTP_USER_AGENT SERVER_NAME
|
63
|
+
# HTTP_ACCEPT_CHARSET PATH_INFO SERVER_PORT
|
64
|
+
# HTTP_ACCEPT_ENCODING PATH_TRANSLATED SERVER_PROTOCOL
|
65
|
+
# HTTP_ACCEPT_LANGUAGE QUERY_STRING SERVER_SOFTWARE
|
66
|
+
# HTTP_CACHE_CONTROL REMOTE_ADDR
|
67
|
+
# HTTP_FROM REMOTE_HOST
|
68
|
+
#
|
69
|
+
#
|
70
|
+
# For each of these variables, there is a corresponding attribute with the
|
71
|
+
# same name, except all lower case and without a preceding HTTP_.
|
72
|
+
# +content_length+ and +server_port+ are integers; the rest are strings.
|
73
|
+
#
|
74
|
+
# === Parameters
|
75
|
+
#
|
76
|
+
# The method #params() returns a hash of all parameters in the request as
|
77
|
+
# name/value-list pairs, where the value-list is an Array of one or more
|
78
|
+
# values. The CGI object itself also behaves as a hash of parameter names
|
79
|
+
# to values, but only returns a single value (as a String) for each
|
80
|
+
# parameter name.
|
81
|
+
#
|
82
|
+
# For instance, suppose the request contains the parameter
|
83
|
+
# "favourite_colours" with the multiple values "blue" and "green". The
|
84
|
+
# following behavior would occur:
|
85
|
+
#
|
86
|
+
# cgi.params["favourite_colours"] # => ["blue", "green"]
|
87
|
+
# cgi["favourite_colours"] # => "blue"
|
88
|
+
#
|
89
|
+
# If a parameter does not exist, the former method will return an empty
|
90
|
+
# array, the latter an empty string. The simplest way to test for existence
|
91
|
+
# of a parameter is by the #has_key? method.
|
92
|
+
#
|
93
|
+
# === Cookies
|
94
|
+
#
|
95
|
+
# HTTP Cookies are automatically parsed from the request. They are available
|
96
|
+
# from the #cookies() accessor, which returns a hash from cookie name to
|
97
|
+
# CGI::Cookie object.
|
98
|
+
#
|
99
|
+
# === Multipart requests
|
100
|
+
#
|
101
|
+
# If a request's method is POST and its content type is multipart/form-data,
|
102
|
+
# then it may contain uploaded files. These are stored by the QueryExtension
|
103
|
+
# module in the parameters of the request. The parameter name is the name
|
104
|
+
# attribute of the file input field, as usual. However, the value is not
|
105
|
+
# a string, but an IO object, either an IOString for small files, or a
|
106
|
+
# Tempfile for larger ones. This object also has the additional singleton
|
107
|
+
# methods:
|
108
|
+
#
|
109
|
+
# #local_path():: the path of the uploaded file on the local filesystem
|
110
|
+
# #original_filename():: the name of the file on the client computer
|
111
|
+
# #content_type():: the content type of the file
|
112
|
+
#
|
113
|
+
# == Responses
|
114
|
+
#
|
115
|
+
# The CGI class provides methods for sending header and content output to
|
116
|
+
# the HTTP client, and mixes in methods for programmatic HTML generation
|
117
|
+
# from CGI::HtmlExtension and CGI::TagMaker modules. The precise version of HTML
|
118
|
+
# to use for HTML generation is specified at object creation time.
|
119
|
+
#
|
120
|
+
# === Writing output
|
121
|
+
#
|
122
|
+
# The simplest way to send output to the HTTP client is using the #out() method.
|
123
|
+
# This takes the HTTP headers as a hash parameter, and the body content
|
124
|
+
# via a block. The headers can be generated as a string using the #http_header()
|
125
|
+
# method. The output stream can be written directly to using the #print()
|
126
|
+
# method.
|
127
|
+
#
|
128
|
+
# === Generating HTML
|
129
|
+
#
|
130
|
+
# Each HTML element has a corresponding method for generating that
|
131
|
+
# element as a String. The name of this method is the same as that
|
132
|
+
# of the element, all lowercase. The attributes of the element are
|
133
|
+
# passed in as a hash, and the body as a no-argument block that evaluates
|
134
|
+
# to a String. The HTML generation module knows which elements are
|
135
|
+
# always empty, and silently drops any passed-in body. It also knows
|
136
|
+
# which elements require matching closing tags and which don't. However,
|
137
|
+
# it does not know what attributes are legal for which elements.
|
138
|
+
#
|
139
|
+
# There are also some additional HTML generation methods mixed in from
|
140
|
+
# the CGI::HtmlExtension module. These include individual methods for the
|
141
|
+
# different types of form inputs, and methods for elements that commonly
|
142
|
+
# take particular attributes where the attributes can be directly specified
|
143
|
+
# as arguments, rather than via a hash.
|
144
|
+
#
|
145
|
+
# === Utility HTML escape and other methods like a function.
|
146
|
+
#
|
147
|
+
# There are some utility tool defined in cgi/util.rb .
|
148
|
+
# And when include, you can use utility methods like a function.
|
149
|
+
#
|
150
|
+
# == Examples of use
|
151
|
+
#
|
152
|
+
# === Get form values
|
153
|
+
#
|
154
|
+
# require "cgi"
|
155
|
+
# cgi = CGI.new
|
156
|
+
# value = cgi['field_name'] # <== value string for 'field_name'
|
157
|
+
# # if not 'field_name' included, then return "".
|
158
|
+
# fields = cgi.keys # <== array of field names
|
159
|
+
#
|
160
|
+
# # returns true if form has 'field_name'
|
161
|
+
# cgi.has_key?('field_name')
|
162
|
+
# cgi.has_key?('field_name')
|
163
|
+
# cgi.include?('field_name')
|
164
|
+
#
|
165
|
+
# CAUTION! <code>cgi['field_name']</code> returned an Array with the old
|
166
|
+
# cgi.rb(included in Ruby 1.6)
|
167
|
+
#
|
168
|
+
# === Get form values as hash
|
169
|
+
#
|
170
|
+
# require "cgi"
|
171
|
+
# cgi = CGI.new
|
172
|
+
# params = cgi.params
|
173
|
+
#
|
174
|
+
# cgi.params is a hash.
|
175
|
+
#
|
176
|
+
# cgi.params['new_field_name'] = ["value"] # add new param
|
177
|
+
# cgi.params['field_name'] = ["new_value"] # change value
|
178
|
+
# cgi.params.delete('field_name') # delete param
|
179
|
+
# cgi.params.clear # delete all params
|
180
|
+
#
|
181
|
+
#
|
182
|
+
# === Save form values to file
|
183
|
+
#
|
184
|
+
# require "pstore"
|
185
|
+
# db = PStore.new("query.db")
|
186
|
+
# db.transaction do
|
187
|
+
# db["params"] = cgi.params
|
188
|
+
# end
|
189
|
+
#
|
190
|
+
#
|
191
|
+
# === Restore form values from file
|
192
|
+
#
|
193
|
+
# require "pstore"
|
194
|
+
# db = PStore.new("query.db")
|
195
|
+
# db.transaction do
|
196
|
+
# cgi.params = db["params"]
|
197
|
+
# end
|
198
|
+
#
|
199
|
+
#
|
200
|
+
# === Get multipart form values
|
201
|
+
#
|
202
|
+
# require "cgi"
|
203
|
+
# cgi = CGI.new
|
204
|
+
# value = cgi['field_name'] # <== value string for 'field_name'
|
205
|
+
# value.read # <== body of value
|
206
|
+
# value.local_path # <== path to local file of value
|
207
|
+
# value.original_filename # <== original filename of value
|
208
|
+
# value.content_type # <== content_type of value
|
209
|
+
#
|
210
|
+
# and value has StringIO or Tempfile class methods.
|
211
|
+
#
|
212
|
+
# === Get cookie values
|
213
|
+
#
|
214
|
+
# require "cgi"
|
215
|
+
# cgi = CGI.new
|
216
|
+
# values = cgi.cookies['name'] # <== array of 'name'
|
217
|
+
# # if not 'name' included, then return [].
|
218
|
+
# names = cgi.cookies.keys # <== array of cookie names
|
219
|
+
#
|
220
|
+
# and cgi.cookies is a hash.
|
221
|
+
#
|
222
|
+
# === Get cookie objects
|
223
|
+
#
|
224
|
+
# require "cgi"
|
225
|
+
# cgi = CGI.new
|
226
|
+
# for name, cookie in cgi.cookies
|
227
|
+
# cookie.expires = Time.now + 30
|
228
|
+
# end
|
229
|
+
# cgi.out("cookie" => cgi.cookies) {"string"}
|
230
|
+
#
|
231
|
+
# cgi.cookies # { "name1" => cookie1, "name2" => cookie2, ... }
|
232
|
+
#
|
233
|
+
# require "cgi"
|
234
|
+
# cgi = CGI.new
|
235
|
+
# cgi.cookies['name'].expires = Time.now + 30
|
236
|
+
# cgi.out("cookie" => cgi.cookies['name']) {"string"}
|
237
|
+
#
|
238
|
+
# === Print http header and html string to $DEFAULT_OUTPUT ($>)
|
239
|
+
#
|
240
|
+
# require "cgi"
|
241
|
+
# cgi = CGI.new("html4") # add HTML generation methods
|
242
|
+
# cgi.out do
|
243
|
+
# cgi.html do
|
244
|
+
# cgi.head do
|
245
|
+
# cgi.title { "TITLE" }
|
246
|
+
# end +
|
247
|
+
# cgi.body do
|
248
|
+
# cgi.form("ACTION" => "uri") do
|
249
|
+
# cgi.p do
|
250
|
+
# cgi.textarea("get_text") +
|
251
|
+
# cgi.br +
|
252
|
+
# cgi.submit
|
253
|
+
# end
|
254
|
+
# end +
|
255
|
+
# cgi.pre do
|
256
|
+
# CGI.escapeHTML(
|
257
|
+
# "params: #{cgi.params.inspect}\n" +
|
258
|
+
# "cookies: #{cgi.cookies.inspect}\n" +
|
259
|
+
# ENV.collect do |key, value|
|
260
|
+
# "#{key} --> #{value}\n"
|
261
|
+
# end.join("")
|
262
|
+
# )
|
263
|
+
# end
|
264
|
+
# end
|
265
|
+
# end
|
266
|
+
# end
|
267
|
+
#
|
268
|
+
# # add HTML generation methods
|
269
|
+
# CGI.new("html3") # html3.2
|
270
|
+
# CGI.new("html4") # html4.01 (Strict)
|
271
|
+
# CGI.new("html4Tr") # html4.01 Transitional
|
272
|
+
# CGI.new("html4Fr") # html4.01 Frameset
|
273
|
+
# CGI.new("html5") # html5
|
274
|
+
#
|
275
|
+
# === Some utility methods
|
276
|
+
#
|
277
|
+
# require 'cgi/util'
|
278
|
+
# CGI.escapeHTML('Usage: foo "bar" <baz>')
|
279
|
+
#
|
280
|
+
#
|
281
|
+
# === Some utility methods like a function
|
282
|
+
#
|
283
|
+
# require 'cgi/util'
|
284
|
+
# include CGI::Util
|
285
|
+
# escapeHTML('Usage: foo "bar" <baz>')
|
286
|
+
# h('Usage: foo "bar" <baz>') # alias
|
287
|
+
#
|
288
|
+
#
|
289
|
+
|
290
|
+
class CGI
|
291
|
+
VERSION = "0.3.3"
|
292
|
+
end
|
293
|
+
|
294
|
+
require 'cgi/core'
|
295
|
+
require 'cgi/cookie'
|
296
|
+
require 'cgi/util'
|
297
|
+
CGI.autoload(:HtmlExtension, 'cgi/html')
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cgi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.3
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- Yukihiro Matsumoto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-09-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Support for the Common Gateway Interface protocol.
|
14
|
+
email:
|
15
|
+
- matz@ruby-lang.org
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- LICENSE.txt
|
21
|
+
- README.md
|
22
|
+
- ext/java/org/jruby/ext/cgi/escape/lib/cgi/escape.rb
|
23
|
+
- lib/cgi.rb
|
24
|
+
- lib/cgi/cookie.rb
|
25
|
+
- lib/cgi/core.rb
|
26
|
+
- lib/cgi/escape.jar
|
27
|
+
- lib/cgi/html.rb
|
28
|
+
- lib/cgi/session.rb
|
29
|
+
- lib/cgi/session/pstore.rb
|
30
|
+
- lib/cgi/util.rb
|
31
|
+
homepage: https://github.com/ruby/cgi
|
32
|
+
licenses:
|
33
|
+
- Ruby
|
34
|
+
- BSD-2-Clause
|
35
|
+
metadata:
|
36
|
+
homepage_uri: https://github.com/ruby/cgi
|
37
|
+
source_code_uri: https://github.com/ruby/cgi
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
- ext/java/org/jruby/ext/cgi/escape/lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.5.0
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.2.29
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Support for the Common Gateway Interface protocol.
|
58
|
+
test_files: []
|