Class: Brute::Tools::NetFetch

Inherits:
LLM::Tool
  • Object
show all
Defined in:
lib/brute/tools/net_fetch.rb

Constant Summary collapse

MAX_BODY =
50_000
TIMEOUT =
30

Instance Method Summary collapse

Instance Method Details

#call(url:) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/brute/tools/net_fetch.rb', line 22

def call(url:)
  uri = URI.parse(url)
  raise "Invalid URL scheme: #{uri.scheme}" unless %w[http https].include?(uri.scheme)

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = uri.scheme == "https"
  http.open_timeout = TIMEOUT
  http.read_timeout = TIMEOUT

  request = Net::HTTP::Get.new(uri)
  request["User-Agent"] = "forge-rb/1.0"

  response = http.request(request)
  body = response.body.to_s
  body = body[0...MAX_BODY] + "\n...(truncated)" if body.size > MAX_BODY

  {status: response.code.to_i, body: body, content_type: response["content-type"]}
end