Class: Zold::Http
- Inherits:
-
Object
- Object
- Zold::Http
- Defined in:
- lib/zold/http.rb
Overview
Http page
Constant Summary collapse
- SCORE_HEADER =
HTTP header we add to each HTTP request, in order to inform the other node about the score. If the score is big enough, the remote node will add us to its list of remote nodes.
'X-Zold-Score'.freeze
- VERSION_HEADER =
HTTP header we add, in order to inform the node about our version. This is done mostly in order to let the other node reboot itself, if the version is higher.
'X-Zold-Version'.freeze
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(uri, score = Score::ZERO) ⇒ Http
constructor
A new instance of Http.
- #put(body) ⇒ Object
Constructor Details
Instance Method Details
#get ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/zold/http.rb', line 48 def get http = Net::HTTP.new(@uri.host, @uri.port) http.read_timeout = 5 return http.request_get(@uri.path, headers) rescue StandardError => e return Net::HTTPServerError.new('1.1', '599', e.) end |
#put(body) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/zold/http.rb', line 56 def put(body) http = Net::HTTP.new(@uri.host, @uri.port) http.read_timeout = 60 return http.request_put( @uri.path, body, headers.merge( 'Content-Type': 'text/plain', 'Content-Length': body.length.to_s ) ) rescue StandardError => e return Net::HTTPServerError.new('1.1', '599', e.) end |