Module: OllamaChat::HTTPHandling
- Included in:
- Chat
- Defined in:
- lib/ollama_chat/http_handling.rb
Overview
Provides helper methods for HTTP interactions used by the OllamaChat
library. The module is mixed into various classes (e.g. OllamaChat::Chat)
to give them access to a convenient, configuration‑aware HTTP client.
The primary responsibilities are:
- Build a hash of HTTP options (e.g. SSL verification and proxy settings) based on the current configuration.
- Perform a GET request with those options, optionally using a cache and debugging information.
The module is deliberately lightweight – it delegates the actual network
call to OllamaChat::Utils::Fetcher.
Instance Method Summary collapse
-
#get_url(url, headers: nil, cache: nil, remember: true) {|IO| ... } ⇒ Object
Performs an HTTP GET request.
-
#http_options(url) ⇒ Hash
Returns a hash of HTTP options suitable for
Net::HTTPor a compatible client. -
#links ⇒ Set
Returns the links set for this object, initializing it lazily if needed.
Instance Method Details
#get_url(url, headers: nil, cache: nil, remember: true) {|IO| ... } ⇒ Object
Performs an HTTP GET request.
The method merges the caller‑supplied headers with the headers
configured in config.request_headers?. It then delegates to
OllamaChat::Utils::Fetcher.get, passing along any cache or debug
flags and the HTTP options generated by http_options.
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ollama_chat/http_handling.rb', line 63 def get_url(url, headers: nil, cache: nil, remember: true, &block) remember and links.add(url.to_s) headers = config.request_headers?.to_h | headers OllamaChat::Utils::Fetcher.get( url, headers: , cache: , debug: , http_options: (OllamaChat::Utils::Fetcher.normalize_url(url)), &block ) end |
#http_options(url) ⇒ Hash
Returns a hash of HTTP options suitable for Net::HTTP or a
compatible client.
The options include:
:ssl_verify_peer– a boolean that disables peer verification for hostnames listed in the configuration’sssl_no_verifyset.:proxy– the proxy URL if one is configured.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ollama_chat/http_handling.rb', line 37 def (url) = {} if ssl_no_verify = config.ssl_no_verify? hostname = URI.parse(url).hostname |= { ssl_verify_peer: !ssl_no_verify.include?(hostname) } end if proxy = config.proxy? |= { proxy: } end end |
#links ⇒ Set
Returns the links set for this object, initializing it lazily if needed.
The links set is memoized, meaning it will only be created once per object instance and subsequent calls will return the same Set instance.
22 23 24 |
# File 'lib/ollama_chat/http_handling.rb', line 22 def links @links ||= OllamaChat::LinksSet.new(chat) end |