Module: StillActive::HttpHelper
Constant Summary collapse
- TRUSTED_HOSTS =
["github.com", "gitlab.com", "codeberg.org", "api.deps.dev", "api.osv.dev", "endoflife.date", "rubygems.pkg.github.com", "repos.ecosyste.ms", "packages.ecosyste.ms", "pypi.org"].freeze
- TRANSPORT_ERRORS =
Transport-level failures ("host unreachable / connection broke", not an HTTP error status). Every network entry point degrades to a safe empty result on these rather than letting one escape and vanish a gem from the audit. SystemCallError is the superclass of the whole Errno::* family (EHOSTUNREACH, ENETUNREACH, ETIMEDOUT, EPIPE, ECONNREFUSED, ECONNRESET, ...), so we don't have to enumerate each one and miss the next.
[ Net::OpenTimeout, Net::ReadTimeout, SocketError, SystemCallError, OpenSSL::SSL::SSLError, EOFError, ].freeze
- MAX_REDIRECTS =
3- MAX_BODY_BYTES =
Ceiling on a single response body. These are metadata endpoints (version lists, scorecards, advisories); legitimate responses are well under this. A source URL is lockfile-derived and a
*.jfrog.iohost is attacker- registerable, so without a cap a hostile or broken source could stream a multi-GB body and OOM the process. 16 MiB leaves generous headroom for a gem with thousands of versions while bounding worst-case memory. 16 * 1024 * 1024
Instance Method Summary collapse
- #get_json(base_uri, path, headers: {}, params: {}) ⇒ Object
- #post_json(base_uri, path, body:, headers: {}) ⇒ Object
Instance Method Details
#get_json(base_uri, path, headers: {}, params: {}) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/helpers/http_helper.rb', line 35 def get_json(base_uri, path, headers: {}, params: {}) uri = base_uri.dup uri.path = path uri.query = URI.encode_www_form(params) unless params.empty? request_json(uri, headers) { |target| Net::HTTP::Get.new(target) } end |
#post_json(base_uri, path, body:, headers: {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/helpers/http_helper.rb', line 43 def post_json(base_uri, path, body:, headers: {}) uri = base_uri.dup uri.path = path request_json(uri, headers) do |target| request = Net::HTTP::Post.new(target) request.body = body request end end |