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, reraise: false, cache: nil) {|IO| ... } ⇒ Object
Performs an HTTP GET request.
-
#http_options(url) ⇒ Hash
Returns a hash of HTTP options suitable for
Net::HTTPor a compatible client.
Instance Method Details
#get_url(url, headers: nil, reraise: false, cache: nil) {|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.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ollama_chat/http_handling.rb', line 51 def get_url(url, headers: nil, reraise: false, cache: nil, &block) headers = config.request_headers?.to_h | headers OllamaChat::Utils::Fetcher.get( url, headers: , cache: , debug: , reraise: , 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.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ollama_chat/http_handling.rb', line 26 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 |