Class: R4A::Test::Message
- Inherits:
-
Object
- Object
- R4A::Test::Message
- Defined in:
- lib/core/r4a/test.rb
Overview
This is the base class that represents an HTTP message. It is a simple container class that manages headers, queries, status and content.
Instance Attribute Summary (collapse)
-
- (Object) content
This holds the request body content.
-
- (Object) headers
This holds the message HTTP headers.
-
- (Object) status
This holds the HTTP status (mainly for response).
Instance Method Summary (collapse)
-
- (Object) backtrace(e)
Prints a backtrace for an exception.
-
- (Message) initialize
constructor
Constructor.
-
- (Object) queryLine(hash)
Creates a URI encoded query line given a hash.
-
- (Object) urlEncode(text)
URI encodes text.
Constructor Details
- (Message) initialize
Constructor. No arguments.
27 28 29 30 31 |
# File 'lib/core/r4a/test.rb', line 27 def initialize() @headers = APR::Table.new(APR::Pool.new()) @status = '' @content = '' end |
Instance Attribute Details
- (Object) content
This holds the request body content
24 25 26 |
# File 'lib/core/r4a/test.rb', line 24 def content @content end |
- (Object) headers
This holds the message HTTP headers. It is an APR Table.
18 19 20 |
# File 'lib/core/r4a/test.rb', line 18 def headers @headers end |
- (Object) status
This holds the HTTP status (mainly for response)
21 22 23 |
# File 'lib/core/r4a/test.rb', line 21 def status @status end |
Instance Method Details
- (Object) backtrace(e)
Prints a backtrace for an exception
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/core/r4a/test.rb', line 44 def backtrace(e) out = '*'*80 + "\n" out << "ERROR\n\n" out << "Handled by : me\n" out << sprintf("%-14s: %s\n", e.class, e.to_s) out << "\nStack trace:\n\n" i = 1 e.backtrace.each do |stack| out << sprintf("%3i. %s\n", i, stack) i += 1 end out << '*'*80 + "\n" return out end |
- (Object) queryLine(hash)
Creates a URI encoded query line given a hash
39 40 41 |
# File 'lib/core/r4a/test.rb', line 39 def queryLine(hash) return hash.to_a.collect {|x| "#{urlEncode(x[0])}=#{urlEncode(x[1])}"}.join('&') end |
- (Object) urlEncode(text)
URI encodes text
34 35 36 |
# File 'lib/core/r4a/test.rb', line 34 def urlEncode(text) return URI.escape(text, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) end |