From 052b113327626cb9a88a07fa73d2d08700c26a49 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Mon, 1 Dec 2025 17:13:55 +0000 Subject: [PATCH 01/11] [DOC] Doc for accept_charset and accept_charset= --- lib/cgi/core.rb | 67 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/lib/cgi/core.rb b/lib/cgi/core.rb index 6a74486..176648b 100644 --- a/lib/cgi/core.rb +++ b/lib/cgi/core.rb @@ -755,12 +755,75 @@ class InvalidEncoding < Exception; end # @@accept_charset="UTF-8" if false # needed for rdoc? - # Return the accept character set for all new CGI instances. + # :call-seq: + # CGI.accept_charset -> encoding + # + # Returns the default accept character set to be used for new \CGI instances; + # see CGI.accept_charset=. def self.accept_charset @@accept_charset end - # Set the accept character set for all new CGI instances. + # :call-seq: + # CGI.accept_charset = encoding + # + # Sets the default accept character set to be used for new \CGI instances; + # returns the argument. + # + # The argument may be an Encoding object or an Encoding name; + # see {Encodings}[https://docs.ruby-lang.org/en/master/language/encodings_rdoc.html]: + # + # # The initial value. + # CGI.accept_charset # => "UTF-8" + # CGI.new + # # => + # # + # + # # Set by Encoding name. + # CGI.accept_charset = 'US-ASCII' # => "US-ASCII" + # CGI.new + # # => + # # + # + # # Set by Encoding object. + # CGI.accept_charset = Encoding::ASCII_8BIT # => # + # CGI.new + # # => + # #, + # @accept_charset_error_block=nil, + # @cookies={}, + # @max_multipart_length=134217728, + # @multipart=false, + # @options={accept_charset: #, max_multipart_length: 134217728}, + # @output_cookies=nil, + # @output_hidden=nil, + # @params={}> + # + # The given encoding is not checked in this method, + # but if it is invalid, a call to CGI.new will fail: + # + # CGI.accept_charset = 'foo' + # CGI.new # Raises ArgumentError: unknown encoding name - foo + # def self.accept_charset=(accept_charset) @@accept_charset=accept_charset end From 6b66501fb1dfb080bccef2242148b1790df0e8bb Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Mon, 1 Dec 2025 23:27:46 +0000 Subject: [PATCH 02/11] [DOC] Doc for CGI#http_header --- lib/cgi/core.rb | 313 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 226 insertions(+), 87 deletions(-) diff --git a/lib/cgi/core.rb b/lib/cgi/core.rb index 176648b..f337b6d 100644 --- a/lib/cgi/core.rb +++ b/lib/cgi/core.rb @@ -72,91 +72,236 @@ def stdoutput private :env_table, :stdinput, :stdoutput - # Create an HTTP header block as a string. - # # :call-seq: - # http_header(content_type_string="text/html") - # http_header(headers_hash) + # http_header(content_type = 'text/html') -> string + # http_header(headers) -> string + # + # Creates and returns an HTTP header section as a multi-line string. + # + # The string always includes: + # + # - Header +Content-Type+ (with a default value if none given). + # - A trailing newline, which delimits the header block. + # + # In Brief + # + # headers = { + # 'charset' => 'iso-2022-jp', + # 'connection' => 'keep-alive', + # 'cookie' => 'foo=0', + # 'expires' => Time.now + (60 * 60 * 24 * 365), + # 'language' => 'en-US, en-CA', + # 'length' => 4096, + # 'nph' => true, + # 'server' => 'Apache/2.4.1 (Unix)', + # 'status' => 'OK', + # 'type' => 'text/xml', + # MyHeader: true + # } + # puts cgi.http_header(headers) + # HTTP/1.0 200 OK + # Date: Mon, 01 Dec 2025 22:08:22 GMT + # Server: Apache/2.4.1 (Unix) + # Connection: keep-alive + # Content-Type: text/xml; charset=iso-2022-jp + # Content-Length: 4096 + # Content-Language: en-US, en-CA + # Expires: Tue, 01 Dec 2026 22:05:30 GMT + # Set-Cookie: foo=0 + # MyHeader: true + # + # headers.delete('nph') + # puts cgi.http_header(headers) + # Status: 200 OK + # Server: Apache/2.4.1 (Unix) + # Connection: keep-alive + # Content-Type: text/xml; charset=iso-2022-jp + # Content-Length: 4096 + # Content-Language: en-US, en-CA + # Expires: Tue, 01 Dec 2026 22:05:30 GMT + # Set-Cookie: foo=0 + # MyHeader: true + # + # Arguments + # + # With no argument given, + # includes only header +Content-Type+ with its default value 'text/html': + # + # cgi.http_header + # # => "Content-Type: text/html\r\n\r\n" + # + # With string argument +content_type+ given, + # includes header +Content-Type+ with its default value 'text/html': + # + # cgi.http_header('text/xml') + # # => "Content-Type: text/xml\r\n\r\n" + # + # With hash argument +headers+ given, + # includes a header for hash entry, whose name is based on the entry's key, + # and whose value is the entry's value. + # + # Recognized Keys + # + # The following keys are recognized; + # each is a lowercase string: + # + # 'charset':: + # The character set of the body; appended to the +Content-Type+ header: + # + # cgi.http_header('charset' => 'iso-2022-jp') + # # => "Content-Type: text/html; charset=iso-2022-jp\r\n\r\n" + # + # 'connection':: + # Sets header +Connection+ to the given string: + # + # cgi.http_header('connection' => 'keep-alive') + # # => "Connection: keep-alive\r\nContent-Type: text/html\r\n\r\n" + # + # 'cookie':: + # Sets one or more +Set-Cookie+ headers to the given value, which may be: + # + # - String cookie. + # - CGI::Cookie object. + # - Array of string cookies and CGI::Cookie objects. + # - A hash whose values are string cookies and CGI::Cookie objects + # (the keys are not used). + # + # Examples: + # + # foo_string = 'foo=0' + # bar_string = 'bar=1' + # foo_cookie = CGI::Cookie.new('foo', '0') + # bar_cookie = CGI::Cookie.new('bar', '1') + # cgi.http_header('cookie' => foo_string) + # # => "Content-Type: text/html\r\nSet-Cookie: foo=0\r\n\r\n" + # cgi.http_header('cookie' => foo_cookie) + # # => "Content-Type: text/html\r\nSet-Cookie: foo=0; path=\r\n\r\n" + # cgi.http_header('cookie' => [foo_cookie, bar_string]) + # # => "Content-Type: text/html\r\nSet-Cookie: foo=0; path=\r\nSet-Cookie: bar=1\r\n\r\n" + # cgi.http_header('cookie' => {foo: foo_cookie, bar: bar_string}) + # # => "Content-Type: text/html\r\nSet-Cookie: foo=0; path=\r\nSet-Cookie: bar=1\r\n\r\n" + # + # These cookies are in addition to the cookies held + # in the @output_cookies variable. + # + # 'expires':: + # Sets header +Expires+ to the given time, + # which must be a {Time}[https://docs.ruby-lang.org/en/master/Time.html] object: + # + # cgi.http_header('expires' => Time.now + (60 * 60 * 24 * 365)) + # # => "Content-Type: text/html\r\nExpires: Tue, 01 Dec 2026 20:47:43 GMT\r\n\r\n" + # + # 'language':: + # Sets header +Content-Language+ to the given string: + # + # cgi.http_header('language' => 'en-US, en-CA') + # # => "Content-Type: text/html\r\nContent-Language: en-US, en-CA\r\n\r\n" + # + # 'length':: + # Sets header +Content-Length+ the given value, + # which may be an integer or a string: + # + # cgi.http_header('length' => 4096) + # # => "Content-Type: text/html\r\nContent-Length: 4096\r\n\r\n" + # cgi.http_header('length' => '4096') + # # => "Content-Type: text/html\r\nContent-Length: 4096\r\n\r\n" + # + # 'nph':: + # If +true+: + # + # - Adds protocol string and status code as first line, + # - Adds date as second line. + # - Adds headers +Server+ with no value, + # and +Connection+ with default value 'close'; + # either or both values may be overridden with explicit values. + # + # Examples: + # + # puts cgi.http_header('nph' => true) + # HTTP/1.0 200 OK + # Date: Mon, 01 Dec 2025 19:42:22 GMT + # Server: + # Connection: close + # Content-Type: text/html + # + # puts cgi.http_header('nph' => true, 'server' => 'Apache/2.4.1 (Unix)', 'connection' => 'keep-alive') + # HTTP/1.0 200 OK + # Date: Mon, 01 Dec 2025 20:00:41 GMT + # Server: Apache/2.4.1 (Unix) + # Connection: keep-alive + # Content-Type: text/html + # + # 'server':: + # Sets header +Server+ to the given string: + # + # cgi.http_header('server' => 'Apache/2.4.1 (Unix)') + # # => "Server: Apache/2.4.1 (Unix)\r\nContent-Type: text/html\r\n\r\n" + # + # 'status':: + # Sets header +Status+ to the given string: + # + # cgi.http_header('status' => '666 MyVeryOwnStatus') + # # => "Status: 666 MyVeryOwnStatus\r\nContent-Type: text/html\r\n\r\n" + # + # If the given string is a key in the hash constant +CGI::HTTP_STATUS+, + # the status becomes the value for that key: + # + # CGI::HTTP_STATUS + # # => + # {"OK" => "200 OK", + # "PARTIAL_CONTENT" => "206 Partial Content", + # "MULTIPLE_CHOICES" => "300 Multiple Choices", + # "MOVED" => "301 Moved Permanently", + # "REDIRECT" => "302 Found", + # "NOT_MODIFIED" => "304 Not Modified", + # "BAD_REQUEST" => "400 Bad Request", + # "AUTH_REQUIRED" => "401 Authorization Required", + # "FORBIDDEN" => "403 Forbidden", + # "NOT_FOUND" => "404 Not Found", + # "METHOD_NOT_ALLOWED" => "405 Method Not Allowed", + # "NOT_ACCEPTABLE" => "406 Not Acceptable", + # "LENGTH_REQUIRED" => "411 Length Required", + # "PRECONDITION_FAILED" => "412 Precondition Failed", + # "SERVER_ERROR" => "500 Internal Server Error", + # "NOT_IMPLEMENTED" => "501 Method Not Implemented", + # "BAD_GATEWAY" => "502 Bad Gateway", + # "VARIANT_ALSO_VARIES" => "506 Variant Also Negotiates"} + # + # cgi.http_header('status' => 'OK') + # # => "Status: 200 OK\r\nContent-Type: text/html\r\n\r\n" + # cgi.http_header('status' => 'NOT_FOUND') + # # => "Status: 404 Not Found\r\nContent-Type: text/html\r\n\r\n" + # + # 'type':: + # Sets +Content-Type+, overriding the default value 'text/html': + # + # cgi.http_header('type' => 'text/xml') + # # => "Content-Type: text/xml\r\n\r\n" + # + # Unrecognized Keys + # + # Headers may also be set for unrecognized keys; + # an unrecognized key becomes a header name with the given value: + # + # cgi.http_header('length' => 0) # Recognized key (lowercase string). + # # => "Content-Type: text/html\r\nContent-Length: 0\r\n\r\n" + # cgi.http_header('Length' => 0) # Unrecognized key (string key not lowercase). + # # => "Content-Type: text/html\r\nLength: 0\r\n\r\n" + # cgi.http_header(length: 0) # Unrecognized key (symbol key not string) + # # => "Content-Type: text/html\r\nlength: 0\r\n\r\n" # - # Includes the empty line that ends the header block. + # This method does not perform charset conversion. # - # +content_type_string+:: - # If this form is used, this string is the Content-Type - # +headers_hash+:: - # A Hash of header values. The following header keys are recognized: - # - # type:: The Content-Type header. Defaults to "text/html" - # charset:: The charset of the body, appended to the Content-Type header. - # nph:: A boolean value. If true, prepend protocol string and status - # code, and date; and sets default values for "server" and - # "connection" if not explicitly set. - # status:: - # The HTTP status code as a String, returned as the Status header. The - # values are: - # - # OK:: 200 OK - # PARTIAL_CONTENT:: 206 Partial Content - # MULTIPLE_CHOICES:: 300 Multiple Choices - # MOVED:: 301 Moved Permanently - # REDIRECT:: 302 Found - # NOT_MODIFIED:: 304 Not Modified - # BAD_REQUEST:: 400 Bad Request - # AUTH_REQUIRED:: 401 Authorization Required - # FORBIDDEN:: 403 Forbidden - # NOT_FOUND:: 404 Not Found - # METHOD_NOT_ALLOWED:: 405 Method Not Allowed - # NOT_ACCEPTABLE:: 406 Not Acceptable - # LENGTH_REQUIRED:: 411 Length Required - # PRECONDITION_FAILED:: 412 Precondition Failed - # SERVER_ERROR:: 500 Internal Server Error - # NOT_IMPLEMENTED:: 501 Method Not Implemented - # BAD_GATEWAY:: 502 Bad Gateway - # VARIANT_ALSO_VARIES:: 506 Variant Also Negotiates - # - # server:: The server software, returned as the Server header. - # connection:: The connection type, returned as the Connection header (for - # instance, "close". - # length:: The length of the content that will be sent, returned as the - # Content-Length header. - # language:: The language of the content, returned as the Content-Language - # header. - # expires:: The time on which the current content expires, as a +Time+ - # object, returned as the Expires header. - # cookie:: - # A cookie or cookies, returned as one or more Set-Cookie headers. The - # value can be the literal string of the cookie; a CGI::Cookie object; - # an Array of literal cookie strings or Cookie objects; or a hash all of - # whose values are literal cookie strings or Cookie objects. - # - # These cookies are in addition to the cookies held in the - # @output_cookies field. - # - # Other headers can also be set; they are appended as key: value. - # - # Examples: - # - # http_header - # # Content-Type: text/html + # It's best to use this method (CGI#http_header), not its aliased method +header+, + # which is provided only for backward compatibility. # - # http_header("text/plain") - # # Content-Type: text/plain + # Method CGI#http_header is preferred because when +tag_maker+ is 'html5', + # calling method +header+ generates an HTML +header+ element: # - # http_header("nph" => true, - # "status" => "OK", # == "200 OK" - # # "status" => "200 GOOD", - # "server" => ENV['SERVER_SOFTWARE'], - # "connection" => "close", - # "type" => "text/html", - # "charset" => "iso-2022-jp", - # # Content-Type: text/html; charset=iso-2022-jp - # "length" => 103, - # "language" => "ja", - # "expires" => Time.now + 30, - # "cookie" => [cookie1, cookie2], - # "my_header1" => "my_value", - # "my_header2" => "my_value") + # cgi = CGI.new(tag_maker: 'html5') + # cgi.http_header # => "Content-Type: text/html\r\n\r\n" # As expected. + # cgi.header # => "
" # Maybe a surprise. # - # This method does not perform charset conversion. def http_header(options='text/html') if options.is_a?(String) content_type = options @@ -178,15 +323,9 @@ def http_header(options='text/html') buf << EOL # empty line of separator return buf end - end # http_header() + end - # This method is an alias for #http_header, when HTML5 tag maker is inactive. - # - # NOTE: use #http_header to create HTTP header blocks, this alias is only - # provided for backwards compatibility. - # - # Using #header with the HTML5 tag maker will create a
element. - alias :header :http_header + alias :header :http_header # :nodoc: def _no_crlf_check(str) if str From 2a1a072f822145ff2b0d5afaf451fcc26776bc8c Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Tue, 2 Dec 2025 00:05:51 +0000 Subject: [PATCH 03/11] [DOC] More on CGI#http_header --- lib/cgi/core.rb | 121 ++++++++++++++++++++++++++++++------------------ 1 file changed, 76 insertions(+), 45 deletions(-) diff --git a/lib/cgi/core.rb b/lib/cgi/core.rb index f337b6d..64e8f56 100644 --- a/lib/cgi/core.rb +++ b/lib/cgi/core.rb @@ -81,7 +81,8 @@ def stdoutput # The string always includes: # # - Header +Content-Type+ (with a default value if none given). - # - A trailing newline, which delimits the header block. + # - A trailing newline, which delimits the header block; + # that last line is omitted from the examples below. # # In Brief # @@ -98,6 +99,7 @@ def stdoutput # 'type' => 'text/xml', # MyHeader: true # } + # # puts cgi.http_header(headers) # HTTP/1.0 200 OK # Date: Mon, 01 Dec 2025 22:08:22 GMT @@ -111,6 +113,7 @@ def stdoutput # MyHeader: true # # headers.delete('nph') + # # puts cgi.http_header(headers) # Status: 200 OK # Server: Apache/2.4.1 (Unix) @@ -127,20 +130,20 @@ def stdoutput # With no argument given, # includes only header +Content-Type+ with its default value 'text/html': # - # cgi.http_header - # # => "Content-Type: text/html\r\n\r\n" + # puts cgi.http_header + # Content-Type: text/html # # With string argument +content_type+ given, # includes header +Content-Type+ with its default value 'text/html': # - # cgi.http_header('text/xml') - # # => "Content-Type: text/xml\r\n\r\n" + # puts cgi.http_header('text/xml') + # Content-Type: text/xml # # With hash argument +headers+ given, # includes a header for hash entry, whose name is based on the entry's key, # and whose value is the entry's value. # - # Recognized Keys + # Recognized Keys # # The following keys are recognized; # each is a lowercase string: @@ -148,14 +151,15 @@ def stdoutput # 'charset':: # The character set of the body; appended to the +Content-Type+ header: # - # cgi.http_header('charset' => 'iso-2022-jp') - # # => "Content-Type: text/html; charset=iso-2022-jp\r\n\r\n" + # puts cgi.http_header('charset' => 'iso-2022-jp') + # Content-Type: text/html; charset=iso-2022-jp # # 'connection':: # Sets header +Connection+ to the given string: # - # cgi.http_header('connection' => 'keep-alive') - # # => "Connection: keep-alive\r\nContent-Type: text/html\r\n\r\n" + # puts cgi.http_header('connection' => 'keep-alive') + # Connection: keep-alive + # Content-Type: text/html # # 'cookie':: # Sets one or more +Set-Cookie+ headers to the given value, which may be: @@ -172,14 +176,24 @@ def stdoutput # bar_string = 'bar=1' # foo_cookie = CGI::Cookie.new('foo', '0') # bar_cookie = CGI::Cookie.new('bar', '1') - # cgi.http_header('cookie' => foo_string) - # # => "Content-Type: text/html\r\nSet-Cookie: foo=0\r\n\r\n" - # cgi.http_header('cookie' => foo_cookie) - # # => "Content-Type: text/html\r\nSet-Cookie: foo=0; path=\r\n\r\n" - # cgi.http_header('cookie' => [foo_cookie, bar_string]) - # # => "Content-Type: text/html\r\nSet-Cookie: foo=0; path=\r\nSet-Cookie: bar=1\r\n\r\n" - # cgi.http_header('cookie' => {foo: foo_cookie, bar: bar_string}) - # # => "Content-Type: text/html\r\nSet-Cookie: foo=0; path=\r\nSet-Cookie: bar=1\r\n\r\n" + # + # puts cgi.http_header('cookie' => foo_string) + # Content-Type: text/html + # Set-Cookie: foo=0 + # + # puts cgi.http_header('cookie' => foo_cookie) + # Content-Type: text/html + # Set-Cookie: foo=0; path= + # + # puts cgi.http_header('cookie' => [foo_cookie, bar_string]) + # Content-Type: text/html + # Set-Cookie: foo=0; path= + # Set-Cookie: bar=1 + # + # puts cgi.http_header('cookie' => {foo: foo_cookie, bar: bar_string}) + # Content-Type: text/html + # Set-Cookie: foo=0; path= + # Set-Cookie: bar=1 # # These cookies are in addition to the cookies held # in the @output_cookies variable. @@ -188,23 +202,28 @@ def stdoutput # Sets header +Expires+ to the given time, # which must be a {Time}[https://docs.ruby-lang.org/en/master/Time.html] object: # - # cgi.http_header('expires' => Time.now + (60 * 60 * 24 * 365)) - # # => "Content-Type: text/html\r\nExpires: Tue, 01 Dec 2026 20:47:43 GMT\r\n\r\n" + # puts cgi.http_header('expires' => Time.now + (60 * 60 * 24 * 365)) + # Content-Type: text/html + # Expires: Tue, 01 Dec 2026 23:42:37 GMT # # 'language':: # Sets header +Content-Language+ to the given string: # - # cgi.http_header('language' => 'en-US, en-CA') - # # => "Content-Type: text/html\r\nContent-Language: en-US, en-CA\r\n\r\n" + # puts cgi.http_header('language' => 'en-US, en-CA') + # Content-Type: text/html + # Content-Language: en-US, en-CA # # 'length':: # Sets header +Content-Length+ the given value, # which may be an integer or a string: # - # cgi.http_header('length' => 4096) - # # => "Content-Type: text/html\r\nContent-Length: 4096\r\n\r\n" - # cgi.http_header('length' => '4096') - # # => "Content-Type: text/html\r\nContent-Length: 4096\r\n\r\n" + # puts cgi.http_header('length' => 4096) + # Content-Type: text/html + # Content-Length: 4096 + # + # puts cgi.http_header('length' => '4096') + # Content-Type: text/html + # Content-Length: 4096 # # 'nph':: # If +true+: @@ -234,14 +253,16 @@ def stdoutput # 'server':: # Sets header +Server+ to the given string: # - # cgi.http_header('server' => 'Apache/2.4.1 (Unix)') - # # => "Server: Apache/2.4.1 (Unix)\r\nContent-Type: text/html\r\n\r\n" + # puts cgi.http_header('server' => 'Apache/2.4.1 (Unix)') + # Server: Apache/2.4.1 (Unix) + # Content-Type: text/html # # 'status':: # Sets header +Status+ to the given string: # - # cgi.http_header('status' => '666 MyVeryOwnStatus') - # # => "Status: 666 MyVeryOwnStatus\r\nContent-Type: text/html\r\n\r\n" + # puts cgi.http_header('status' => '666 MyVeryOwnStatus') + # Status: 666 MyVeryOwnStatus + # Content-Type: text/html # # If the given string is a key in the hash constant +CGI::HTTP_STATUS+, # the status becomes the value for that key: @@ -267,28 +288,36 @@ def stdoutput # "BAD_GATEWAY" => "502 Bad Gateway", # "VARIANT_ALSO_VARIES" => "506 Variant Also Negotiates"} # - # cgi.http_header('status' => 'OK') - # # => "Status: 200 OK\r\nContent-Type: text/html\r\n\r\n" - # cgi.http_header('status' => 'NOT_FOUND') - # # => "Status: 404 Not Found\r\nContent-Type: text/html\r\n\r\n" + # puts cgi.http_header('status' => 'OK') + # Status: 200 OK + # Content-Type: text/html + # + # puts cgi.http_header('status' => 'NOT_FOUND') + # Status: 404 Not Found + # Content-Type: text/html # # 'type':: # Sets +Content-Type+, overriding the default value 'text/html': # - # cgi.http_header('type' => 'text/xml') - # # => "Content-Type: text/xml\r\n\r\n" + # puts cgi.http_header('type' => 'text/xml') + # Content-Type: text/xml # - # Unrecognized Keys + # Unrecognized Keys # # Headers may also be set for unrecognized keys; # an unrecognized key becomes a header name with the given value: # - # cgi.http_header('length' => 0) # Recognized key (lowercase string). - # # => "Content-Type: text/html\r\nContent-Length: 0\r\n\r\n" - # cgi.http_header('Length' => 0) # Unrecognized key (string key not lowercase). - # # => "Content-Type: text/html\r\nLength: 0\r\n\r\n" - # cgi.http_header(length: 0) # Unrecognized key (symbol key not string) - # # => "Content-Type: text/html\r\nlength: 0\r\n\r\n" + # puts cgi.http_header('length' => 0) # Recognized key (lowercase string). + # Content-Type: text/html + # Content-Length: 0 + # + # puts cgi.http_header('Length' => 0) # Unrecognized key (string key not lowercase). + # Content-Type: text/html + # Length: 0 + # + # puts cgi.http_header(length: 0) # Unrecognized key (symbol key not string) + # Content-Type: text/html + # length: 0 # # This method does not perform charset conversion. # @@ -299,8 +328,10 @@ def stdoutput # calling method +header+ generates an HTML +header+ element: # # cgi = CGI.new(tag_maker: 'html5') - # cgi.http_header # => "Content-Type: text/html\r\n\r\n" # As expected. - # cgi.header # => "
" # Maybe a surprise. + # puts cgi.http_header # Works as expected. + # Content-Type: text/html + # puts cgi.header # Maybe a surprise. + #
# def http_header(options='text/html') if options.is_a?(String) From f3990f15b240a1ca352a6855340b7d539f49c24f Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Tue, 2 Dec 2025 00:12:44 +0000 Subject: [PATCH 04/11] [DOC] More on CGI#http_header --- lib/cgi/core.rb | 61 ++----------------------------------------------- 1 file changed, 2 insertions(+), 59 deletions(-) diff --git a/lib/cgi/core.rb b/lib/cgi/core.rb index 64e8f56..522ae25 100644 --- a/lib/cgi/core.rb +++ b/lib/cgi/core.rb @@ -928,8 +928,7 @@ class InvalidEncoding < Exception; end # :call-seq: # CGI.accept_charset -> encoding # - # Returns the default accept character set to be used for new \CGI instances; - # see CGI.accept_charset=. + # Return the accept character set for all new CGI instances. def self.accept_charset @@accept_charset end @@ -937,63 +936,7 @@ def self.accept_charset # :call-seq: # CGI.accept_charset = encoding # - # Sets the default accept character set to be used for new \CGI instances; - # returns the argument. - # - # The argument may be an Encoding object or an Encoding name; - # see {Encodings}[https://docs.ruby-lang.org/en/master/language/encodings_rdoc.html]: - # - # # The initial value. - # CGI.accept_charset # => "UTF-8" - # CGI.new - # # => - # # - # - # # Set by Encoding name. - # CGI.accept_charset = 'US-ASCII' # => "US-ASCII" - # CGI.new - # # => - # # - # - # # Set by Encoding object. - # CGI.accept_charset = Encoding::ASCII_8BIT # => # - # CGI.new - # # => - # #, - # @accept_charset_error_block=nil, - # @cookies={}, - # @max_multipart_length=134217728, - # @multipart=false, - # @options={accept_charset: #, max_multipart_length: 134217728}, - # @output_cookies=nil, - # @output_hidden=nil, - # @params={}> - # - # The given encoding is not checked in this method, - # but if it is invalid, a call to CGI.new will fail: - # - # CGI.accept_charset = 'foo' - # CGI.new # Raises ArgumentError: unknown encoding name - foo - # + # Set the accept character set for all new CGI instances. def self.accept_charset=(accept_charset) @@accept_charset=accept_charset end From ce4e65a317f5b9ee7eb912040716ec2d1c4a3f63 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Tue, 2 Dec 2025 00:14:22 +0000 Subject: [PATCH 05/11] [DOC] More on CGI#http_header --- lib/cgi/core.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/cgi/core.rb b/lib/cgi/core.rb index 522ae25..c4d523b 100644 --- a/lib/cgi/core.rb +++ b/lib/cgi/core.rb @@ -925,17 +925,11 @@ class InvalidEncoding < Exception; end # @@accept_charset="UTF-8" if false # needed for rdoc? - # :call-seq: - # CGI.accept_charset -> encoding - # # Return the accept character set for all new CGI instances. def self.accept_charset @@accept_charset end - # :call-seq: - # CGI.accept_charset = encoding - # # Set the accept character set for all new CGI instances. def self.accept_charset=(accept_charset) @@accept_charset=accept_charset From 097721ef0c5160db567bf6b59210ab765cc6ddc2 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Tue, 2 Dec 2025 00:16:27 +0000 Subject: [PATCH 06/11] [DOC] More on CGI#http_header --- lib/cgi/core.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/cgi/core.rb b/lib/cgi/core.rb index c4d523b..87fbf52 100644 --- a/lib/cgi/core.rb +++ b/lib/cgi/core.rb @@ -356,8 +356,14 @@ def http_header(options='text/html') end end - alias :header :http_header # :nodoc: - + # This method is an alias for #http_header, when HTML5 tag maker is inactive. + # + # NOTE: use #http_header to create HTTP header blocks, this alias is only + # provided for backwards compatibility. + # + # Using #header with the HTML5 tag maker will create a
element. + alias :header :http_header + def _no_crlf_check(str) if str str = str.to_s From ac30d27e00cf7687e48ccb4d7bbeca278db4cf79 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Tue, 2 Dec 2025 00:18:29 +0000 Subject: [PATCH 07/11] [DOC] More on CGI#http_header --- lib/cgi/core.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/cgi/core.rb b/lib/cgi/core.rb index 87fbf52..0f8e783 100644 --- a/lib/cgi/core.rb +++ b/lib/cgi/core.rb @@ -354,7 +354,7 @@ def http_header(options='text/html') buf << EOL # empty line of separator return buf end - end + end # http_header() # This method is an alias for #http_header, when HTML5 tag maker is inactive. # @@ -363,7 +363,6 @@ def http_header(options='text/html') # # Using #header with the HTML5 tag maker will create a
element. alias :header :http_header - def _no_crlf_check(str) if str str = str.to_s From e127d802b6d5ed8a81c4a410d5f8b01453865101 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Tue, 2 Dec 2025 00:20:11 +0000 Subject: [PATCH 08/11] [DOC] More on CGI#http_header --- lib/cgi/core.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/cgi/core.rb b/lib/cgi/core.rb index 0f8e783..0d02348 100644 --- a/lib/cgi/core.rb +++ b/lib/cgi/core.rb @@ -363,6 +363,7 @@ def http_header(options='text/html') # # Using #header with the HTML5 tag maker will create a
element. alias :header :http_header + def _no_crlf_check(str) if str str = str.to_s From d170dc7c870ad1d3783397caa1561a2aa6615aea Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Tue, 2 Dec 2025 00:21:12 +0000 Subject: [PATCH 09/11] [DOC] More on CGI#http_header --- lib/cgi/core.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/cgi/core.rb b/lib/cgi/core.rb index 0d02348..0f8e783 100644 --- a/lib/cgi/core.rb +++ b/lib/cgi/core.rb @@ -363,7 +363,6 @@ def http_header(options='text/html') # # Using #header with the HTML5 tag maker will create a
element. alias :header :http_header - def _no_crlf_check(str) if str str = str.to_s From 204b3a7e5a441bcfa2e61b283865714f39c4314c Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Tue, 2 Dec 2025 00:22:18 +0000 Subject: [PATCH 10/11] [DOC] More on CGI#http_header --- lib/cgi/core.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/cgi/core.rb b/lib/cgi/core.rb index 0f8e783..8606f0c 100644 --- a/lib/cgi/core.rb +++ b/lib/cgi/core.rb @@ -363,7 +363,8 @@ def http_header(options='text/html') # # Using #header with the HTML5 tag maker will create a
element. alias :header :http_header - def _no_crlf_check(str) + + def _no_crlf_check(str) if str str = str.to_s raise "A HTTP status or header field must not include CR and LF" if str =~ /[\r\n]/ From 0d8233ac55eec075cf98aee67afc3af61a1f8579 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Tue, 2 Dec 2025 00:23:33 +0000 Subject: [PATCH 11/11] [DOC] More on CGI#http_header --- lib/cgi/core.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cgi/core.rb b/lib/cgi/core.rb index 8606f0c..7f02980 100644 --- a/lib/cgi/core.rb +++ b/lib/cgi/core.rb @@ -364,7 +364,7 @@ def http_header(options='text/html') # Using #header with the HTML5 tag maker will create a
element. alias :header :http_header - def _no_crlf_check(str) + def _no_crlf_check(str) if str str = str.to_s raise "A HTTP status or header field must not include CR and LF" if str =~ /[\r\n]/