Class: Spider::Request

Inherits:
Object show all
Defined in:
lib/spiderfw/controller/request.rb

Direct Known Subclasses

HTTP::RackRequest, HTTP::WEBrickRequest

Constant Summary collapse

BUFSIZE =
1024*4

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Request

Returns a new instance of Request.



23
24
25
26
27
28
29
30
31
32
# File 'lib/spiderfw/controller/request.rb', line 23

def initialize(env)
    Spider::Logger.debug("REQUEST:")
    Spider::Logger.debug(env)
    @env = env
    @locale = Locale.current[0]
    @misc = {}
    @params = {}
    @action = ""
    @session = {}
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



4
5
6
# File 'lib/spiderfw/controller/request.rb', line 4

def action
  @action
end

#controller_pathObject

Returns the value of attribute controller_path.



4
5
6
# File 'lib/spiderfw/controller/request.rb', line 4

def controller_path
  @controller_path
end

#cookiesObject

Returns the value of attribute cookies.



4
5
6
# File 'lib/spiderfw/controller/request.rb', line 4

def cookies
  @cookies
end

#envObject

Returns the value of attribute env.



4
5
6
# File 'lib/spiderfw/controller/request.rb', line 4

def env
  @env
end

#formatObject

Returns the value of attribute format.



4
5
6
# File 'lib/spiderfw/controller/request.rb', line 4

def format
  @format
end

#localeObject

Returns the value of attribute locale.



4
5
6
# File 'lib/spiderfw/controller/request.rb', line 4

def locale
  @locale
end

#miscObject

Returns the value of attribute misc.



4
5
6
# File 'lib/spiderfw/controller/request.rb', line 4

def misc
  @misc
end

#paramsObject

Returns the value of attribute params.



4
5
6
# File 'lib/spiderfw/controller/request.rb', line 4

def params
  @params
end

#protocolObject

Returns the value of attribute protocol.



4
5
6
# File 'lib/spiderfw/controller/request.rb', line 4

def protocol
  @protocol
end

#request_timeObject

Returns the value of attribute request_time.



4
5
6
# File 'lib/spiderfw/controller/request.rb', line 4

def request_time
  @request_time
end

#serverObject

Returns the value of attribute server.



4
5
6
# File 'lib/spiderfw/controller/request.rb', line 4

def server
  @server
end

#sessionObject

Returns the value of attribute session.



4
5
6
# File 'lib/spiderfw/controller/request.rb', line 4

def session
  @session
end

#user_idObject

Returns the value of attribute user_id.



4
5
6
# File 'lib/spiderfw/controller/request.rb', line 4

def user_id
  @user_id
end

Class Method Details

.currentObject



10
11
12
# File 'lib/spiderfw/controller/request.rb', line 10

def self.current
    Thread.current[:spider_request] ||= {}
end

.current=(val) ⇒ Object



14
15
16
# File 'lib/spiderfw/controller/request.rb', line 14

def self.current=(val)
    Thread.current[:spider_request] = val
end

.reset_currentObject



18
19
20
# File 'lib/spiderfw/controller/request.rb', line 18

def self.reset_current
    Thread.current[:spider_request] = nil
end

Instance Method Details

#bodyObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/spiderfw/controller/request.rb', line 38

def body
    b = @body.is_a?(String) ? StringIO.new(@body) : @body
    return nil unless b
    if block_given?
        b.rewind
        while (buf = b.read(BUFSIZE))
            yield buf
        end
    end
    return b
end

#body=(b) ⇒ Object



34
35
36
# File 'lib/spiderfw/controller/request.rb', line 34

def body=(b)
    @body = b
end

#pathObject

Original request path



61
62
63
# File 'lib/spiderfw/controller/request.rb', line 61

def path
    @action
end

#read_bodyObject



51
52
53
54
55
56
57
58
# File 'lib/spiderfw/controller/request.rb', line 51

def read_body
    return @body if @body.is_a?(String)
    b = ''
    self.body do |buf|
        b += buf
    end
    @body = b
end