Class: LLM::Transport::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/transport/request.rb

Overview

LLM::Transport::Request defines the normalized request interface expected by transports.

Providers build request objects through this class, then hand them to a transport for execution without depending on any specific HTTP client library.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, path, headers = nil) ⇒ LLM::Transport::Request

Parameters:

  • method (String)
  • path (String)
  • headers (Hash, nil) (defaults to: nil)


77
78
79
80
81
82
# File 'lib/llm/transport/request.rb', line 77

def initialize(method, path, headers = nil)
  @method = method.to_s.upcase
  @path = path.to_s
  @headers = {}
  (headers || {}).each { self[_1] = _2 }
end

Instance Attribute Details

#bodyObject?

Returns:



14
15
16
# File 'lib/llm/transport/request.rb', line 14

def body
  @body
end

#body_streamIO?

Returns:

  • (IO, nil)


18
19
20
# File 'lib/llm/transport/request.rb', line 18

def body_stream
  @body_stream
end

#headersHash (readonly)

Returns:

  • (Hash)


30
31
32
# File 'lib/llm/transport/request.rb', line 30

def headers
  @headers
end

#methodString (readonly)

Returns:

  • (String)


22
23
24
# File 'lib/llm/transport/request.rb', line 22

def method
  @method
end

#pathString (readonly)

Returns:

  • (String)


26
27
28
# File 'lib/llm/transport/request.rb', line 26

def path
  @path
end

Class Method Details

.delete(path, headers = nil) ⇒ LLM::Transport::Request

Parameters:

  • path (String)
  • headers (Hash, nil) (defaults to: nil)

Returns:



68
69
70
# File 'lib/llm/transport/request.rb', line 68

def self.delete(path, headers = nil)
  new("DELETE", path, headers)
end

.get(path, headers = nil) ⇒ LLM::Transport::Request

Parameters:

  • path (String)
  • headers (Hash, nil) (defaults to: nil)

Returns:



36
37
38
# File 'lib/llm/transport/request.rb', line 36

def self.get(path, headers = nil)
  new("GET", path, headers)
end

.patch(path, headers = nil) ⇒ LLM::Transport::Request

Parameters:

  • path (String)
  • headers (Hash, nil) (defaults to: nil)

Returns:



60
61
62
# File 'lib/llm/transport/request.rb', line 60

def self.patch(path, headers = nil)
  new("PATCH", path, headers)
end

.post(path, headers = nil) ⇒ LLM::Transport::Request

Parameters:

  • path (String)
  • headers (Hash, nil) (defaults to: nil)

Returns:



44
45
46
# File 'lib/llm/transport/request.rb', line 44

def self.post(path, headers = nil)
  new("POST", path, headers)
end

.put(path, headers = nil) ⇒ LLM::Transport::Request

Parameters:

  • path (String)
  • headers (Hash, nil) (defaults to: nil)

Returns:



52
53
54
# File 'lib/llm/transport/request.rb', line 52

def self.put(path, headers = nil)
  new("PUT", path, headers)
end

Instance Method Details

#[](key) ⇒ String?

Parameters:

  • key (String)

Returns:

  • (String, nil)


87
88
89
# File 'lib/llm/transport/request.rb', line 87

def [](key)
  @headers[normalize_header(key)]
end

#[]=(key, value) ⇒ String

Parameters:

Returns:

  • (String)


95
96
97
# File 'lib/llm/transport/request.rb', line 95

def []=(key, value)
  @headers[normalize_header(key)] = value.to_s
end

#each_header {|key, value| ... } ⇒ Hash

Yield Parameters:

  • key (String)
  • value (String)

Returns:

  • (Hash)


103
104
105
# File 'lib/llm/transport/request.rb', line 103

def each_header(&block)
  @headers.each(&block)
end

#inspectString

Returns:

  • (String)


109
110
111
112
113
# File 'lib/llm/transport/request.rb', line 109

def inspect
  "#<#{self.class.name}:0x#{object_id.to_s(16)}" \
    " @method=#{@method} @path=#{@path}" \
    " @headers=#{@headers.inspect}>"
end