Class: MLserver::Response
- Inherits:
-
Object
- Object
- MLserver::Response
- Defined in:
- lib/MLserver/response.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#httpver ⇒ Object
Returns the value of attribute httpver.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(status: 200, headers: {}, data: "", content_type: nil, httpver: "HTTP/1.1") ⇒ Response
constructor
A new instance of Response.
- #to_s(array: false) ⇒ Object
Constructor Details
#initialize(status: 200, headers: {}, data: "", content_type: nil, httpver: "HTTP/1.1") ⇒ Response
Returns a new instance of Response.
8 9 10 11 12 13 14 |
# File 'lib/MLserver/response.rb', line 8 def initialize(status:200, headers:{}, data:"", content_type: nil, httpver: "HTTP/1.1") @status = status @data = data @httpver = httpver @headers = @@default_headers.merge(response_specific_headers).merge(headers) @headers[:"Content-Type"] = content_type if content_type end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
30 31 32 |
# File 'lib/MLserver/response.rb', line 30 def data @data end |
#headers ⇒ Object
Returns the value of attribute headers.
30 31 32 |
# File 'lib/MLserver/response.rb', line 30 def headers @headers end |
#httpver ⇒ Object
Returns the value of attribute httpver.
30 31 32 |
# File 'lib/MLserver/response.rb', line 30 def httpver @httpver end |
#status ⇒ Object
Returns the value of attribute status.
30 31 32 |
# File 'lib/MLserver/response.rb', line 30 def status @status end |
Instance Method Details
#to_s(array: false) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/MLserver/response.rb', line 16 def to_s(array:false) status_line = "#{httpver} #{status}" headers = @headers.map { |header| k=header[0].to_s v=header[1].to_s header = "#{k}: #{v}" } headers = headers.join("\r\n") if !array data = @data return "#{status_line}\r\n#{headers}\r\n\r\n#{data}\r\n" if !array return [status_line, headers, "", data, ""] if array end |