File: part.rb

package info (click to toggle)
ruby-http-form-data 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 204 kB
  • sloc: ruby: 861; makefile: 5
file content (30 lines) | stat: -rw-r--r-- 760 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

require "stringio"

require "http/form_data/readable"

module HTTP
  module FormData
    # Represents a body part of multipart/form-data request.
    #
    # @example Usage with String
    #
    #  body = "Message"
    #  FormData::Part.new body, :content_type => 'foobar.txt; charset="UTF-8"'
    class Part
      include Readable

      attr_reader :content_type, :filename

      # @param [#to_s] body
      # @param [String] content_type Value of Content-Type header
      # @param [String] filename     Value of filename parameter
      def initialize(body, content_type: nil, filename: nil)
        @io = StringIO.new(body.to_s)
        @content_type = content_type
        @filename = filename
      end
    end
  end
end