Class: Net::AJP13::AJP13CGI
- Inherits:
-
Object
- Object
- Net::AJP13::AJP13CGI
- Extended by:
- Forwardable
- Includes:
- CGI::QueryExtension
- Defined in:
- lib/net/ajp13/ajp13cgi.rb
Overview
The adapter to adapt Net::AJP13::Request and Net::AJP13::Response into CGI’s interface.
Constant Summary collapse
- MESSAGE_TO_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, "Rrecondition 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"], }.freeze
Instance Attribute Summary collapse
-
#env_table ⇒ Object
readonly
Method object that contains #env.
-
#response ⇒ Object
readonly
Created AJP13::Response object.
Instance Method Summary collapse
- #content_type ⇒ Object
- #gateway_interface ⇒ Object
- #header(arg = "text/html") ⇒ Object
-
#initialize(req) ⇒ AJP13CGI
constructor
A new instance of AJP13CGI.
- #output(arg = 'text/html') ⇒ Object
- #path_info ⇒ Object
- #query_string ⇒ Object
- #request_method ⇒ Object
- #request_url ⇒ Object
- #server_protocol ⇒ Object
Constructor Details
#initialize(req) ⇒ AJP13CGI
Returns a new instance of AJP13CGI.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/net/ajp13/ajp13cgi.rb', line 11 def initialize(req) @req = req if req.method == "POST" and %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n.match(req['content-type']) then boundary = $1.dup @multipart = true @params = read_multipart(boundary, req.content_length) elsif req.body_stream and req['content-type'] == 'application/x-www-form-urlencoded' @multipart = false @params = CGI::parse(req.body = req.body_stream.read) req.body_stream = nil elsif qs = query_string @multipart = false @params = CGI::parse(qs) else @multipart = false @params = {} end @env_table = self.method(:env) class << @env_table def include?(key) call(key).nil? end alias :key? :include? end @cookies = CGI::Cookie::parse(req['cookie']) end |
Instance Attribute Details
#env_table ⇒ Object (readonly)
Method object that contains #env
120 121 122 |
# File 'lib/net/ajp13/ajp13cgi.rb', line 120 def env_table @env_table end |
#response ⇒ Object (readonly)
Created AJP13::Response object.
42 43 44 |
# File 'lib/net/ajp13/ajp13cgi.rb', line 42 def response @response end |
Instance Method Details
#content_type ⇒ Object
157 158 159 |
# File 'lib/net/ajp13/ajp13cgi.rb', line 157 def content_type @req['content-type'] end |
#gateway_interface ⇒ Object
161 162 163 |
# File 'lib/net/ajp13/ajp13cgi.rb', line 161 def gateway_interface 'AJP/1.3' end |
#header(arg = "text/html") ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/net/ajp13/ajp13cgi.rb', line 65 def header(arg = "text/html") if arg.kind_of? String @response = Net::AJP13::Response.new(200) @response['content-type'] = arg elsif arg.respond_to?(:each) and arg.respond_to?(:[]) if status = arg['status'] raise ArgumentError, "Unrecognized status line format: #{status}" unless /\A(?:([0-9]{3}) )?(\w+)\Z/ =~ status status_line = $1 ? [$1.to_i, $2] : MESSAGE_TO_STATUS[$2.to_sym] raise ArgumentError, "Unrecognized status line: #{status}" unless status_line @response = Net::AJP13::Response.new(status_line[0], :reason_phrase => status_line[1]) else @response = Net::AJP13::Response.new(200) end type = nil; charset = nil arg.each do |name, value| case name.downcase when 'nph', 'status' # do nothing when "type" type = value when "charset" charset = value when 'length' @response['content-length'] = value.to_s when 'language' @response['content-language'] = value when 'cookie' case value when String @respose.add_header('set-cookie', value) when Array, Hash value.each {|val| @response.add_header('set-cookie', val.to_s) } end else @response[name] = value end end type = 'text/html' unless type @response['content-type'] = charset ? ("%s; charset=%s" % [type, charset]) : type else raise ArgumentError, "argument is not a String nor Hash" end end |
#output(arg = 'text/html') ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/net/ajp13/ajp13cgi.rb', line 110 def output(arg = 'text/html') content = yield header(arg) @response['content-length'] ||= content.length unless content.nil? or @request.method == 'HEAD' @response.body = content end end |
#path_info ⇒ Object
165 166 167 168 169 |
# File 'lib/net/ajp13/ajp13cgi.rb', line 165 def path_info #val = @req.get_attributes('path_info') #val && val[0] or @req.path @req.path end |
#query_string ⇒ Object
171 172 173 174 |
# File 'lib/net/ajp13/ajp13cgi.rb', line 171 def query_string qs = @req.get_attributes('query_string') qs and qs.join('&') end |
#request_method ⇒ Object
176 177 178 |
# File 'lib/net/ajp13/ajp13cgi.rb', line 176 def request_method @req.method end |
#request_url ⇒ Object
180 181 182 |
# File 'lib/net/ajp13/ajp13cgi.rb', line 180 def request_url @req.path end |
#server_protocol ⇒ Object
184 185 186 |
# File 'lib/net/ajp13/ajp13cgi.rb', line 184 def server_protocol @req.protocol end |