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
4
- CONNECT_TIMEOUT =
Connect timeout in seconds
4
Instance Method Summary collapse
Instance Method Details
#get ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/zold/http.rb', line 73 def get http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == 'https' http.read_timeout = Http::READ_TIMEOUT http.open_timeout = Http::CONNECT_TIMEOUT path = uri.path path += '?' + uri.query if uri.query Timeout.timeout(Http::READ_TIMEOUT + Http::CONNECT_TIMEOUT) do http.request_get(path, headers) end rescue StandardError => e Error.new(e) end |
#put(body) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/zold/http.rb', line 87 def put(body) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == 'https' http.read_timeout = Http::READ_TIMEOUT http.open_timeout = Http::CONNECT_TIMEOUT path = uri.path path += '?' + uri.query if uri.query Timeout.timeout(Http::READ_TIMEOUT + Http::CONNECT_TIMEOUT) do http.request_put( path, body, headers.merge( 'Content-Type': 'text/plain', 'Content-Length': body.length.to_s ) ) end rescue StandardError => e Error.new(e) end |