module Turbopuffer::Internal::Util
def encode_content(headers, body)
-
(Object)
-
Parameters:
-
body
(Object
) -- -
headers
(Hash{String=>String}
) --
Other tags:
- Api: - private
def encode_content(headers, body) # rubocop:disable Style/CaseEquality # rubocop:disable Layout/LineLength content_type = headers["content-type"] case [content_type, body] in [Turbopuffer::Internal::Util::JSON_CONTENT, Hash | Array | -> { primitive?(_1) }] [headers, JSON.generate(body)] in [Turbopuffer::Internal::Util::JSONL_CONTENT, Enumerable] unless Turbopuffer::Internal::Type::FileInput === body [headers, body.lazy.map { JSON.generate(_1) }] in [%r{^multipart/form-data}, Hash | Turbopuffer::Internal::Type::FileInput] boundary, strio = encode_multipart_streaming(body) headers = {**headers, "content-type" => "#{content_type}; boundary=#{boundary}"} [headers, strio] in [_, Symbol | Numeric] [headers, body.to_s] in [_, StringIO] [headers, body.string] in [_, Turbopuffer::FilePart] [headers, body.content] else [headers, body] end # rubocop:enable Layout/LineLength # rubocop:enable Style/CaseEquality end