Class: Hayabusa::Cgi_session
- Inherits:
-
Client_session
- Object
- Client_session
- Hayabusa::Cgi_session
- Defined in:
- lib/hayabusa_cgi_session.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#alert_sent ⇒ Object
Returns the value of attribute alert_sent.
-
#browser ⇒ Object
readonly
Returns the value of attribute browser.
-
#cgroup ⇒ Object
readonly
Returns the value of attribute cgroup.
-
#cookie ⇒ Object
readonly
Returns the value of attribute cookie.
-
#data ⇒ Object
Returns the value of attribute data.
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#eruby ⇒ Object
readonly
Returns the value of attribute eruby.
-
#get ⇒ Object
readonly
Returns the value of attribute get.
-
#hb ⇒ Object
readonly
Returns the value of attribute hb.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#httpsession_var ⇒ Object
readonly
Returns the value of attribute httpsession_var.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#out ⇒ Object
readonly
Returns the value of attribute out.
-
#page_path ⇒ Object
Returns the value of attribute page_path.
-
#post ⇒ Object
readonly
Returns the value of attribute post.
-
#resp ⇒ Object
readonly
Returns the value of attribute resp.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#session_hash ⇒ Object
readonly
Returns the value of attribute session_hash.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#working ⇒ Object
readonly
Returns the value of attribute working.
Attributes inherited from Client_session
Instance Method Summary collapse
- #handler ⇒ Object
-
#initialize(args) ⇒ Cgi_session
constructor
A new instance of Cgi_session.
Methods inherited from Client_session
#add_size, #create_binding, #execute_done, #execute_page, #force_content, #force_fileread, #init_thread, #modified_since, #threadded_content, #write
Constructor Details
#initialize(args) ⇒ Cgi_session
Returns a new instance of Cgi_session.
5 6 7 8 9 10 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 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 108 109 110 111 112 113 114 115 |
# File 'lib/hayabusa_cgi_session.rb', line 5 def initialize(args) @args = args @hb = @args[:hb] @config = @hb.config @handlers_cache = @config[:handlers_cache] cgi_conf = @config[:cgi] @get, @post, @meta, @headers = cgi_conf[:get], cgi_conf[:post], cgi_conf[:meta], cgi_conf[:headers] @browser = Knj::Web.browser(@meta) #Parse cookies and other headers. @cookie = {} @headers.each do |key, val| #$stderr.puts "Header-Key: '#{key}'." case key when "COOKIE" Knj::Web.(val).each do |key, val| @cookie[key] = val end end end #Set up the 'out', 'written_size' and 'size_send' variables which is used to write output. if cgi_conf[:cgi] @out = cgi_conf[:cgi] else @out = $stdout end @written_size = 0 @size_send = @config[:size_send] @eruby = Knj::Eruby.new( :cache_hash => @hb.eruby_cache, :binding_callback => self.method(:create_binding) ) self.init_thread #Parse URI (page_path and get). match = @meta["SERVER_PROTOCOL"].match(/^HTTP\/1\.(\d+)\s*/) raise "Could match HTTP-protocol from: '#{@meta["SERVER_PROTOCOL"]}'." if !match http_version = "1.#{match[1]}" Dir.chdir(@config[:doc_root]) @page_path = @meta["PATH_TRANSLATED"] @page_path = "index.rhtml" if @page_path == "/" @ext = File.extname(@page_path).downcase[1..-1].to_s @resp = Hayabusa::Http_session::Response.new(:socket => self) @resp.reset(:http_version => http_version, :mode => :cgi, :cookie => @cookie) @cgroup = Hayabusa::Http_session::Contentgroup.new(:socket => self, :hb => @hb, :resp => @resp, :httpsession => self) @cgroup.reset @resp.cgroup = @cgroup @resp.header("Content-Type", "text/html") #Set up session-variables. if !@cookie["HayabusaSession"].to_s.empty? @session_id = @cookie["HayabusaSession"] elsif @browser["browser"] == "bot" @session_id = "bot" else @session_id = @hb.session_generate_id(@meta) = true end #Set the 'ip'-variable which is required for sessions. @ip = @hb.ip(:meta => @meta) raise "No 'ip'-variable was set: '#{@meta}'." if !@ip raise "'session_id' was not valid." if @session_id.to_s.strip.empty? begin @session, @session_hash = @hb.session_fromid(@ip, @session_id, @meta) rescue ArgumentError => e #User should not have the session he asked for because of invalid user-agent or invalid IP. @session_id = @hb.session_generate_id(@meta) @session, @session_hash = @hb.session_fromid(@ip, @session_id, @meta) = true end if @resp.( "name" => "HayabusaSession", "value" => @session_id, "path" => "/", "expires" => Time.now + 32140800 #add around 12 months ) end raise "'session'-variable could not be spawned." if !@session raise "'session_hash'-variable could not be spawned." if !@session_hash Thread.current[:hayabusa][:session] = @session begin self.execute_page self.execute_done rescue SystemExit #do nothing - ignore. rescue Timeout::Error @resp.status = 408 end end |
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def active @active end |
#alert_sent ⇒ Object
Returns the value of attribute alert_sent.
2 3 4 |
# File 'lib/hayabusa_cgi_session.rb', line 2 def alert_sent @alert_sent end |
#browser ⇒ Object (readonly)
Returns the value of attribute browser.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def browser @browser end |
#cgroup ⇒ Object (readonly)
Returns the value of attribute cgroup.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def cgroup @cgroup end |
#cookie ⇒ Object (readonly)
Returns the value of attribute cookie.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def @cookie end |
#data ⇒ Object
Returns the value of attribute data.
2 3 4 |
# File 'lib/hayabusa_cgi_session.rb', line 2 def data @data end |
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def debug @debug end |
#eruby ⇒ Object (readonly)
Returns the value of attribute eruby.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def eruby @eruby end |
#get ⇒ Object (readonly)
Returns the value of attribute get.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def get @get end |
#hb ⇒ Object (readonly)
Returns the value of attribute hb.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def hb @hb end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def headers @headers end |
#httpsession_var ⇒ Object (readonly)
Returns the value of attribute httpsession_var.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def httpsession_var @httpsession_var end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def ip @ip end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def @meta end |
#out ⇒ Object (readonly)
Returns the value of attribute out.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def out @out end |
#page_path ⇒ Object
Returns the value of attribute page_path.
2 3 4 |
# File 'lib/hayabusa_cgi_session.rb', line 2 def page_path @page_path end |
#post ⇒ Object (readonly)
Returns the value of attribute post.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def post @post end |
#resp ⇒ Object (readonly)
Returns the value of attribute resp.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def resp @resp end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def session @session end |
#session_hash ⇒ Object (readonly)
Returns the value of attribute session_hash.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def session_hash @session_hash end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def session_id @session_id end |
#working ⇒ Object (readonly)
Returns the value of attribute working.
3 4 5 |
# File 'lib/hayabusa_cgi_session.rb', line 3 def working @working end |
Instance Method Details
#handler ⇒ Object
117 118 119 |
# File 'lib/hayabusa_cgi_session.rb', line 117 def handler return self end |