class BBS::HTTP::Request
One request and its redirects; HTTP.get and HTTP.post make one.
Public Class Methods
# File lib/bbs/http.rb, line 91 def initialize(method, url, body: nil, headers: {}, open_timeout: 5, read_timeout: 15, deadline: 30, max_bytes: MAX_BYTES, redirects: 3, user_agent: BBS.config.user_agent, public_only: true, to: nil) @method = method @url = url.to_s @body = body @headers = { 'User-Agent' => user_agent, **headers } @timeouts = [open_timeout, read_timeout] @max_bytes = max_bytes @redirects = redirects @public_only = public_only @to = to @deadline = monotonic + deadline end
Prepares a request; the options are those of HTTP.get, method is :get or :post and body the body of a POST.
Public Instance Methods
Source
# File lib/bbs/http.rb, line 107 def run uri = address(@url) (@redirects + 1).times do response = exchange(uri) return response unless REDIRECTS.include?(response.status) && response.headers['location'] uri = address(response.headers['location'], uri) end fail!(uri, 'too many redirects') end
Sends the request, follows its redirects and returns the last Response. Raises Error when it fails.