Class: Zold::Http
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Zold::Http
- Defined in:
- lib/zold/http.rb
Overview
Http page
Defined Under Namespace
Classes: Error
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'
- 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'
- NETWORK_HEADER =
HTTP header we add, in order to inform the node about our network. This is done in order to isolate test networks from production one.
'X-Zold-Network'
- PROTOCOL_HEADER =
HTTP header we add, in order to inform the node about our protocol.
'X-Zold-Protocol'
- READ_TIMEOUT =
Read timeout in seconds
32
- CONNECT_TIMEOUT =
Connect timeout in seconds
8
Instance Method Summary collapse
Instance Method Details
#get ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/zold/http.rb', line 73 def get http = Net::HTTP.new(uri.host, uri.port) http.read_timeout = Http::READ_TIMEOUT http.open_timeout = Http::CONNECT_TIMEOUT path = uri.path path += '?' + uri.query if uri.query http.request_get(path, headers) rescue StandardError => e Error.new(e) end |
#put(body) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/zold/http.rb', line 84 def put(body) http = Net::HTTP.new(uri.host, uri.port) http.read_timeout = Http::READ_TIMEOUT http.open_timeout = Http::CONNECT_TIMEOUT path = uri.path path += '?' + uri.query if uri.query http.request_put( path, body, headers.merge( 'Content-Type': 'text/plain', 'Content-Length': body.length.to_s ) ) rescue StandardError => e Error.new(e) end |