Class: Api2Convert::Http::NetHttpSender

Inherits:
Object
  • Object
show all
Defined in:
lib/api2convert/http/net_http_sender.rb

Overview

The default HttpSender, built on Ruby's stdlib Net::HTTP (zero runtime dependencies).

Net::HTTP does not follow redirects on its own — this SDK relies on that. A request only follows a 3xx when Request#follow_redirects is true (the no-secret download path); a redirect is then re-issued as a bare GET carrying only Accept/User-Agent, so a custom X-Oc-* secret header can never be forwarded to the redirect target.

An HttpSender is any object responding to call(request) -> Response. Unit tests inject a fake in its place; this real sender is exercised end-to-end by the independent security suite against loopback servers.

Constant Summary collapse

MAX_REDIRECTS =
5
REDIRECT_CODES =
[301, 302, 303, 307, 308].freeze
STREAM_ERRORS =

Errors worth surfacing when they strike mid-stream (after bytes have already reached the sink). They are re-raised as NetworkError so the transport does NOT retry — replaying would re-stream the whole body and append it to the partial file, silently corrupting the download.

This MUST stay a superset of Transport::TRANSPORT_ERRORS: any transport error the retry loop would otherwise catch (notably OpenSSL::SSL::SSLError on a truncated/reset TLS body) has to be intercepted here first, or an idempotent streamed GET gets retried and the file is corrupted.

[
  IOError, EOFError, SocketError, SystemCallError, Timeout::Error,
  OpenSSL::SSL::SSLError, URI::Error,
  Net::OpenTimeout, Net::ReadTimeout, Net::HTTPBadResponse, Net::ProtocolError
].freeze
METHOD_CLASSES =
{
  "GET" => Net::HTTP::Get,
  "HEAD" => Net::HTTP::Head,
  "POST" => Net::HTTP::Post,
  "PUT" => Net::HTTP::Put,
  "PATCH" => Net::HTTP::Patch,
  "DELETE" => Net::HTTP::Delete,
  "OPTIONS" => Net::HTTP::Options
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(timeout: 30) ⇒ NetHttpSender

Returns a new instance of NetHttpSender.



51
52
53
# File 'lib/api2convert/http/net_http_sender.rb', line 51

def initialize(timeout: 30)
  @timeout = timeout
end

Instance Method Details

#call(request) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/api2convert/http/net_http_sender.rb', line 55

def call(request)
  perform(
    request.method, request.url, request.headers,
    request.body, request.body_stream, request.content_length,
    request.follow_redirects, request.response_sink, 0
  )
end