Class: HttpResponseFormat
- Inherits:
-
Format
- Object
- Format
- HttpResponseFormat
- Defined in:
- lib/httpresponseformat.rb
Overview
The HttpResponseFormat class is the format used to publish messages to HTTP response clients connected to a GRIP proxy.
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#code ⇒ Object
Returns the value of attribute code.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#reason ⇒ Object
Returns the value of attribute reason.
Instance Method Summary collapse
-
#export ⇒ Object
Export the message into the required format and include only the fields that are set.
-
#initialize(code = nil, reason = nil, headers = nil, body = nil) ⇒ HttpResponseFormat
constructor
Initialize with the message code, reason, headers, and body to send to the client when the message is publishing.
-
#name ⇒ Object
The name used when publishing this format.
Constructor Details
#initialize(code = nil, reason = nil, headers = nil, body = nil) ⇒ HttpResponseFormat
Initialize with the message code, reason, headers, and body to send to the client when the message is publishing.
21 22 23 24 25 26 |
# File 'lib/httpresponseformat.rb', line 21 def initialize(code=nil, reason=nil, headers=nil, body=nil) @code = code @reason = reason @headers = headers @body = body end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
17 18 19 |
# File 'lib/httpresponseformat.rb', line 17 def body @body end |
#code ⇒ Object
Returns the value of attribute code.
14 15 16 |
# File 'lib/httpresponseformat.rb', line 14 def code @code end |
#headers ⇒ Object
Returns the value of attribute headers.
16 17 18 |
# File 'lib/httpresponseformat.rb', line 16 def headers @headers end |
#reason ⇒ Object
Returns the value of attribute reason.
15 16 17 |
# File 'lib/httpresponseformat.rb', line 15 def reason @reason end |
Instance Method Details
#export ⇒ Object
Export the message into the required format and include only the fields that are set. The body is exported as base64 if the text is encoded as binary.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/httpresponseformat.rb', line 36 def export out = Hash.new if !@code.nil? out['code'] = @code end if !@reason.nil? out['reason'] = @reason end if !@headers.nil? and @headers.length > 0 out['headers'] = @headers end if !@body.nil? if @body.clone.force_encoding("UTF-8").valid_encoding? out['body'] = @body else out['body-bin'] = Base64.encode64(@body) end end return out end |
#name ⇒ Object
The name used when publishing this format.
29 30 31 |
# File 'lib/httpresponseformat.rb', line 29 def name return 'http-response' end |