Class: Aws::Crt::Http::Message

Inherits:
Object
  • Object
show all
Includes:
ManagedNative
Defined in:
lib/aws-crt/http/message.rb

Overview

HTTP Message (request)

Instance Method Summary collapse

Methods included from ManagedNative

included, #manage_native, #native, #native_set?, #release

Constructor Details

#initialize(method, path, headers = {}) ⇒ Message

Returns a new instance of Message.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/aws-crt/http/message.rb', line 15

def initialize(method, path, headers = {})
  strings = [method, path] +
            headers.flatten
  blob = StringBlob.encode(strings)
  blob_ptr = FFI::MemoryPointer.new(:char, blob.length)
  blob_ptr.write_array_of_char(blob)

  manage_native do
    Aws::Crt::Native.http_message_new_from_blob(blob_ptr, blob.length)
  end
end

Instance Method Details

#headersObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/aws-crt/http/message.rb', line 33

def headers
  blob_strings = to_blob_strings
  # blob_strings must have at least 2 element and must have
  # pairs of header/values
  if blob_strings.length < 2 ||
     blob_strings.length.odd?
    raise Aws::Crt::Errors::Error,
          'Invalid blob_string for HTTP Message'
  end
  blob_strings[2..blob_strings.length].each_slice(2).to_h
end

#methodObject



45
46
47
# File 'lib/aws-crt/http/message.rb', line 45

def method
  to_blob_strings[0]
end

#pathObject



49
50
51
# File 'lib/aws-crt/http/message.rb', line 49

def path
  to_blob_strings[1]
end

#to_blob_stringsObject



27
28
29
30
31
# File 'lib/aws-crt/http/message.rb', line 27

def to_blob_strings
  buf_out = Aws::Crt::Native::CrtBuf.new
  Aws::Crt::Native.http_message_to_blob(native, buf_out)
  StringBlob.decode(buf_out.to_blob)
end