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.



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

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



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

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



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

def method
  to_blob_strings[0]
end

#pathObject



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

def path
  to_blob_strings[1]
end

#to_blob_stringsObject



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

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