Class: Proxie::SQLiteLogger
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Instance Method Summary collapse
-
#initialize(path, overwrite = true) ⇒ SQLiteLogger
constructor
Initialize SQLite3 logger.
-
#packet(req, resp) ⇒ Object
Save request and response data.
Constructor Details
#initialize(path, overwrite = true) ⇒ SQLiteLogger
Initialize SQLite3 logger
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/proxie/logger.rb', line 13 def initialize(path, overwrite=true) raise 'Database file with this name already exists!' if File.exists?(path) && !overwrite File.delete(path) if File.exists?(path) @db = Sequel.sqlite(path) @db.create_table :requests do primary_key :id string :request_headers string :request_url string :request_body string :response_headers string :response_body end @records = @db[:requests] end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
10 11 12 |
# File 'lib/proxie/logger.rb', line 10 def db @db end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
10 11 12 |
# File 'lib/proxie/logger.rb', line 10 def records @records end |
Instance Method Details
#packet(req, resp) ⇒ Object
Save request and response data
30 31 32 33 34 35 36 37 38 |
# File 'lib/proxie/logger.rb', line 30 def packet(req, resp) @records.insert( :request_headers => req.header.to_json, :request_url => req.request_line, :request_body => req.body.inspect, :response_headers => resp.header.to_json, :response_body => resp.body.inspect ) end |